Registers
Shortcuts
Ctrl + z
This will leave the current Vim session in tact and go back to our Unix-like command line.We can then type fg in the CLI at any time to return to our Vim session without having to re-open our buffers.
Ctrl + ^
Switches between our last 2 visited buffersShift + *
When our cursor is on a word or selection this will load that into search. We can then usen or N to navigate that search.
Ctrl + d
Down 1/2 screenCtrl + u
Up 1/2 screenVim Motions
The simplest form of a VIM motion is {count}{motion}. For example 5w will advance the cursor 5 words.
A more advanced from is {count}{command}{motion}.
Here are some basic examples:
3d$ will delete the next 3 lines until the end.
dfe will delete all chars up to the letter e
cfe will do same as dfe except we would end up in insert mode
yfx will yank up until the character x
vfx will enter visual mode and select up until x
vi{ and va{
These are exceptionally useful motions.
These will select a visual block between the brackets and can also be replaced with other types of brackets vi) or va[.
Once selected we can use o to jump back and forth between positions.
And we can also use:
Shift + v
To select full line of all selectionThis pattern also works with yank ya{, change ci{ and delete da{.
viw is also useful for selecting words and yiW to backwards select words.
F, b, r
Fdoes same things afonly backwardsbgoes backwards by wordrreplaces whatever is under cursor with next keypress- when using f, we can use
;to repeat forward and,to go backwards
I and A go to the beginning and end of a line but change you into insert mode
Macros
:'<,'>norm! @a - execute a macro on all visually selected lines