vim is a text editor.
Use hjkl to move around. Ctrl-f and Ctrl-b moves forward and back a page.
For line navigation, use 0 and $ to go to the start and end.
Move between words with b and w.
Move between sentences with ( and ).
Move between paragraphs with { and }.
Search for word at cursor with * and #.
Navigate quickjump list with Ctrl-O and Ctrl-I.
d to cut, y to copy and p to paste. (delete, yank and put)
Copy to clipboard from the top of the buffer to the cursor, press Space-h. This is a custom leader binding, source here.
To paste while keeping the current line's indentation, use ]p.
To copy to primary clipboard (alt c - alt v in terminal) use "+y
Vim has registers and marks. Registers are like boxes to store text in, and marks are pointers to a character in a file.
To copy some text, use ma to mark the current position into mark a, go to the other end and do y'a. This copies the text from mark a to here.
To access the exact marked character, use <backtick> a
You can use registers by prepending any operation with "r to use the r register.
For example, you can copy the current line into the a register with "ayy and paste it somewhere with "ap.
You can change text inside certain selectors such as words, paragraphs or delimiting characters.
Replace entire words with ciw. This keeps the whitespace after the word. (caw doesn't)
To change text inside quotes, use ci"
You can use other commands with selectors, like dw to delete a word, dip to delete a paragraph.
Append text to the end of the current line with A.
Insert text at the beginning of a line with I.
Insert emtpy line below cursor with o. Same but above with O.
Global replace: :%s/this/that/g
% means to operate on every line.
Record actions and replay them when needed.
qa starts recording a macro in register a. Stop recording with q.
@a replay macro from register a.
Buffers are files loaded into memory.
View a list of them with :ls
Switch between them with :b <nr,name>. This supports autocompletion with filenames. Custom leader binding: Space-b
Some custom bindings allow me to move between buffers with Alt-<Left,Right> as well. (remapped to :bp and :bn)
Use windows for having multiple views into a buffer.
Create them with :new or any kind of split.
Navigate between them with C-w-<h,j,k,l> (just like you would normally move in vim)
Move them with C-w-r to rotate them around, or with C-w-<H,J,K,L> to move them in the vim directions.
Resize windows equally with C-w-=. Change height with C-w-{+,-} and width with C-w-{<,>}
Split the current view horizontally with :split or C-w-s and vertically with :vsplit or C-w-v.
If you've been working on a project you probably have windows and splits just as you want them.
To save a session, do :mksession. This will save a Session.vim file in the current working directory. To save it somewhere else pass a location to the command.
To load a session, do :source Session.vim
Set tw to maximum column width, then select what you want to format and type gq
See https://blog.ezyang.com/2010/03/vim-textwidth/ for more info.
You can fold sections with zf operator. Specify range visually or with regular movement commands. Fold/Unfold with zo and zc.
You can use vim as a mergetool with git for easier conflict resolving. Run :diffget <LOCAL,BASE,REMOTE> to choose which version to keep.
Use [i to get the selected function's signature as a hint in the command window
You can manage plugins using Vim's native plugin support or with something like vim-plug: https://github.com/junegunn/vim-plug
tpope
gc{motion} to comment/uncomment and gcc [count] for count nr lines.vimwiki
junegunn