Open a file in vim; a missing file is created, with the cursor on line 1
vim /etc/nginx/nginx.confA quick reference for modes, motions, editing, search and replace, splits and common settings, with notes on vi versus vim compatibility.
Open a file in vim; a missing file is created, with the cursor on line 1
vim /etc/nginx/nginx.confOpen a file at line 42, handy when jumping to an error line
vim +42 app.logEnter insert mode before the cursor; a inserts after, o opens a new line below
iReturn to normal mode, where all motion and editing commands work
EscEnter character-wise, line-wise or block-wise visual mode before acting on a selection
v / V / Ctrl+vSave and quit; :x and ZZ behave the same and only write when the buffer changed
:wqQuit and discard every change; accidental use loses unsaved work
:q!Move left, down, up, right by one character; prefix a count such as 5j to move five lines
h j k lJump to the next word, the previous word, or the end of the current word
w b eJump to the start of the line, its first non-blank character, or the end
0 ^ $Jump to the first line, the last line, or a specific line number
gg G :42Scroll half a page down or up; Ctrl+f and Ctrl+b scroll a full page
Ctrl+d Ctrl+uJump by paragraph, delimited by blank lines, which is fast in config files
{ }f jumps to the next x in the line, t to the character before it, ; repeats the jump
f x t x ;Jump between matching brackets, useful when reading scripts
%Delete the character under the cursor or the one before it
x XDelete a line, yank a line, paste below or paste above
dd yy p PDelete to the next word, to the end of the line, or to the start; prefix a count to repeat
dw d$ d0Change the current word and enter insert mode, the everyday way to edit a setting
cwUndo the last change, or redo an undone change
u Ctrl+rIndent or outdent the current line; works on a visual selection as well
>> <<Join the next line into the current one, useful for wrapped settings
Jr replaces one character and returns to normal mode; R keeps replacing until Esc
r RSearch downward; use ? to search upward, then n and N to jump between matches
/errorSearch for the word under the cursor downward with * or upward with #
* #Replace every match in the file; check the scope with :set number first
:%s/old/new/gConfirm each replacement: y replaces, n skips and a replaces the rest
:%s/old/new/gcDelete every line matching the pattern; preview with :g/pattern/p first
:g/pattern/dClear the highlight left by the last search
:nohSelect whole lines and delete them; a selection can also be yanked or indented
V j j dBlock-select several lines, insert a comment marker, then Esc to apply it everywhere
Ctrl+v j j I # EscReplace only inside the previous visual selection
:'<,'>s/old/new/gStart recording a macro into register a; press q again to stop
qaRun the macro in register a; @@ repeats the last executed macro
@a @@Split horizontally to open another file; use :vsp to split vertically
:sp /etc/hostsMove between split windows by direction
Ctrl+w h / j / k / lEqualize split sizes
Ctrl+w =Open a new tab; gt and gT switch to the next and previous tab
:tabnew gt gTKeep only the current window, close the current one, or :qa to quit all
:only :qWrite the current file without quitting
:wWrite a copy to another path, a cheap backup before editing configs
:w /tmp/nginx.conf.bakWrite back with elevated rights when the file was opened without sudo
:w !sudo tee %Reload the file and discard local changes, useful after external edits
:e!Insert the contents of another file below the cursor
:r /etc/hostsConvert CRLF to LF, fixing bad interpreter errors for scripts copied from Windows
:set ff=unixEdit the personal config file; set commands there apply on every start
vim ~/.vimrcShow line numbers; :set relativenumber shows relative numbers for fast jumps
:set numberSet tab width 4, shift width 4 and expand tabs to spaces
:set ts=4 sw=4 etEnable before pasting so auto-indent does not cascade; turn it off with :set nopaste
:set pasteTurn on syntax highlighting
:syntax onLeave vi-compatible mode to enable undo trees, completion and plugins
:set nocompatibleOn most distributions vi is a symlink to vim, so behavior depends on compatible mode; classic vi lacks extended :set options and multi-level undo
Start the built-in interactive tutorial; use :help for the full manual
vimtutorThis website uses cookies to ensure you get the best experience on our website. Privacy Policy.