Vim

Vim Cheatsheet #

Vim is a highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor with many enhancements.

Basic Navigation #

Command/OptionExampleDescription
hhMove cursor left
jjMove cursor down
kkMove cursor up
llMove cursor right
ggggMove to the beginning of the file
GGMove to the end of the file

Editing Text #

Command/OptionExampleDescription
iiEnter insert mode before the cursor
IIEnter insert mode at the beginning of the line
aaEnter insert mode after the cursor
AAEnter insert mode at the end of the line
ooOpen a new line below the current line
OOOpen a new line above the current line
xxDelete the character under the cursor
ddddDelete the current line
yyyyYank (copy) the current line
ppPaste the yanked or deleted text

Search and Replace #

Command/OptionExampleDescription
/search/exampleSearch for “example”
?search?exampleSearch backward for “example”
nnMove to the next search result
NNMove to the previous search result
:%s/old/new/g:%s/old/new/gReplace all occurrences of “old” with “new” in the file
:s/old/new/g:s/old/new/gReplace all occurrences of “old” with “new” in the current line

File Operations #

Command/OptionExampleDescription
:w:wSave the current file
:q:qQuit Vim
:wq:wqSave and quit Vim
:x:xSave and quit Vim (alternative to :wq)
:q!:q!Quit without saving changes
:e filename:e newfile.txtOpen a file named “newfile.txt”
:w filename:w newfile.txtSave the current file as “newfile.txt”

Window Management #

Command/OptionExampleDescription
:split:splitSplit the window horizontally
:vsplit:vsplitSplit the window vertically
Ctrl-w wCtrl-w wSwitch between windows
Ctrl-w qCtrl-w qClose the current window

Visual Mode #

Command/OptionExampleDescription
vvEnter visual mode to select characters
VVEnter line-wise visual mode
Ctrl-vCtrl-vEnter block visual mode
ddDelete the selected text
yyYank (copy) the selected text
ppPaste the yanked or deleted text

Advanced Commands #

Command/OptionExampleDescription
:set number:set numberShow line numbers
:set relativenumber:set relativenumberShow relative line numbers
:syntax on:syntax onEnable syntax highlighting
:set tabstop=4:set tabstop=4Set the width of a tab to 4 spaces
:set shiftwidth=4:set shiftwidth=4Set the number of spaces for auto-indents

This cheatsheet covers the essential Vim commands and options to help you navigate, edit, and manage files efficiently in Vim.

Vim

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.