Vim Cheat Sheet by Mode
Organized in the same order of daily use, Normal, Insert, Command Line, Visual.
Back to the dashboard
EscNormal Mode
iInsert Mode
:Command-line Mode
vVisual Mode
Normal Mode (Esc)
Main mode for browsing and editing
Key idea.
In normal mode you navigate, delete, copy and combine movements with actions.
You can always return to this mode with
Esc.
Basic movement in the file
h j k lMove the cursor, left, down, up, right.0Go to the beginning of the line.^Go to the first non-space character.$Go to the end of the line.wNext word start.bBeginning of previous word.eEnd of the current word.ggGo to the beginning of the file.GGo to the end of the file.nGgo to line n.
Movement by blocks and screens
{/}Previous or next paragraph.%Jump to the pair of parentheses or brackets.Ctrl + uMedia pantalla arriba.Ctrl + dMedia pantalla abajo.Ctrl + b/Ctrl + fFull page up or down.HPosition the cursor at the top of the screen.MPosition cursor in the center of the screen.LPosition the cursor at the bottom of the screen.
Quick edit from normal mode
- Basic operators
ddelete,ccambiar,ycopy, always combined with a movement. d{mov}Delete using a movement, for exampledw,d$,d0,d3w.c{mov}Change the text covered by the move and enter insert, for examplecw,c$.y{mov}Copy using a motion, for exampleyw,y$,yapfull paragraph.ddDelete entire line.yyCopy entire line.ccChange entire line and enter insert.D/CDelete or change from the cursor to the end of the line, equivalent tod$yc$.dj/dkDelete current line and the next or the previous one.dGDelete from the current line to the end of the file.dggDelete from the current line to the beginning of the file.n ddDelete n lines, for example5dd.xpSwap two characters, quickly cut and paste.sDelete character under the cursor and enter insert.SDelete entire line and enter insert, similar tocc.rReplace a single character without entering insert.~Reverse upper or lower case of the character under the cursor.gU{mov}/gu{mov}Convert to upper or lower case using a move, for examplegUw.uUndo last action.Ctrl + rRedo the undone action..Repeat the last complete action, key to fast editing.
Copy, paste and indent
yyCopy the entire line.pPaste after the cursor or line.PPaste before the cursor or line.gpPaste and leave the cursor at the end of the pasted text.JJoin the current line with the next one.>>Increase line indentation.<<Decrease line indentation.>{mov}/<{mov}Increase or decrease indentation in the indicated range, e.g.>ap.=o={mov}Auto indentation of the line or range, for example=ap.
Search from normal mode
/textSearch down.?textSearch up.n/NNext or previous match.*Search the word under the down cursor.#Search the word under the cursor up.
Windows, tabs and buffers
Ctrl + w sSplit window horizontally.Ctrl + w vSplit window vertically.Ctrl + w wSwitch to the next window.Ctrl + w h/j/k/lMoverse entre ventanas.:tabnewNew tab with an empty buffer.gt/gTNext or previous tab.:lsList open buffers.:b nGo to buffer number n.
Insert Mode (i)
To enter text and make direct changes
Key idea.
Use insert mode only to type text, then return to normal mode with
Esc to move and edit without touching the mouse.
Enter insert mode
iInsertar antes del cursor.aInsert after the cursor.IInsert at the beginning of the line.AInsert at the end of the line.oCreate new line below and insert.OCreate new line above and insert.ccChange entire line and enter insert.cwCambiar palabra y entrar en insertar.
Exit insert and useful shortcuts
EscReturn to normal mode.Ctrl + hDelete previous character.Ctrl + wDelete previous word.Ctrl + uDelete until start of line.Ctrl + r {register}Paste content from a record.Ctrl + n/Ctrl + pAutocompletar palabras siguientes o anteriores.
Command-line Mode (:)
To save, exit, search, configure.
Key idea.
From normal mode, press
: to open the command line, there you can use any full Vim command, e.g. :w, :q, :help.
Save and exit
:wSave file.:w nuevo_nombreSave as a new file.:qSalir si no hay cambios pendientes.:q!Salir descartando cambios.:wqo:xSave and exit.ZZSave and exit, shortcut from normal mode.ZQExit without saving, shortcut from normal mode.
Global Search and Replace
:%s/viejo/nuevo/gReplace throughout the file.:%s/viejo/nuevo/gcReplace in entire file with commit.:s/viejo/nuevo/Replace only on the current line.:'<,'>s/viejo/nuevo/gReplace within a visual selection.:nohRemove search highlighting.
Work with files, buffers and tabs
:e fileEdit or open a file.:bnext/:bprevNext or previous buffer.:bdClose the current buffer.:tabnewCreate new tab.:tabcloseClose current tab.:split/:vsplitSplit window horizontally or vertically.
Useful configuration options
:set numberShow line numbers.:set relativenumberRelative line numbers.:set hlsearchHighlight search results.:set expandtabConvertir tab en espacios.:set tabstop=4Visible tab size.:set shiftwidth=4Espacios usados al sangrar.:help temaOpen help for a topic, for example:help motion.txt.
Ejemplo compacto de .vimrc
" Recommended basic configuration
set number
set relativenumber
set tabstop=4
set shiftwidth=4
set expandtab
set smartindent
set hlsearch
set incsearch
set clipboard=unnamedplus
set mouse=a
" Useful shortcuts
nnoremap <Space> :nohlsearch<CR>
nnoremap <leader>w :w<CR>
Command line tips
- HistoryUse the up and down arrows to step through previous commands.
- RangesYou can use ranges, for example
:10,20s/old/new/g. - CompletionUse
Tabto complete command and file names. - Save as administratorIf you forgot to open the file with
sudoand don't have permission to save it, use:w !sudo tee %to save changes without leaving Vim. - Delete lines containing KSWMDelete every line in the file containing KSWM, kswm, etc.:
:g/KSWM\c/d
Visual Mode (v)
Select text to copy, delete or modify
Key idea.
In visual mode select text, then apply a command, e.g.
d to delete, y to copy, > to bleed.
Selection types
vSelect by character.VSelect entire lines.Ctrl + vSelect a rectangular block of columns.EscExit Visual mode.oSwitch the active end of the selection.
Actions on selection
yCopy the selection.dClear the selection.cChange the selection and go to insert.>/<Increase or decrease indentation.=Auto indentation of the selection.gU/guConvert to upper or lower case.
Block visual, bulk editing
" Insert text at the start of many lines
Ctrl+v " blockwise Visual mode
j j j " move down to select multiple lines
I " insert at the start of the block
# " type the desired text
Esc " Vim repeats the change on every selected line
Guided replacement with selection
" In Visual mode, select the range
:'<,'>s/viejo/nuevo/gc
" Replace only within the selection, with confirmation