I use vscode these days, but I think it’s important to learn vim or emacs because eventually you’ll be stuck ssh’ing into a server and have to edit a file or search a log. Vim is endlessly configurable and has a million commands but I try to keep my setup simple.
Here are some commands to get you started.
anything in CAPS is a placeholder (ie use :5 not :NUMBER)
# ESSENTIAL COMMANDS
:w – save
:q – quit
:wq – save and quit
:q! – quit without saving
i – insert mode (you can change stuff)
esc – get out of insert mode
# BASIC STUFF
dd – delete the current line
yy – copy current line
p – paste
dNUMBER down – delete that many lines after pressing down
v – visually select text
d – delete selected text
$ – jump to end of the current line
^ – jump to the beginning of the current line
# STUFF THAT KEEPS ME USING VIM
/STRING – search any string. press n to see the next match
G – jump to the end of the file
:?STRING – search the file in reverse
:NUMBER – jump to that line of the file
:%s/OLD_TEXT/NEW_TEXT/igc – find a case insensitive string and replace it with a new string. confirm each time
:%s/OLD_TEXT/NEW_TEXT/ig – same, but yolo the replacements
:%s/OLD_TEXT/NEW_TEXT/g – same as above, but case sensitive
# CONFIG STUFF, should probably be in your .vimrc
:set nu – show line numbers
:set nonu – don’t show line numbers
:set list – ends of lines marked with a special character so you can see them
:set listchars=tab:>- – see tabs visually
:set tabstop=2 shiftwidth=2 – tab key makes two spaces
:set backspace=2 – Makes backspace work like you’d expect
Leave a Reply