Vim Tricks Only a Few People Know About

Here are a few known Vim tricks that can come in handy:

  1. The ‘g;‘ and ‘g,‘ commands allow you to jump between the last two locations where you made a change in the current buffer.
  2. The ‘:marks‘ command shows a list of all the named marks in the current file and the line number where they are located.
  3. The ‘:set spell‘ command enables spell-checking, and ‘]s‘ and ‘[s‘ can be used to navigate between misspelled words.
  4. The ‘gq‘ command can be used to format the text within a visually selected block to a specified width.
  5. :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.
  6. The ‘gU‘ command makes the selected text uppercase, and ‘gu‘ makes it lowercase.
  7. The ‘:retab‘ command can be used to convert tabs to spaces or spaces to tabs.
  8. 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:

  1. CTRL-A‘ and ‘CTRL-X‘ can be used to increment and decrement numbers, respectively, in normal mode.
  2. g CTRL-]‘ will take you to the definition of the keyword under the cursor.
  3. :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.
  4. gv‘ command will reselect the last visual selection.
  5. CTRL-O‘ and ‘CTRL-I‘ can be used to navigate backwards and forwards, respectively, through the jumplist, which keeps track of your cursor movements.
  6. :set whichwrap+=<,>,h,l‘ allow you to move between the beginning and end of the line when using ‘h,j,k,l’ keys.
  7. :set cursorline‘ highlights the current line your cursor is on, and ‘:set nocursorline‘ turns the highlighting off.
  8. :undo {n}‘ command will undo the last n actions.
  9. :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

Leave a Comment