VIM

August 24, 2021

Navigation Commands

  • H – Go to the first line of current screen.
  • M – Go to the middle line of current screen.
  • L – Go to the last line of current screen.
  • ctrl+f – Jump forward one full screen.
  • ctrl+b – Jump backwards one full screen.
  • ctrl+d – Jump forward (down) a half screen.
  • ctrl+u – Jump back (up) one half screen.
  • gd - go to function definition
  • g; - go to the previous change location
  • g, - go to the newer change location
  • gi - place the cursor at the same position where it was left last time in the Insert mode
  • * or # - searches for the exact word at the cursor
  • % - End of the function block
  • fc - Find (
  • You can also use ZZ to quickly save and close.
  • When navigating back to the start, you can also use ^ to go to non-whitespace chars.

Visual commands

  • vi( - Highlight inside (

Edit commands

  • I (capital i) To enter insert mode at the beginning of the line.
  • A (capital a) To enter insert mode at the end of the line.
  • ci" change inside "
  • ca" change around "
  • cit change inside tag
  • ciq change inside quotes
  • ci( Change Inside (
  • cia Change inside arguments
  • dab Delete inside brackets
  • cs'" change surround ' with "
  • di" delete inside "
  • da" delete around "
  • dit change inside tag
  • dab delete around brackets
  • dib delete inside brackets
  • dap delete around paragraph
  • dip delete inside paragraph
  • di( Delete inside (
  • S (capital S) To delete the line and enter insert mode at the start.

mini.surround

  • Add surrounding with sa (in visual mode or on motion).
  • Delete surrounding with sd.
  • Replace surrounding with sr.
  • Find surrounding with sf or sF (move cursor right or left).
  • Highlight surrounding with sh.
  • Change number of neighbor lines with sn (see |MiniSurround-algorithm|).

FZF

  • Look for files under current directory :FZF

  • Look for files under your home directory :FZF ~

  • With fzf command-line options :FZF --reverse --info=inline /tmp

  • Bang version starts fzf in fullscreen mode :FZF!

switch between tabs

  • gt -> Switch between tabs

References

  • https://world.hey.com/dhh/wonderful-vi-a1d034d3

contrl+z to switch to terminal and fg to open vim again