My Vim Cheatsheet

Vim is a powerful text editor that is free and open-source. It is highly configurable. It can be accessed via terminal by typing vi or vim. Below I will put some useful vim commands that made my life easier.

:%s/\s\+$// ## removes all trailing whitespaces

:set textwidth=80
gqG               # hard wrap lines at 80 characters

:?text # search for the specific text in the document

cc # clear the line contents without deleting it

To configure your vim such that all text are hard wrapped at 80 characters per line, without breaking any words, do:

vi ~/.vimrc
## add the following lines to your .vimrc:
set textwidth=80
set formatoptions+=t
set wrapmargin=0
set linebreak

To comment out a block of text inside vim:

  • press Esc to leave editing or other mode
  • hit ctrl + v (visual block mode)
  • use the up/down arrow keys to select lines you want
  • Shift + i
  • insert the text you want, i.e. % or #
  • press Esc twice

To quickly jump to a certain line in vim:

  • press Esc to enter the normal command mode
  • type the line number, and then press Shift + g

To turn on/off line number:

:set number
:set nonumber
Yishu Xue
Yishu Xue
Data Scientist / Coder / Novice Sprinter / Gym Enthusiast

The night is dark and full of terrors.