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.
Shift + a: To edit at the end of the current line.
Shift + i: To edit at the beginning of the current line.
Shift + o: To write at previous line.
s: To replace the current char.
w, b: To go to next/previous word(counts special char as a space)
Shift + w: To go to next word (Doesn't count special char as space)
t + 'char: To go to the next 'char' in current line.
c + i + Shift + '('/'{': Change inside braces/paranthesis
(Many features in this command and very useful)
= + {till a block}/{inside a block/braces}: Indent till/a piece of code
; : 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.
t ${char} : goes till char and not on the char.
f ${char} : goes on the char.
Quickfix: Useful plugin for debugging compiled languages like C++ and C. Save the compilation error in a file and open it with "-q".
Ctags
C-w C-] : Got to definition
C-w S-] : Opens the tag in preview mode.
Auto-Completion
C-x C-l : autocomplete a line.
C-x C-k : autocomplete a word from dictionary.
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.
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 .
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.
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.
Formatting
Use :ClangFormat inside Vim.
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.
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.)
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.
Writing
Use :Goyo to invoke a distraction free mode for writing.
Use :Goyo! to exit this mode.
Vimwiki
ww : opens the default page of wiki.
whh : renders the page in browser.
:VWS pattern : search for a pattern in the wiki.
Quickfix
:cw : open the list if there are errors.
:ccl : close the list.
:cn : go to next item,.
Vim Explorer
% : While in the vim file explorer, use this to create a new file.
File Name
<1-Ctrl-G> : Display full path of current file.
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.
Macros
qa : Start recording sequence of commands to register a.
@a : Run the sequence of commmands stored in register a.
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.
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.
YCM
s : Go to the source (definition) of the type
r : Populate the quickfix list with references (usage) of this type
Jumplist
Saves the locations of jumps: searching, substitute and marks.
This works across files.
: Jump inside the jumplist
: Jump outside in the jumplist
Changelist
Saves the locations of all changes
g; : Go inside in the changelist
g, : Go outside in the changelist
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
Editing
~ : Change case of current char or of visual selection.
Registers
0 : The 0 register saves only the yanked text. Hence, it is more useful
than the " register.
Location List
It is a window-specific version of the quickfix list.