Vim and Tmux shortcuts and commands (Printer version)



Key / Command Action / Results
gj, gk On long wrapped lines, these commands go down and up in the line "visually": (inside the line, not jumping to the next line), like in several other editors.
gg and G Go to first or last line of the document
<Number>G or X% Move cursor to the line number <Number> or the X% of the file
Ctrl+f and Ctrl+b Scroll 1 page Forward or Backwards
Ctrl+e and Ctrl+y Scroll 1 line Forward or Backwards
H and M and L Place the cursor on the High, Medium or Low line of the screen. Allows verbs (dH = delete to top of screen)
zt and zz and zb Alter the "viewable window" so that the current line is in the top, zenter (center) or bottom of the screen
w and b Move cursor a word forward and backwards (W and B for works with hyphens, etc)
e and E Move cursor at the end of the next or previous word (E and gE for works with hyphens, etc)
{ and } Move cursor a paragraph (or block of code) forward and backwards
% Move cursor to the matching parenthesis, curly braces, quotes, etc ( ( ), [ ], { }, ' ', " " …
t<char> and T<char> Move cursor to first ocurrence of <char> forward (t) or backwards (T). Supports multipliers (2tX) and verbs (dfX)
f<char> and F<char> Move cursor to first ocurrence of <char> forward (f) or backwards (F), included <char> itself. Supports multipliers and verbs.
; or , Repeat the execution of the last fFtT command (forward or backwards)
gi and g; and '. Move to the last edited line (or the exact cursor position)
m[a-z] Mark current cursor position locally (Lowercase marks = mark for this file).
m[A-Z] Mark current cursor position globally (Uppercase marks). You can return to this file and position later at any moment.
'[a-z] and `[a-z] Go to line marked. Change to the list (') or to the exact cursor position of the mark (`)
'' and `` Return to the position on which we were before a mark-jump (great!)
'^ Go back to the last line you were in Insert Mode (and actually inserted text)
'[ and '] Go back to the first ([) or last (]) line of the latest block modified in the document.
F7 or ,hs Hide the Sign Column (remove marks from the screen, eg to copy with mouse:w)

Alter text

Key / Command Action / Results
i and I Insert text at cursor or at Beginning of Line
a and A Insert text at right of the cursor or at End of Line
o and O Insert empty new line after or before the current one (and switch ot Insert mode)
S or cc and C Substitute entire line (replace line with S) or from cursor to end (with C), and switch ot Insert mode. C is synonym of c$.
r<char> and c<char> Replace character under cursor in command mode, with <char>. r remains in command mode and supports multipliers like 10rX, c replaces the char and switches to Insert mode.
J Join the current line with the next one
x and X Delete char under cursor, or char left to cursor (backspace). Synonyms of dl and dh.
D or d$ Delete from cursor to end of line (copies text to buffer, keeps command mode). Also d0 or d^ to beginning of line
yy and dd Yank (copy) or delete current line (delete also copies to the default buffer).
y$ or Y Yank (copy) from cursor to end of line
. Repeat the last command that altered the document. Very useful for repetitive changes or repeating the last "complex" command quickly.
ci<char> and di<char> Change or delete the text between <char> and <char>. Where <char> can be ', ", (, {, [ and <. So we can use di( or di) to delete all the content inside ( and ) (with cursor anywhere inside the parenthesis). Also works for strings with the quotes/double-quotes char di" ⇒ quick way of delete the content of a string.
cit Like ciX but for tag entities (like <p> and </p>)
u and Ctrl+r Undo and Redo changes (multiple times). Also :earlier 1h 30m or :later 30m
:earlier <time> and :later <time> Rewind or advance changes in time: (ex: :earlier 1h and then later: 10m)
diw and daw Delete the word under the cursor, no matter where the cursor is located inside the word (daw includes spaces) - Also with 'c' verb.
dis and das Delete the sentence (until a dot) under the cursor (das includes spaces) - Also with 'c' verb
dat Delete a tag (html, xml, etc).

Copy, Paste and Delete

Key / Command Action / Results
p and P Paste default buffer contents after and before the current line. Supports multipliers (2p).
]p Paste default buffer contents reindenting it to the appropiate level based on the place where we paste (auto indents code)
v and V Visual selection (using cursors or hjkl) for characters or full lines
Ctrl+v Block Visual selection (copy and paste blocks!)
gv Grab last selection (ex: gvA to append text after last selection).
gV Select last pasted text (ex, for indenting).
ggVG Select all the content (gg = go line 1, V = visual mode, G = go EOF).
d and y and c (in visual mode) Delete, copy or replace the selection. d and y keep command mode while c switches to insert mode.
d`a and c`a and y`a Delete, cut or copy from the current cursor position to mark 'a or `a
"[a-z]<vim-command> Use register a-z before the y, p, d commands to use one of Vim's 26 registers (instead of using the default Unnamed register "). Ex: "zdd and then "zp
"[A-Z]<vim-command> Use register A-Z before the y, p, d commands to APPEND to one of Vim's 26 registers
%!external-command Filter the entire file (or visual selection with :!command*) through a command (ex: %!sort
%r filename or %r !external-command Insert the contents of a file or the output of a command inside our file (ex: %r !date

The following ranges are available for some of the operations:

  • % ⇒ all the document (ex: %!sort).
  • n,M ⇒ block from line n to lime M (ex: 15,20d).
  • 'a,'b ⇒ block from mark a to mark b (ex: :'a,'b s/replace/string/g).
  • '<,'> ⇒ current visual block content (just press : to get it on the command line).

Appart from the default buffer ("the unnamed buffer" or ") the following additional buffers (registers) are available for buffer operations:

  • "a to "z ⇒ 26 available buffers. Preffix your operation with the register name: Ex: "ayy and "ap
  • "A to "Z (uppercase) ⇒ ADD content to the 26 available buffers (add content at the bottom of the register) Ex: "Ayy
  • "_ ⇒ Black hole register (really delete content and don't store in a buffer, don't overwriting current " buffer).
  • "0 ⇒ Content of the most recent yank operation ("0, the yank-register).
  • "* and "+ ⇒ Contents of System and X11 clipboard.
  • :registers ⇒ See the contents of the available registers.
  • let @a = "My buffer content" ⇒ Set the value of a given register. * :%s/PATTERN/\=@a/g ⇒ Use a buffer value in a replacement.

Files, Windows and Buffers

Key / Command Action / Results
:e filename Open a file in the current buffer
:enew or ,b Open a new, empty buffer
gf Open the filename under the cursor (great for opening include/require files)
:bp (or C-n, or ,p) Move to previous buffer
:bn (or C-m, or ,n) Move to next buffer
:bd (or C-D, or :bD!) Close buffer
:bf or :bl) Move to first or last buffer
:bn (or C-m Move to next or previous buffer (close with :bd, :bD! or C-D). Also :bf and :bl for first and last.
Ctrl+w v and Ctrl+w s Split window vertically or horizontally
Ctrl+w cursors and Ctrl+w h/j/k/l Move among windows (up, down, left, right…)
Ctrl+w q and Ctrl+w c Close current window (user :q! if not saved)
Ctrl+w + and Ctrl+w - Resize horizontal split in 1 unit (+ or -). Also :resize +-N
Ctrl+w < and Ctrl+w > Resize vertical split in 1 unit (+ or -)
Ctrl+w _ Maximize current window size (make all other windows of size=1)
Ctrl+w = Make all windows equal size
Ctrl+w o Make this window the only one (close all others)
Ctrl+w r and Ctrl+w x Rotate or swap window order
:sp filename or :split filename Open a file in a new horizontal split
:vsp filename or :vsplit filename Open a file in a new vertical split
vim file1.txt file2.txt *.c Open multiple files in buffers
vim -o *.txt or vim -O *.txt Open (from the command line) a set of files in horizontal or vertical splits
vim -u NONE Launch Vim withour reading .vimrc file
vim +NUMBER or vim + or vim +/PATTERN Launch Vim in line N, in last line, or in first ocurrence of PATTERN
command |vim - Launch Vim editing output of command (save it with :w filename)

Search and replace

Key / Command Action / Results
* and # Search the word under the cursor forward and backwards. Use it again to repeat. Highlights matches if using set hlsearch.
/<string> and ?<string> Search <string> forward and backwards. String can be a regular expression (see below)
n and N Go to next or previous search ocurrence
/\c<string> and ?\c<string> Ignore case on a search
d/<string> and y/<string> Searches also admits actions: delete or copy from cursor to next ocurrence of string
/\V<string> and ?\V<string> Insert \V to treat strings as "raw strings" and not regexps
%s/regexp1/string/modifiers Replace ocurrences of "regexp1" with "string".
%s/\Vstring/string/modifiers Insert \V to treat the search string as "raw string" and not regexp
%g/regexp1/action Apply action(s) to all lines matching regexp1 (example: :%g/DONE/d deletes all lines containing the string DONE). Lots of commands can be used (jklm, p, f, etc). Ex: g/BAR(/ normal nf(iT
%v/regexp1/action Apply action(s) to all lines NOT matching regexp1 (example: :%g/TODO/d

Replacement modifiers:

  • i = case insensitive
  • g = replace all ocurrences in the same line (without g, only the first one).
  • c = ask for confirmation

Searches (with / and ?) and the search of replacements follow Vim's regular expression format (different from Perl's):

  • The following characters have special Action / Results like in regexps: ^ $ . * [ ] / \ ? ~.
  • The following characters need to be escaped with \ to have special Action / Results: < > | ( ) +.
  • Capture groups with parenthesis are referenced with \NUMBER.
  • Vim doesn't support the non-greedy modifier (?) after *. Instead of .*, it uses .\{-}.
  • You don't need to escape anything in the substitution string except the backslash (for \1, \2…).
  • The substitution string accepts \0 as the whole matched pattern and \r as a "split line in this point" tag.


/mystring                           # simple string search
/I have 1\$ in the bank             # Escape $ because we don't want end of line
/red\|green\|blue                   # OR (|) between terms
/\<completeword\>                   # <word> = search for complete word (not substrings)
/\<\(\d\+\)\>                       # integer number
:%s/cad1/cad2/gi                    # simple string replacement
:%s|cad1|cad2|g                     # Use a different separator to free / from escaping
:%s/red\|green\|blue/purple/g       # search regexp
:%s//purple/g                       # reuse last search with replacement
:'<,'>s//purple/g                   # apply replacement only to selection
:%s/style=".\{-}"//g.               # non-greedy operator (like .*? in Perl)
:%s/\s\+$//e                        # Remove trailing blanks at end of line
:%g/PATTERN/d                       # Delete all the lines matching regexp 'PATTERN'
:%g/PATTERN/d_                       # Delete all the lines matching regexp 'PATTERN' (to blackhole register)
:%v/PATTERN/d   or  :!g/PATTERN/d   # Delete all the lines NOT matching regexp 'PATTERN'
:%g/PATTERN/t$                      # Copy all lines containing Pattern to the end of the file
:%g/PATTERN/m$                      # Move all lines containing Pattern to the end of the file

Operating in the Visual Mode

While in visual mode, we can use not only cursors and ijkl to select text, but also the standard Vim verbs like 0, $, G, gg, and movements like fCHAR, /string, n (next search result), and:

Key / Command Action / Results
viX Select the entire block based on X, where X can be:
w or W ⇒ word
s ⇒ sentence
p ⇒ paragraph
b or ( ⇒ block of parenthesis (content inside ( and ) ).
B or { ⇒ block of { braces }
t ⇒ a <tag> and </tag> block
< ⇒ a < and > block
[ ⇒ a [ and ] block
" or ' ⇒ string (block of quotes)
NOTE: Closing tags also work, like ), ], etc.
Ex: vi"d (strings) or vibd (function arguments)
vaX Select the entire block based on X. Like iX but includes the surrounding spaces if present.

Programming aid

Key / Command Action / Results
zf Create a fold with the selected lines (or movement like zf/string or zf}
zd and zE Delete one or all the folds in the file (just the fold itself, not the content)
za Open/Close current fold (Also <space> with mapping - see custom mappings section below)
zM and zR Open/Close all the existing folds in the file
== Indent current line (or selection) with the auto-indent (based of the language/filetype)
>> and << Indent line or selection by 1 level
~, u and U Change caseof the char under the cursor, or the selection. (~ = toggle, u = make lowercase and U = make uppercase)
Ctrl+] and Ctrl+t o Jump to the ctags definition of the word under the cursor to go back from the jump
Ctrl+v <char> Insert raw char (ex: tab, ^M, etc)
vi"d (or vi"c) Delete or change the content of a double quoted string. Also works vi', vi{, vi[, vi(, vi<, etc. for the content of {}, [], (), <> blocks.
* and # Search FW or BW (and highlight all ocurrences) for the word under the cursor
gd and gD Move to the local or global declaration of the variable under the cursor
:retab Replace tabs with blocks of spaces


Key / Command Action / Results
,e or ,b or ,n or :e Open Vim's native file explorer (netrw) and use these shortcuts inside netrw window:
d Create new directory
% Create and open a new file
D Delete a file or directory
R Rename a file or directory
o or v Open the file in a horizontal or vertical split
/STRING Find filename into the netrw window

Plugins mappings

Key / Command Plugin Action / Results
,ci NERDCommenter Toggles comments on current line or each selection line individually (not aligned)
,cb and ,cb NERDCommenter Toggles left or both comments on current line or each selection line (aligned)
,cc and ,cu NERDCommenter Comments out or uncomments the current line or selection
,c$ NERDCommenter Comments the line from the current cursor position to the end of line
,ca NERDCommenter Changes to the alternate set of comment / delimiters
cs'" Surround Inside a string delimited by single quotes, replace them with double quotes (also cs"')
ds' Surround Delete quotes (can be also used with tags like ds<p>)
Ctrl+p Ctrlp Fuzzy search
Tab and Ctrl+v Tab Supertab Tab completion and insert real tab (use Ctrl+x Ctrl+o for Vim's autocomplete)
,ac or ,autoclose Autoclose Toggle autoclose plugin (for pairs of quotes, parenthesis, etc)
,td or ,todo TaskLists Open TaskList plugin window (TODO lines)
F8 or ,tags or ,tagbar Tagbar Open Tagbar (ctags) Windows
,n1 and ,n0 numbers Toggle highlight current cursor column or line
<F3> numbers Alternate between relative and absolute numbers (Plugin numbers.vim)
,ch Syntastic Toggle syntastic syntax analysis
Ctrl+w u undoquit Undo last Window close / quit / :q!
Ctrl+C searchant Cancel last search (hide search highlight


  • Write a string in multiple lines:
    • In the beggining of the lines: Ctrl+V ⇒ I ⇒ write text ⇒ ESC ⇒ wait 1 second
    • In the ed of the lines: Ctrl+V ⇒ $ ⇒ A ⇒ write text ⇒ ESC ⇒ wait 1 second
  • Repeat a string N times:
    • <nowikiw>60i-<ESC><ENTER>
    • 10iHellow<ENTER><ESC><ENTER>


C-a ? Help
C-a d Detach terminal for a "tmux attach / tmux list-sessions / tmux attach -t NNN"


C-a c Create Window
C-a p and C-a n Previous / Next Window (also C-a + PgUp/PgDown or cursors
C-a [0-9] Move to Window N
C-a & Close current Window
C-a w Display list of windows (use cursors to select one)
C-a , and C-a . Change Window title and Window Number in status bar

Buffer mode:

C-a ] or C-a Space Change to buffer history mode (C-a PgUp also changes + does PgUp)
hjkl, PgUp/Dn, Cursors Move in buffer mode
C-a f Search in buffer mode
Space and Enter Start selection and end+copy selection in buffer mode
ESC and q ESC cancels current selection and 'q' exists buffer mode
C-a [ Paste current buffer (there are several buffers, use C-a # to show/select buffer)
C-a :show-buffer Show the content of the current selection (accepts -b NUMBER)
C-a :list-buffers or C-a # Show buffers contents (they rotate)
C-a :choose-buffer or C-a = Choose one of the existing buffers as "current"
C-a :save-buffer file.txt Save buffer content to file. Accepts -b NUMBER.
tmux save-buffer file.txt Save buffer from the command-line (calling tmux binary)


C-a - Split window horizontally (also C-a %
C-a | Split window vertically (also C-a "
C-a x Kill current pane
C-a ! Convert current pane into a full screen window
C-a cursor Move between panes
C-a Control-cursor and C-a Alt-cursor Resize current pane in 1 or 5 units
C-a { and C-a } Exchange current panel with previous or next

<Volver a la sección de GNU/Linux>