Vim Notebook

Explore a personal collection of Vim commands and tricks that I've found useful in enhancing my text editing efficiency. Whether you're a DevOps engineer, a frontend developer, or a backend coder, these notes will guide you through mastering Vim.

What is Vim?

Vim (Vi IMproved) is a highly configurable text editor built to make creating and changing any kind of text very efficient. It is an improved version of the vi editor distributed with most UNIX systems.

I am using Vim for monitoring log files, modifying scripts and environment files for DevOps tasks. Occasionally, I switch to frontend and backend development, where I might forget some commands. Here are some notes for myself, and hopefully, they help others too!

Basic Movements

CommandDescription
hMove cursor left
jMove cursor down
kMove cursor up
lMove cursor right
ggGo to the first line of the file
GGo to the last line of the file
wMove to the beginning of the next word
eMove to the end of the current word
bMove to the beginning of the previous word
0Move the cursor to the beginning of the current line
$Move the cursor to the end of the current line
WMove the cursor to the beginning of the next WORD (a WORD is a sequence of non-whitespace characters)
}Move the cursor to the beginning of the next paragraph
{Move the cursor to the beginning of the previous paragraph
%Move the cursor to the matching bracket or parenthesis

Editing Commands

CommandDescription
iEnter insert mode before the cursor
oInsert a new line below the current line and enter insert mode
OInsert a new line above the current line and enter insert mode
ddDelete the current line
yyYank (copy) the current line
pPaste the yanked or deleted text after the cursor
Jjoin the current line with the next line
uUndo the last change
rReplace the character under the cursor with the next character typed
sDelete the character under the cursor and enter insert mode
xDelete the character under the cursor
Ctrl + rRedo the undone change
:wSave the file
:qQuit Vim
:wqSave and quit
:q!Quit without saving

Searching and Replacing

CommandDescription
/patternSearch for pattern
nRepeat search in the same direction
NRepeat search in the opposite direction
:s/foo/bar/gReplace foo with bar in the file
:%s/old/new/gReplace all instances of old with new

Control

CommandDescription
Ctrl + oJump back to the previous position
Ctrl + iJump forward to the next position
Ctrl + fMove the cursor forward one screen
Ctrl + bMove the cursor backward one screen
Ctrl + dMove the cursor down half a screen
Ctrl + uMove the cursor up half a screen
Ctrl + gShow the current cursor position in the document
Ctrl + wDelete the word before the cursor
Ctrl + yCopy the character above the cursor and insert it at the cursor position
Ctrl + eCopy the character below the cursor and insert it at the cursor position
Ctrl + rEnter register mode (used for copying and pasting text)

Customisation

CommandDescription
:set numberShow line numbers
:set hlsearchHighlight all search matches
:set ignorecaseIgnore case when searching
:set tabstop=4Set the tab width to 4 spaces
:set expandtabConvert tabs to spaces
:set mouse=aEnable mouse support in Vim