Vim - shivamvats/notes GitHub Wiki

  1. Registers
  2. Reference: http://www.moolenaar.net/habits.html

Workflow

Exploration

  • Use to look at an outline of code in the current buffer

Editing

  • to to list all TODOS and [/]q to go through them
  • fix to list all FIXMEs and [/]q to go through them

Commands

  • c stands for change
  • a stands for a or an
  • i stands for inside
  • i always selects less than a.
  1. Shift + a: To edit at the end of the current line.
  2. Shift + i: To edit at the beginning of the current line.
  3. Shift + o: To write at previous line.
  4. s: To replace the current char.
  5. w, b: To go to next/previous word(counts special char as a space)
  6. Shift + w: To go to next word (Doesn't count special char as space)
  7. t + 'char: To go to the next 'char' in current line.
  8. c + i + Shift + '('/'{': Change inside braces/paranthesis (Many features in this command and very useful)
  9. = + {till a block}/{inside a block/braces}: Indent till/a piece of code
  10. ; : Repeats the previous command. For example, while going to a particular character in a line, I use f ${char} and let's say there are multiple instances of that char in the line. Then,I need to repeat my command and I should simple use f ${char} ; ; etc.
  11. t ${char} : goes till char and not on the char.
  12. f ${char} : goes on the char.
  13. Quickfix: Useful plugin for debugging compiled languages like C++ and C. Save the compilation error in a file and open it with "-q".
  14. Ctags

    • C-w C-] : Got to definition
    • C-w S-] : Opens the tag in preview mode.
  15. Auto-Completion

    • C-x C-l : autocomplete a line.
    • C-x C-k : autocomplete a word from dictionary.
  16. Snippets

    • :UltiSnipsEdit : Add a new snippet to the current file type.
    • <tab> : to activate the snippet or go to the next snippet.
    • C-j : to navigate the next placeholder.
  17. Easy-motion

    • <leader><leader>w : Highlight all words.
    • <leader><leader>f<char> : Highlight all following words with .
    • <leader><leader>F<char> : Highlight all previous words with .
  18. Motion

    • w / b : Move to the beginning of next / previous word.
    • e : Move to the end of next word.
    • { / } : Go up/down to the first blank line.
    • [{ / ]} or [( / )] : Go to the beginning/end of the current section delimited by {} or ().
    • * : Search for the current word.
    • [[ / ]] : Go to the previous/next top-level scope.
    • [m / ]m : Go to the previous/next method/scope.
  19. Spelling

    • z= : This opens a list of alternative spellings for the current word.
    • 1z= : This automatically chooses the 1st suggestion rather than having to choose from a window.
  20. Formatting

    • Use :ClangFormat inside Vim.
  21. Vim-surround

    • ys<motion><delim> : Surround a chunk of text with delimiters.
    • cs<motion><from><to> : Change a pair of delimiters.
    • yss<delim> : Surround the whole line.
  22. Object-select

    • Used in Visual mode.
    • A command starting with 'a' selects 'a'n object including white space.
    • A command starting with 'i' selects an inner object without white space.
    • 'a' commands: aw, aW, as, ap, a[, a(, etc.
    • 'i' commands: iw, iW, iw, ip, i[, i(, etc.)
  23. LateX-editing

    • Use vimtex commands for editing latex files.
    • ll : compilation.
    • lv : view the pdf.
    • ls : when using subfiles package, choose whether to compile the current file or TEX ROOT.
  24. Writing

    • Use :Goyo to invoke a distraction free mode for writing.
    • Use :Goyo! to exit this mode.
  25. Vimwiki

    • ww : opens the default page of wiki.
    • whh : renders the page in browser.
    • :VWS pattern : search for a pattern in the wiki.
  26. Quickfix

    • :cw : open the list if there are errors.
    • :ccl : close the list.
    • :cn : go to next item,.
  27. Vim Explorer

    • % : While in the vim file explorer, use this to create a new file.
  28. File Name

    • <1-Ctrl-G> : Display full path of current file.
  29. Search and Replace

    • <:s/C-r C-w/bar> : Replace the word under cursor with bar.
    • <:s/foo/C-r C-w> : Replace foo with the word under the cursor.
    • :/foo : Search for foo in the current file after the current line.
  30. Macros

    • qa : Start recording sequence of commands to register a.
    • @a : Run the sequence of commmands stored in register a.
  31. Commenting

    • ,c : Toggle the comment-state of selected lines.
    • ,cm : Comment using multi-part delimiters if possible.
    • ,cA : Insert comments at the end of current line.
  32. Search

    • [I : Show all occurrences of current word in the file.
    • ]I : Show all occurrences of current word in the file, starting from the cursor.
  33. YCM

    • s : Go to the source (definition) of the type
    • r : Populate the quickfix list with references (usage) of this type
  34. Jumplist

    • Saves the locations of jumps: searching, substitute and marks.
    • This works across files.
    • : Jump inside the jumplist
    • : Jump outside in the jumplist
  35. Changelist

    • Saves the locations of all changes
    • g; : Go inside in the changelist
    • g, : Go outside in the changelist
  36. Fugitive

    • cc : Open the commit window while in Gstatus mode
    • D : Open a file in diff mode
      • : Move a file from staged to unstaged and vice-versa
  37. Editing

    • ~ : Change case of current char or of visual selection.
  38. Registers

    • 0 : The 0 register saves only the yanked text. Hence, it is more useful than the " register.
  39. Location List

    It is a window-specific version of the quickfix list.
    • :lopen : Open the location window
    • :ln : Got to next item
    • :lp : Got to previous item
  40. Marks

    • ` : Jump to mark position
    • '. : Jump to last change in current buffer
    • ]' : Jump to next line with a lowercase mark
    • ]` : Jump to next line with uppercase mark
⚠️ **GitHub.com Fallback** ⚠️