Here are a few known Vim tricks that can come in handy:
- The ‘
g;
‘ and ‘g,
‘ commands allow you to jump between the last two locations where you made a change in the current buffer. - The ‘
:marks
‘ command shows a list of all the named marks in the current file and the line number where they are located. - The ‘
:set spell
‘ command enables spell-checking, and ‘]s
‘ and ‘[s
‘ can be used to navigate between misspelled words. - The ‘
gq
‘ command can be used to format the text within a visually selected block to a specified width. - ‘
:normal {commands}
‘ can be used to execute a sequence of normal-mode commands as if they were typed by hand, the {commands} are the keys or command to be executed. - The ‘
gU
‘ command makes the selected text uppercase, and ‘gu
‘ makes it lowercase. - The ‘
:retab
‘ command can be used to convert tabs to spaces or spaces to tabs. - The ‘
g CTRL-G
‘ command shows the current line number, column number, and file name at the bottom of the screen.
Here are a few less-known Vim tricks that might come in handy:
- ‘
CTRL-A
‘ and ‘CTRL-X
‘ can be used to increment and decrement numbers, respectively, in normal mode. - ‘
g CTRL-]
‘ will take you to the definition of the keyword under the cursor. - ‘
:bufdo
‘ command can be used to execute a command on all open buffers, for example: ‘:bufdo %s/oldword/newword/g
‘ will replace all occurences of ‘oldword’ with ‘newword’ in all open files. - ‘
gv
‘ command will reselect the last visual selection. - ‘
CTRL-O
‘ and ‘CTRL-I
‘ can be used to navigate backwards and forwards, respectively, through the jumplist, which keeps track of your cursor movements. - ‘
:set whichwrap+=<,>,h,l
‘ allow you to move between the beginning and end of the line when using ‘h,j,k,l’ keys. - ‘
:set cursorline
‘ highlights the current line your cursor is on, and ‘:set nocursorline
‘ turns the highlighting off. - ‘
:undo {n}
‘ command will undo the last n actions. - ‘
:m{a-zA-Z}
‘ command can be used to create a named mark on the current line, this mark can be used to jump to later with'{a-zA-Z}
command