Normal Mode (Esc)

Main mode for browsing and editing
N
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.
  • 0 Go to the beginning of the line.
  • ^ Go to the first non-space character.
  • $ Go to the end of the line.
  • w Next word start.
  • b Beginning of previous word.
  • e End of the current word.
  • gg Go to the beginning of the file.
  • G Go to the end of the file.
  • nG go 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.
  • H Position the cursor at the top of the screen.
  • M Position cursor in the center of the screen.
  • L Position the cursor at the bottom of the screen.
Quick edit from normal mode
  • Basic operatorsd delete, c cambiar, y copy, always combined with a movement.
  • d{mov} Delete using a movement, for example dw, d$, d0, d3w.
  • c{mov} Change the text covered by the move and enter insert, for example cw, c$.
  • y{mov} Copy using a motion, for example yw, y$, yap full paragraph.
  • dd Delete entire line.
  • yy Copy entire line.
  • cc Change entire line and enter insert.
  • D / C Delete or change from the cursor to the end of the line, equivalent to d$ y c$.
  • dj / dk Delete current line and the next or the previous one.
  • dG Delete from the current line to the end of the file.
  • dgg Delete from the current line to the beginning of the file.
  • n dd Delete n lines, for example 5dd.
  • xp Swap two characters, quickly cut and paste.
  • s Delete character under the cursor and enter insert.
  • S Delete entire line and enter insert, similar to cc.
  • r Replace 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 example gUw.
  • u Undo last action.
  • Ctrl + r Redo the undone action.
  • . Repeat the last complete action, key to fast editing.
Copy, paste and indent
  • yy Copy the entire line.
  • p Paste after the cursor or line.
  • P Paste before the cursor or line.
  • gp Paste and leave the cursor at the end of the pasted text.
  • J Join 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
  • /text Search down.
  • ?text Search up.
  • n / N Next or previous match.
  • * Search the word under the down cursor.
  • # Search the word under the cursor up.
Windows, tabs and buffers
  • Ctrl + w s Split window horizontally.
  • Ctrl + w v Split window vertically.
  • Ctrl + w w Switch to the next window.
  • Ctrl + w h/j/k/l Moverse entre ventanas.
  • :tabnew New tab with an empty buffer.
  • gt / gT Next or previous tab.
  • :ls List open buffers.
  • :b n Go to buffer number n.

Insert Mode (i)

To enter text and make direct changes
I
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
  • i Insertar antes del cursor.
  • a Insert after the cursor.
  • I Insert at the beginning of the line.
  • A Insert at the end of the line.
  • o Create new line below and insert.
  • O Create new line above and insert.
  • cc Change entire line and enter insert.
  • cw Cambiar palabra y entrar en insertar.
Exit insert and useful shortcuts
  • Esc Return to normal mode.
  • Ctrl + h Delete previous character.
  • Ctrl + w Delete previous word.
  • Ctrl + u Delete until start of line.
  • Ctrl + r {register} Paste content from a record.
  • Ctrl + n / Ctrl + p Autocompletar 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
  • :w Save file.
  • :w nuevo_nombre Save as a new file.
  • :q Salir si no hay cambios pendientes.
  • :q! Salir descartando cambios.
  • :wq o :x Save and exit.
  • ZZ Save and exit, shortcut from normal mode.
  • ZQ Exit without saving, shortcut from normal mode.
Global Search and Replace
  • :%s/viejo/nuevo/g Replace throughout the file.
  • :%s/viejo/nuevo/gc Replace in entire file with commit.
  • :s/viejo/nuevo/ Replace only on the current line.
  • :'<,'>s/viejo/nuevo/g Replace within a visual selection.
  • :noh Remove search highlighting.
Work with files, buffers and tabs
  • :e file Edit or open a file.
  • :bnext / :bprev Next or previous buffer.
  • :bd Close the current buffer.
  • :tabnew Create new tab.
  • :tabclose Close current tab.
  • :split / :vsplit Split window horizontally or vertically.
Useful configuration options
  • :set number Show line numbers.
  • :set relativenumber Relative line numbers.
  • :set hlsearch Highlight search results.
  • :set expandtab Convertir tab en espacios.
  • :set tabstop=4 Visible tab size.
  • :set shiftwidth=4 Espacios usados al sangrar.
  • :help tema Open 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 Tab to complete command and file names.
  • Save as administratorIf you forgot to open the file with sudo and 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
V
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
  • y Copy the selection.
  • d Clear the selection.
  • c Change the selection and go to insert.
  • > / < Increase or decrease indentation.
  • = Auto indentation of the selection.
  • gU / gu Convert 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