Access all 834 Vim commands in our ultimate Vim cheat sheet.
From basic text editing to advanced mode commands, cursor movements, and file operations – all organized by type.
List of All Vim Commands
Command | Function | Category | Mode |
---|---|---|---|
h | Move cursor left | Navigation | Normal |
j | Move cursor down | Navigation | Normal |
k | Move cursor up | Navigation | Normal |
l | Move cursor right | Navigation | Normal |
gj | Move cursor down (multi-line text) | Navigation | Normal |
gk | Move cursor up (multi-line text) | Navigation | Normal |
H | Move to top of screen | Navigation | Normal |
M | Move to middle of screen | Navigation | Normal |
L | Move to bottom of screen | Navigation | Normal |
w | Jump forwards to start of word | Navigation | Normal |
W | Jump forwards to start of WORD | Navigation | Normal |
e | Jump forwards to end of word | Navigation | Normal |
E | Jump forwards to end of WORD | Navigation | Normal |
b | Jump backwards to start of word | Navigation | Normal |
B | Jump backwards to start of WORD | Navigation | Normal |
ge | Jump backwards to end of word | Navigation | Normal |
gE | Jump backwards to end of WORD | Navigation | Normal |
% | Jump to matching bracket | Navigation | Normal |
0 | Jump to start of line | Navigation | Normal |
^ | Jump to first non-blank char of line | Navigation | Normal |
$ | Jump to end of line | Navigation | Normal |
g_ | Jump to last non-blank char of line | Navigation | Normal |
gg | Go to first line | Navigation | Normal |
G | Go to last line | Navigation | Normal |
{n}G | Go to line n | Navigation | Normal |
{n}gg | Go to line n | Navigation | Normal |
gd | Go to local declaration | Navigation | Normal |
gD | Go to global declaration | Navigation | Normal |
fx | Jump to next occurrence of x | Navigation | Normal |
Fx | Jump to previous occurrence of x | Navigation | Normal |
tx | Jump to before next occurrence of x | Navigation | Normal |
Tx | Jump to after previous occurrence of x | Navigation | Normal |
; | Repeat last f/t/F/T movement | Navigation | Normal |
, | Repeat last f/t/F/T movement backwards | Navigation | Normal |
} | Jump to next paragraph/function | Navigation | Normal |
{ | Jump to previous paragraph/function | Navigation | Normal |
]] | Jump to next section | Navigation | Normal |
[[ | Jump to previous section | Navigation | Normal |
][ | Jump to end of section | Navigation | Normal |
[] | Jump to end of previous section | Navigation | Normal |
zz | Center cursor on screen | Navigation | Normal |
zt | Position cursor at top of screen | Navigation | Normal |
zb | Position cursor at bottom of screen | Navigation | Normal |
Ctrl+e | Scroll down one line | Navigation | Normal |
Ctrl+y | Scroll up one line | Navigation | Normal |
Ctrl+b | Scroll up one page | Navigation | Normal |
Ctrl+f | Scroll down one page | Navigation | Normal |
Ctrl+d | Scroll down half page | Navigation | Normal |
Ctrl+u | Scroll up half page | Navigation | Normal |
Ctrl+o | Jump to older position | Navigation | Normal |
Ctrl+i | Jump to newer position | Navigation | Normal |
g; | Go to older change | Navigation | Normal |
g, | Go to newer change | Navigation | Normal |
gi | Go to last insert position | Navigation | Normal |
gv | Go to last visual selection | Navigation | Normal |
g* | Search word under cursor (partial) | Navigation | Normal |
g# | Search word under cursor backwards (partial) | Navigation | Normal |
* | Search word under cursor | Navigation | Normal |
# | Search word under cursor backwards | Navigation | Normal |
x | Delete character under cursor | Editing | Normal |
X | Delete character before cursor | Editing | Normal |
dd | Delete current line | Editing | Normal |
D | Delete from cursor to end of line | Editing | Normal |
d{motion} | Delete text specified by motion | Editing | Normal |
diw | Delete inner word | Editing | Normal |
daw | Delete a word | Editing | Normal |
dip | Delete inner paragraph | Editing | Normal |
dap | Delete a paragraph | Editing | Normal |
d$ | Delete to end of line | Editing | Normal |
d0 | Delete to start of line | Editing | Normal |
d^ | Delete to first non-blank character | Editing | Normal |
dG | Delete to end of file | Editing | Normal |
dgg | Delete to start of file | Editing | Normal |
cc | Change entire line | Editing | Normal |
C | Change from cursor to end of line | Editing | Normal |
c{motion} | Change text specified by motion | Editing | Normal |
ciw | Change inner word | Editing | Normal |
caw | Change a word | Editing | Normal |
cip | Change inner paragraph | Editing | Normal |
cap | Change a paragraph | Editing | Normal |
c$ | Change to end of line | Editing | Normal |
c0 | Change to start of line | Editing | Normal |
c^ | Change to first non-blank character | Editing | Normal |
s | Delete character and enter insert mode | Editing | Normal |
S | Delete line and enter insert mode | Editing | Normal |
r{char} | Replace single character | Editing | Normal |
R | Enter replace mode | Editing | Normal |
yy | Yank (copy) current line | Editing | Normal |
Y | Yank from cursor to end of line | Editing | Normal |
y{motion} | Yank text specified by motion | Editing | Normal |
yiw | Yank inner word | Editing | Normal |
yaw | Yank a word | Editing | Normal |
yip | Yank inner paragraph | Editing | Normal |
yap | Yank a paragraph | Editing | Normal |
p | Paste after cursor | Editing | Normal |
P | Paste before cursor | Editing | Normal |
]p | Paste and adjust indent | Editing | Normal |
[p | Paste before and adjust indent | Editing | Normal |
gp | Paste after and move cursor | Editing | Normal |
gP | Paste before and move cursor | Editing | Normal |
J | Join line below | Editing | Normal |
gJ | Join line below without space | Editing | Normal |
>> | Indent line | Editing | Normal |
<< | Unindent line | Editing | Normal |
== | Auto-indent line | Editing | Normal |
>% | Indent a block | Editing | Normal |
<% | Unindent a block | Editing | Normal |
=% | Auto-indent a block | Editing | Normal |
>ip | Indent inner paragraph | Editing | Normal |
Unindent inner paragraph | Editing | Normal | |
=ip | Auto-indent inner paragraph | Editing | Normal |
gu{motion} | Make lowercase | Editing | Normal |
gU{motion} | Make uppercase | Editing | Normal |
g~{motion} | Toggle case | Editing | Normal |
guu | Lowercase line | Editing | Normal |
gUU | Uppercase line | Editing | Normal |
g~~ | Toggle case of line | Editing | Normal |
u | Undo | Editing | Normal |
U | Undo all changes on line | Editing | Normal |
Ctrl+r | Redo | Editing | Normal |
. | Repeat last change | Editing | Normal |
~ | Toggle case of character | Editing | Normal |
g& | Repeat last substitute on all lines | Editing | Normal |
gv | Reselect last visual selection | Editing | Normal |
gq{motion} | Format text to textwidth | Editing | Normal |
gwip | Format inner paragraph | Editing | Normal |
gJ | Join lines without space | Editing | Normal |
g/pattern/d | Delete lines matching pattern | Editing | Normal |
v/pattern/d | Delete lines not matching pattern | Editing | Normal |
i | Enter insert mode before cursor | Insert | Normal |
I | Enter insert mode at line start | Insert | Normal |
a | Enter insert mode after cursor | Insert | Normal |
A | Enter insert mode at line end | Insert | Normal |
o | Open new line below and insert | Insert | Normal |
O | Open new line above and insert | Insert | Normal |
gi | Insert at last insert position | Insert | Normal |
gI | Insert at column 1 | Insert | Normal |
Ctrl+h | Delete character before cursor | Insert | Insert |
Ctrl+w | Delete word before cursor | Insert | Insert |
Ctrl+u | Delete all characters before cursor in line | Insert | Insert |
Ctrl+j | Begin new line | Insert | Insert |
Ctrl+t | Indent current line | Insert | Insert |
Ctrl+d | Unindent current line | Insert | Insert |
Ctrl+n | Insert next match of word before cursor | Insert | Insert |
Ctrl+p | Insert previous match of word before cursor | Insert | Insert |
Ctrl+r {reg} | Insert contents of register | Insert | Insert |
Ctrl+r = | Insert result of expression | Insert | Insert |
Ctrl+r % | Insert current filename | Insert | Insert |
Ctrl+r # | Insert alternate filename | Insert | Insert |
Ctrl+r / | Insert last search pattern | Insert | Insert |
Ctrl+r : | Insert last command line | Insert | Insert |
Ctrl+r . | Insert last inserted text | Insert | Insert |
Ctrl+a | Insert previously inserted text | Insert | Insert |
Ctrl+@ | Insert previously inserted text and stop insert | Insert | Insert |
Ctrl+o | Execute one normal mode command | Insert | Insert |
Ctrl+v {char} | Insert character literally | Insert | Insert |
Ctrl+v {number} | Insert character by decimal value | Insert | Insert |
Ctrl+k {char1} {char2} | Insert character by digraph | Insert | Insert |
Ctrl+x Ctrl+l | Line completion | Insert | Insert |
Ctrl+x Ctrl+n | Keyword completion from current file | Insert | Insert |
Ctrl+x Ctrl+k | Dictionary completion | Insert | Insert |
Ctrl+x Ctrl+t | Thesaurus completion | Insert | Insert |
Ctrl+x Ctrl+i | Keyword completion from included files | Insert | Insert |
Ctrl+x Ctrl+] | Tag completion | Insert | Insert |
Ctrl+x Ctrl+f | File path completion | Insert | Insert |
Ctrl+x Ctrl+d | Definition completion | Insert | Insert |
Ctrl+x Ctrl+v | Vim command line completion | Insert | Insert |
Ctrl+x Ctrl+u | User defined completion | Insert | Insert |
Ctrl+x Ctrl+o | Omni completion | Insert | Insert |
Ctrl+x s | Spelling suggestions | Insert | Insert |
Ctrl+x Ctrl+e | Scroll window up | Insert | Insert |
Ctrl+x Ctrl+y | Scroll window down | Insert | Insert |
Ctrl+e | Insert character from below | Insert | Insert |
Ctrl+y | Insert character from above | Insert | Insert |
Shift+Left | Move cursor left | Insert | Insert |
Shift+Right | Move cursor right | Insert | Insert |
Shift+Up | Move cursor up | Insert | Insert |
Shift+Down | Move cursor down | Insert | Insert |
Home | Move cursor to start of line | Insert | Insert |
End | Move cursor to end of line | Insert | Insert |
PageUp | Scroll window up | Insert | Insert |
PageDown | Scroll window down | Insert | Insert |
v | Enter character-wise visual mode | Visual | Normal |
V | Enter line-wise visual mode | Visual | Normal |
Ctrl+v | Enter block-wise visual mode | Visual | Normal |
gv | Reselect last visual selection | Visual | Normal |
o | Move cursor to other end of selection | Visual | Visual |
O | Move cursor to other corner of block | Visual | Visual |
aw | Select a word | Visual | Visual |
iw | Select inner word | Visual | Visual |
aW | Select a WORD | Visual | Visual |
iW | Select inner WORD | Visual | Visual |
as | Select a sentence | Visual | Visual |
is | Select inner sentence | Visual | Visual |
ap | Select a paragraph | Visual | Visual |
ip | Select inner paragraph | Visual | Visual |
ab | Select a block (()) | Visual | Visual |
ib | Select inner block (()) | Visual | Visual |
aB | Select a block ({}) | Visual | Visual |
iB | Select inner block ({}) | Visual | Visual |
at | Select a tag block (<>) | Visual | Visual |
it | Select inner tag block (<>) | Visual | Visual |
a’ | Select a single quoted string | Visual | Visual |
i’ | Select inner single quoted string | Visual | Visual |
a” | Select a double quoted string | Visual | Visual |
i” | Select inner double quoted string | Visual | Visual |
a` | Select a backtick string | Visual | Visual |
i` | Select inner backtick string | Visual | Visual |
a] | Select a [] block | Visual | Visual |
i] | Select inner [] block | Visual | Visual |
a> | Select a <> block | Visual | Visual |
i> | Select inner <> block | Visual | Visual |
d | Delete selection | Visual | Visual |
y | Yank selection | Visual | Visual |
c | Change selection | Visual | Visual |
s | Substitute selection | Visual | Visual |
r | Replace selection with character | Visual | Visual |
> | Indent selection | Visual | Visual |
< | Unindent selection | Visual | Visual |
= | Auto-indent selection | Visual | Visual |
~ | Toggle case of selection | Visual | Visual |
u | Make selection lowercase | Visual | Visual |
U | Make selection uppercase | Visual | Visual |
J | Join selected lines | Visual | Visual |
: | Enter command line for selected lines | Visual | Visual |
Ctrl+a | Increment number in selection | Visual | Visual |
Ctrl+x | Decrement number in selection | Visual | Visual |
g Ctrl+a | Increment numbers in selection | Visual | Visual |
g Ctrl+x | Decrement numbers in selection | Visual | Visual |
I | Insert at start of visual block | Visual | Visual Block |
A | Append at end of visual block | Visual | Visual Block |
c | Change visual block | Visual | Visual Block |
C | Change till end of visual block | Visual | Visual Block |
$ | Extend block to end of lines | Visual | Visual Block |
o | Move to other corner of block | Visual | Visual Block |
O | Move to other corner horizontally | Visual | Visual Block |
p | Paste over visual selection | Visual | Visual |
P | Paste before visual selection | Visual | Visual |
x | Delete visual selection | Visual | Visual |
D | Delete till end of visual selection | Visual | Visual |
Y | Yank visual selection | Visual | Visual |
gq | Format selected text | Visual | Visual |
gw | Format selected text and maintain cursor | Visual | Visual |
g? | ROT13 encode selection | Visual | Visual |
! | Filter selection through external command | Visual | Visual |
:w | Write (save) file | File Operations | Command |
:w filename | Write to filename | File Operations | Command |
:w! | Force write | File Operations | Command |
:q | Quit | File Operations | Command |
:q! | Force quit | File Operations | Command |
:wq | Write and quit | File Operations | Command |
😡 | Write if changed and quit | File Operations | Command |
:wa | Write all buffers | File Operations | Command |
:qa | Quit all buffers | File Operations | Command |
:wqa | Write and quit all buffers | File Operations | Command |
:e filename | Edit filename | File Operations | Command |
:e! | Reload current file | File Operations | Command |
:e# | Edit alternate file | File Operations | Command |
:r filename | Read file into current buffer | File Operations | Command |
:r !command | Read command output into buffer | File Operations | Command |
:saveas filename | Save as filename | File Operations | Command |
:f filename | Rename current file | File Operations | Command |
:bn | Next buffer | Buffer | Command |
:bp | Previous buffer | Buffer | Command |
:bd | Delete buffer | Buffer | Command |
:buffers | List all buffers | Buffer | Command |
:ball | Load all buffers | Buffer | Command |
:badd filename | Add file to buffer list | Buffer | Command |
:set option | Set option | Settings | Command |
:set option? | Show option value | Settings | Command |
:set option& | Reset option to default | Settings | Command |
:setlocal option | Set option for current buffer/window | Settings | Command |
:map key command | Map key to command | Mapping | Command |
:nmap key command | Map key in normal mode | Mapping | Command |
:vmap key command | Map key in visual mode | Mapping | Command |
:imap key command | Map key in insert mode | Mapping | Command |
:unmap key | Remove mapping | Mapping | Command |
:marks | Show all marks | Marks | Command |
:jumps | Show jump list | Navigation | Command |
:changes | Show changes list | History | Command |
:reg | Show registers | Registers | Command |
:ls | List buffers | Buffer | Command |
:cd path | Change directory | File Operations | Command |
:pwd | Print working directory | File Operations | Command |
:!command | Execute shell command | Shell | Command |
:make | Run make command | Build | Command |
:copen | Open quickfix window | Quickfix | Command |
:cclose | Close quickfix window | Quickfix | Command |
:cnext | Next quickfix item | Quickfix | Command |
:cprev | Previous quickfix item | Quickfix | Command |
:grep pattern files | Grep for pattern | Search | Command |
:vimgrep pattern files | Vim internal grep | Search | Command |
:%s/old/new/g | Replace old with new globally | Search/Replace | Command |
:%s/old/new/gc | Replace with confirmation | Search/Replace | Command |
:g/pattern/command | Execute command on matching lines | Global | Command |
:v/pattern/command | Execute command on non-matching lines | Global | Command |
:sort | Sort lines | Text Processing | Command |
:retab | Convert tabs to spaces | Text Processing | Command |
:source file | Source vimscript file | Scripting | Command |
:syntax on/off | Toggle syntax highlighting | Display | Command |
:highlight | Show highlight groups | Display | Command |
:filetype on/off | Toggle filetype detection | Filetype | Command |
:split | Split window horizontally | Window | Command |
:vsplit | Split window vertically | Window | Command |
:new | Create new window | Window | Command |
:close | Close current window | Window | Command |
:only | Close all windows except current | Window | Command |
:tabnew | Create new tab | Tab | Command |
:tabclose | Close current tab | Tab | Command |
:tabnext | Go to next tab | Tab | Command |
:tabprevious | Go to previous tab | Tab | Command |
:undo number | Go to specific undo state | History | Command |
:earlier time | Go to earlier state | History | Command |
:later time | Go to later state | History | Command |
:hardcopy | Print document | File Operations | Command |
:mksession file | Save session to file | Session | Command |
:source session | Load session from file | Session | Command |
Ctrl+w s | Split window horizontally | Window | Normal |
Ctrl+w v | Split window vertically | Window | Normal |
Ctrl+w n | Create new window | Window | Normal |
Ctrl+w q | Quit current window | Window | Normal |
Ctrl+w c | Close current window | Window | Normal |
Ctrl+w o | Make current window only one | Window | Normal |
Ctrl+w j | Move cursor to window below | Window | Normal |
Ctrl+w k | Move cursor to window above | Window | Normal |
Ctrl+w h | Move cursor to window left | Window | Normal |
Ctrl+w l | Move cursor to window right | Window | Normal |
Ctrl+w w | Move cursor to next window | Window | Normal |
Ctrl+w W | Move cursor to previous window | Window | Normal |
Ctrl+w p | Move cursor to previous window | Window | Normal |
Ctrl+w r | Rotate windows downwards/rightwards | Window | Normal |
Ctrl+w R | Rotate windows upwards/leftwards | Window | Normal |
Ctrl+w x | Exchange current window with next | Window | Normal |
Ctrl+w = | Make all windows equal size | Window | Normal |
Ctrl+w _ | Maximize window height | Window | Normal |
Ctrl+w | Maximize window width | Window | |
Ctrl+w + | Increase window height | Window | Normal |
Ctrl+w – | Decrease window height | Window | Normal |
Ctrl+w > | Increase window width | Window | Normal |
Ctrl+w < | Decrease window width | Window | Normal |
Ctrl+w T | Move window to new tab | Window | Normal |
Ctrl+w H | Move window to far left | Window | Normal |
Ctrl+w L | Move window to far right | Window | Normal |
Ctrl+w J | Move window to bottom | Window | Normal |
Ctrl+w K | Move window to top | Window | Normal |
:sb buffer | Split window and edit buffer | Buffer/Window | Command |
:vert sb buffer | Vertically split window and edit buffer | Buffer/Window | Command |
:buffers | List all buffers | Buffer | Command |
:ls | List all buffers | Buffer | Command |
:ball | Load all buffers in windows | Buffer | Command |
:vertical ball | Load all buffers in vertical windows | Buffer | Command |
:bn | Go to next buffer | Buffer | Command |
:bp | Go to previous buffer | Buffer | Command |
:bf | Go to first buffer | Buffer | Command |
:bl | Go to last buffer | Buffer | Command |
:bd | Delete current buffer | Buffer | Command |
:bd! | Force delete current buffer | Buffer | Command |
:bw | Wipe out current buffer | Buffer | Command |
:badd file | Add file to buffer list | Buffer | Command |
:bunload | Unload current buffer | Buffer | Command |
:buffer num | Go to buffer num | Buffer | Command |
:buffer file | Go to buffer file | Buffer | Command |
:bdelete num | Delete buffer num | Buffer | Command |
:bdelete file | Delete buffer file | Buffer | Command |
:bufdo command | Execute command on all buffers | Buffer | Command |
:tab sball | Open all buffers in tabs | Buffer/Tab | Command |
:unhide | Open window for each loaded buffer | Buffer/Window | Command |
:windo command | Execute command on all windows | Window | Command |
:wincmd command | Execute window command | Window | Command |
:resize n | Set window height to n | Window | Command |
:vertical resize n | Set window width to n | Window | Command |
:leftabove split | Split window, new window above | Window | Command |
:rightbelow split | Split window, new window below | Window | Command |
:leftabove vsplit | Split window, new window left | Window | Command |
:rightbelow vsplit | Split window, new window right | Window | Command |
:e | Reload current file | File | Command |
:e filename | Edit filename | File | Command |
:e! | Reload file, discard changes | File | Command |
:enew | Create new empty buffer | File | Command |
:find filename | Find and edit filename | File | Command |
:w | Write current file | File | Command |
:w filename | Write to filename | File | Command |
:w! | Force write | File | Command |
:w !sudo tee % | Write with sudo permissions | File | Command |
:wn | Write and move to next file | File | Command |
:wN | Write and move to previous file | File | Command |
:wa | Write all changed buffers | File | Command |
:wa! | Force write all buffers | File | Command |
:saveas filename | Save file as filename | File | Command |
:update | Write if buffer changed | File | Command |
:write ++enc=encoding | Write with specific encoding | File | Command |
:write ++ff=format | Write with specific format | File | Command |
:write ++bin | Write in binary mode | File | Command |
:read filename | Insert file contents | File | Command |
:read !command | Insert command output | File | Command |
:edit +num file | Open file at line num | File | Command |
:edit +/pat file | Open file at pattern pat | File | Command |
:edit # | Edit alternate file | File | Command |
:browse e | Open file browser | File | Command |
:cd path | Change working directory | File | Command |
:cd – | Change to previous directory | File | Command |
:pwd | Print working directory | File | Command |
:file | Show current file info | File | Command |
:file name | Set filename | File | Command |
:filetype | Display filetype | File | Command |
:filetype on/off | Toggle filetype detection | File | Command |
gf | Go to file under cursor | File | Normal |
gF | Go to file under cursor (with line number) | File | Normal |
:oldfiles | List recently edited files | File | Command |
:browse oldfiles | Browse recently edited files | File | Command |
:mksession file | Save session to file | File | Command |
:source file | Load session from file | File | Command |
:mkview | Save view configuration | File | Command |
:loadview | Load view configuration | File | Command |
:hardcopy | Print document | File | Command |
:TOhtml | Convert to HTML | File | Command |
:earlier time | Revert to earlier state | File | Command |
:later time | Revert to later state | File | Command |
:recover | Recover swap file | File | Command |
:preserve | Preserve swap file | File | Command |
:DiffOrig | Diff with original file | File | Command |
ZZ | Write if changed and quit | File | Normal |
ZQ | Quit without checking changes | File | Normal |
😡 | Write if changed and quit | File | Command |
:exit | Same as 😡 | File | Command |
:wq | Write and quit | File | Command |
:xit | Same as 😡 | File | Command |
:q | Quit | File | Command |
:q! | Force quit | File | Command |
:qa | Quit all | File | Command |
:qa! | Force quit all | File | Command |
:wqa | Write all and quit | File | Command |
:xa | Same as :wqa | File | Command |
/pattern | Search forward for pattern | Search | Normal |
?pattern | Search backward for pattern | Search | Normal |
n | Repeat search forward | Search | Normal |
N | Repeat search backward | Search | Normal |
* | Search forward for word under cursor | Search | Normal |
# | Search backward for word under cursor | Search | Normal |
g* | Search forward for partial word under cursor | Search | Normal |
g# | Search backward for partial word under cursor | Search | Normal |
gd | Go to local declaration | Search | Normal |
gD | Go to global declaration | Search | Normal |
:%s/old/new/g | Replace all occurrences in file | Replace | Command |
:%s/old/new/gc | Replace all occurrences with confirmation | Replace | Command |
:s/old/new/g | Replace all occurrences in line | Replace | Command |
:s/old/new/gc | Replace all occurrences in line with confirmation | Replace | Command |
:{range}s/old/new/g | Replace in range | Replace | Command |
:g/pattern/s/old/new/g | Replace in lines matching pattern | Replace | Command |
:v/pattern/s/old/new/g | Replace in lines not matching pattern | Replace | Command |
:&& | Repeat last substitute | Replace | Command |
:~ | Repeat last substitute with last search pattern | Replace | Command |
:g/pattern | List lines matching pattern | Search | Command |
:v/pattern | List lines not matching pattern | Search | Command |
:vimgrep pattern files | Search in multiple files | Search | Command |
:grep pattern files | External grep search | Search | Command |
:lgrep pattern files | External grep search (location list) | Search | Command |
:copen | Open quickfix window | Search | Command |
:lopen | Open location list window | Search | Command |
:cnext | Next quickfix item | Search | Command |
:cprev | Previous quickfix item | Search | Command |
:cfirst | First quickfix item | Search | Command |
:clast | Last quickfix item | Search | Command |
:lnext | Next location list item | Search | Command |
:lprev | Previous location list item | Search | Command |
:lfirst | First location list item | Search | Command |
:llast | Last location list item | Search | Command |
:cdo command | Execute command on each quickfix item | Search | Command |
:ldo command | Execute command on each location list item | Search | Command |
:noh | Clear search highlighting | Search | Command |
:set hlsearch | Enable search highlighting | Search | Command |
:set nohlsearch | Disable search highlighting | Search | Command |
:set incsearch | Enable incremental search | Search | Command |
:set noincsearch | Disable incremental search | Search | Command |
:set ignorecase | Enable case-insensitive search | Search | Command |
:set noignorecase | Disable case-insensitive search | Search | Command |
:set smartcase | Enable smart case search | Search | Command |
:set nosmartcase | Disable smart case search | Search | Command |
gn | Select next search match | Search | Normal |
gN | Select previous search match | Search | Normal |
:promptfind | Open GUI find dialog | Search | Command |
:promptrepl | Open GUI replace dialog | Search | Command |
m{a-zA-Z} | Set mark {a-zA-Z} at cursor position | Marks | Normal |
‘{a-zA-Z} | Jump to line of mark {a-zA-Z} | Marks | Normal |
`{a-zA-Z} | Jump to position of mark {a-zA-Z} | Marks | Normal |
:marks | List all marks | Marks | Command |
:delmarks {marks} | Delete specified marks | Marks | Command |
:delmarks! | Delete all marks for current buffer | Marks | Command |
” | Jump to last jump position | Marks | Normal |
“ | Jump to exact last jump position | Marks | Normal |
‘. | Jump to position of last change | Marks | Normal |
`. | Jump to exact position of last change | Marks | Normal |
‘[ | Jump to start of last changed/yanked text | Marks | Normal |
‘] | Jump to end of last changed/yanked text | Marks | Normal |
‘< | Jump to start of last visual selection | Marks | Normal |
‘> | Jump to end of last visual selection | Marks | Normal |
‘0 | Jump to position where Vim was last exited | Marks | Normal |
‘1-‘9 | Jump to positions of last 9 files exited | Marks | Normal |
“{a-z} | Use register {a-z} for next delete/yank/put | Registers | Normal |
“{A-Z} | Append to register {a-z} | Registers | Normal |
“” | Unnamed register (last delete/yank) | Registers | Normal |
“0 | Yank register | Registers | Normal |
“1-“9 | Delete registers (historical) | Registers | Normal |
“: | Last command register | Registers | Normal |
“. | Last inserted text register | Registers | Normal |
“% | Current filename register | Registers | Normal |
“# | Alternate filename register | Registers | Normal |
“/ | Last search pattern register | Registers | Normal |
“= | Expression register | Registers | Normal |
“* | System clipboard register (X11 primary) | Registers | Normal |
“+ | System clipboard register (X11 clipboard) | Registers | Normal |
“_ | Black hole register | Registers | Normal |
:reg | Display contents of all registers | Registers | Command |
:reg {arg} | Display contents of specified registers | Registers | Command |
Ctrl+r {reg} | Insert contents of register in insert mode | Registers | Insert |
@{reg} | Execute contents of register as macro | Registers | Normal |
“xy{motion} | Yank {motion} text into register x | Registers | Normal |
“xp | Put contents of register x after cursor | Registers | Normal |
“xP | Put contents of register x before cursor | Registers | Normal |
:let @x = “string” | Set register x to “string” | Registers | Command |
:let @x .= “string” | Append “string” to register x | Registers | Command |
:let @/ = “pattern” | Set search pattern | Registers | Command |
:let @” = “string” | Set unnamed register | Registers | Command |
:let @* = “string” | Set system clipboard | Registers | Command |
:let @+ = “string” | Set system clipboard (X11) | Registers | Command |
“% | Name of current file | Registers | Normal |
“# | Name of alternate file | Registers | Normal |
“. | Last inserted text | Registers | Normal |
“: | Last command-line | Registers | Normal |
“/ | Last search pattern | Registers | Normal |
“= | Result of expression | Registers | Normal |
“* | GUI selection | Registers | Normal |
“+ | GUI clipboard | Registers | Normal |
“~ | Drop register | Registers | Normal |
“_ | Black hole | Registers | Normal |
aw | A word | Text Object | Normal/Visual |
iw | Inner word | Text Object | Normal/Visual |
aW | A WORD | Text Object | Normal/Visual |
iW | Inner WORD | Text Object | Normal/Visual |
as | A sentence | Text Object | Normal/Visual |
is | Inner sentence | Text Object | Normal/Visual |
ap | A paragraph | Text Object | Normal/Visual |
ip | Inner paragraph | Text Object | Normal/Visual |
a] or a[ | A [] block | Text Object | Normal/Visual |
i] or i[ | Inner [] block | Text Object | Normal/Visual |
a) or ab | A () block | Text Object | Normal/Visual |
i) or ib | Inner () block | Text Object | Normal/Visual |
a> or a< | A <> block | Text Object | Normal/Visual |
i> or i< | Inner <> block | Text Object | Normal/Visual |
a} or aB | A {} block | Text Object | Normal/Visual |
i} or iB | Inner {} block | Text Object | Normal/Visual |
at | A tag block | Text Object | Normal/Visual |
it | Inner tag block | Text Object | Normal/Visual |
a” | A double quoted string | Text Object | Normal/Visual |
i” | Inner double quoted string | Text Object | Normal/Visual |
a’ | A single quoted string | Text Object | Normal/Visual |
i’ | Inner single quoted string | Text Object | Normal/Visual |
a` | A backtick string | Text Object | Normal/Visual |
i` | Inner backtick string | Text Object | Normal/Visual |
d{motion} | Delete text specified by {motion} | Operator | Normal |
c{motion} | Change text specified by {motion} | Operator | Normal |
y{motion} | Yank text specified by {motion} | Operator | Normal |
>{motion} | Indent text specified by {motion} | Operator | Normal |
<{motion} | Unindent text specified by {motion} | Operator | Normal |
={motion} | Auto-indent text specified by {motion} | Operator | Normal |
g~{motion} | Toggle case of text specified by {motion} | Operator | Normal |
gu{motion} | Make text specified by {motion} lowercase | Operator | Normal |
gU{motion} | Make text specified by {motion} uppercase | Operator | Normal |
!{motion} | Filter text through external command | Operator | Normal |
gq{motion} | Format text specified by {motion} | Operator | Normal |
gw{motion} | Format text specified by {motion} and keep cursor | Operator | Normal |
g?{motion} | ROT13 encode text specified by {motion} | Operator | Normal |
zf{motion} | Create fold for text specified by {motion} | Operator | Normal |
g@{motion} | Call function set by ‘operatorfunc’ | Operator | Normal |
diw | Delete inner word | Operation | Normal |
ciw | Change inner word | Operation | Normal |
yiw | Yank inner word | Operation | Normal |
daw | Delete a word | Operation | Normal |
caw | Change a word | Operation | Normal |
yaw | Yank a word | Operation | Normal |
di( | Delete inside parentheses | Operation | Normal |
ci( | Change inside parentheses | Operation | Normal |
yi( | Yank inside parentheses | Operation | Normal |
da( | Delete around parentheses | Operation | Normal |
ca( | Change around parentheses | Operation | Normal |
ya( | Yank around parentheses | Operation | Normal |
dit | Delete inside tag | Operation | Normal |
cit | Change inside tag | Operation | Normal |
yit | Yank inside tag | Operation | Normal |
dat | Delete around tag | Operation | Normal |
cat | Change around tag | Operation | Normal |
yat | Yank around tag | Operation | Normal |
q{a-z} | Start recording macro into register {a-z} | Macro | Normal |
q | Stop recording macro | Macro | Normal |
@{a-z} | Execute macro in register {a-z} | Macro | Normal |
@@ | Execute last executed macro | Macro | Normal |
{count}@{a-z} | Execute macro {count} times | Macro | Normal |
:reg {a-z} | Show contents of macro register | Macro | Command |
“ap | Paste contents of macro register to edit | Macro | Normal |
“{a-z}yy | Yank current line into macro register | Macro | Normal |
:let @a=” | Clear macro register a | Macro | Command |
:let @a.=’commands’ | Append to macro register a | Macro | Command |
qa | Start recording into register a | Macro | Normal |
q | End recording | Macro | Normal |
:normal @a | Execute macro on each line in range | Macro | Command |
:argdo normal @a | Execute macro on each file in argument list | Macro | Command |
:bufdo normal @a | Execute macro on each buffer | Macro | Command |
:windo normal @a | Execute macro on each window | Macro | Command |
:tabdo normal @a | Execute macro on each tab | Macro | Command |
:global/pattern/normal @a | Execute macro on matching lines | Macro | Command |
“ap | Paste macro contents | Macro | Normal |
“{reg}yy | Yank line into register | Macro | Normal |
:let @a=@b | Copy macro from register b to a | Macro | Command |
:let @a=@a[1:] | Remove first character of macro | Macro | Command |
:let @a=@a[:-2] | Remove last character of macro | Macro | Command |
:break | Break out of macro execution | Macro | Command |
:continue | Continue macro execution | Macro | Command |
:return | Return from macro execution | Macro | Command |
:silent normal @a | Execute macro silently | Macro | Command |
:verbose normal @a | Execute macro verbosely | Macro | Command |
:while condition | Start while loop in macro | Macro | Command |
:endwhile | End while loop in macro | Macro | Command |
:if condition | Start if condition in macro | Macro | Command |
:endif | End if condition in macro | Macro | Command |
:for item in list | Start for loop in macro | Macro | Command |
:endfor | End for loop in macro | Macro | Command |
zf{motion} | Create fold | Folding | Normal |
zF | Create fold for [count] lines | Folding | Normal |
:{range}fo[ld] | Create fold for range | Folding | Command |
zd | Delete fold at cursor | Folding | Normal |
zD | Delete fold at cursor recursively | Folding | Normal |
zE | Eliminate all folds | Folding | Normal |
zo | Open fold under cursor | Folding | Normal |
zO | Open fold under cursor recursively | Folding | Normal |
zc | Close fold under cursor | Folding | Normal |
zC | Close fold under cursor recursively | Folding | Normal |
za | Toggle fold under cursor | Folding | Normal |
zA | Toggle fold under cursor recursively | Folding | Normal |
zv | View cursor line (open folds) | Folding | Normal |
zx | Update folds and open cursor fold | Folding | Normal |
zX | Update folds | Folding | Normal |
zm | Fold more (reduce foldlevel) | Folding | Normal |
zM | Close all folds | Folding | Normal |
zr | Fold less (increase foldlevel) | Folding | Normal |
zR | Open all folds | Folding | Normal |
zi | Toggle folding | Folding | Normal |
[z | Move to start of current fold | Folding | Normal |
]z | Move to end of current fold | Folding | Normal |
zj | Move downwards to start of next fold | Folding | Normal |
zk | Move upwards to end of previous fold | Folding | Normal |
zn | Disable folding | Folding | Normal |
zN | Enable folding | Folding | Normal |
:set foldmethod=manual | Set manual folding | Folding | Command |
:set foldmethod=indent | Set indent folding | Folding | Command |
:set foldmethod=marker | Set marker folding | Folding | Command |
:set foldmethod=syntax | Set syntax folding | Folding | Command |
:set foldmethod=expr | Set expression folding | Folding | Command |
:set foldmethod=diff | Set diff folding | Folding | Command |
:set foldlevel=n | Set fold level to n | Folding | Command |
:set foldcolumn=n | Show fold column of width n | Folding | Command |
:set foldminlines=n | Minimum lines for a fold | Folding | Command |
:set foldnestmax=n | Maximum fold nesting | Folding | Command |
:set foldtext=string | Set text displayed for closed folds | Folding | Command |
:set foldmarker=str,str | Set fold markers | Folding | Command |
:set foldignore=char | Set chars to ignore in indent folding | Folding | Command |
:set foldenable | Enable folding | Folding | Command |
:set nofoldenable | Disable folding | Folding | Command |
zj | Move downwards to next fold | Folding | Normal |
zk | Move upwards to previous fold | Folding | Normal |
[z | Move to start of current open fold | Folding | Normal |
]z | Move to end of current open fold | Folding | Normal |
:fold | Create fold for current line | Folding | Command |
:foldclose | Close fold | Folding | Command |
:foldopen | Open fold | Folding | Command |
:diffsplit {filename} | Split window and show diff | Diff | Command |
:vert diffsplit {filename} | Vertical split and show diff | Diff | Command |
:diffpatch {patchfile} | Apply patch and show diff | Diff | Command |
:diffthis | Make current window part of diff | Diff | Command |
:diffoff | Turn off diff mode | Diff | Command |
:diffoff! | Turn off diff mode in all windows | Diff | Command |
:diffupdate | Update diff colors | Diff | Command |
do | Diff obtain (get change from other window) | Diff | Normal |
dp | Diff put (put change to other window) | Diff | Normal |
]c | Jump to next change | Diff | Normal |
[c | Jump to previous change | Diff | Normal |
:diffget | Get changes from other window | Diff | Command |
:diffput | Put changes to other window | Diff | Command |
:diffget //2 | Get changes from file 2 in 3-way diff | Diff | Command |
:diffget //3 | Get changes from file 3 in 3-way diff | Diff | Command |
:set diffopt+=iwhite | Ignore whitespace in diff | Diff | Command |
:set diffopt+=horizontal | Horizontal diff split | Diff | Command |
:set diffopt+=vertical | Vertical diff split | Diff | Command |
:set diffopt+=filler | Show filler lines | Diff | Command |
:set diffopt+=context:n | Set context lines | Diff | Command |
:set diffexpr=MyDiff() | Set custom diff expression | Diff | Command |
vimdiff file1 file2 | Start vim in diff mode | Diff | Shell |
:windo diffthis | Diff all windows | Diff | Command |
:diffs | Show diff stats | Diff | Command |
:diffo | Turn off diff mode | Diff | Command |
:set noscrollbind | Disable scroll binding | Diff | Command |
:set scrollbind | Enable scroll binding | Diff | Command |
:set cursorbind | Enable cursor binding | Diff | Command |
:set nocursorbind | Disable cursor binding | Diff | Command |
:set diffopt+=icase | Ignore case differences | Diff | Command |
:set diffopt+=iwhite | Ignore whitespace changes | Diff | Command |
:set diffopt+=iwhiteall | Ignore all whitespace | Diff | Command |
:set diffopt+=iwhiteeol | Ignore whitespace at EOL | Diff | Command |
:set diffopt+=filler | Show filler lines | Diff | Command |
:set diffopt+=context:3 | Set context lines to 3 | Diff | Command |
:set diffopt+=horizontal | Prefer horizontal splits | Diff | Command |
:set diffopt+=vertical | Prefer vertical splits | Diff | Command |
:set diffopt+=internal | Use internal diff | Diff | Command |
:set diffopt+=algorithm:patience | Use patience diff algorithm | Diff | Command |
:set diffopt+=indent-heuristic | Use indent heuristic | Diff | Command |
]c | Next difference | Diff | Normal |
[c | Previous difference | Diff | Normal |
:1,$+1diffget | Get all changes from other window | Diff | Command |
:1,$+1diffput | Put all changes to other window | Diff | Command |
Ctrl+] | Jump to tag under cursor | Tags | Normal |
Ctrl+t | Jump back from tag | Tags | Normal |
:tag {tag} | Jump to tag | Tags | Command |
:tags | Show tag stack | Tags | Command |
:tselect {tag} | Select from multiple tags | Tags | Command |
:tjump {tag} | Jump to tag or select if multiple | Tags | Command |
:tnext | Jump to next matching tag | Tags | Command |
:tprev | Jump to previous matching tag | Tags | Command |
:tfirst | Jump to first matching tag | Tags | Command |
:tlast | Jump to last matching tag | Tags | Command |
g] | Show all tags under cursor | Tags | Normal |
:ptag {tag} | Preview tag | Tags | Command |
:pclose | Close preview window | Tags | Command |
:ptjump {tag} | Preview tag and jump | Tags | Command |
Ctrl+n | Next completion | Completion | Insert |
Ctrl+p | Previous completion | Completion | Insert |
Ctrl+x Ctrl+n | Keywords in current file | Completion | Insert |
Ctrl+x Ctrl+i | Keywords in included files | Completion | Insert |
Ctrl+x Ctrl+] | Tags completion | Completion | Insert |
Ctrl+x Ctrl+k | Dictionary completion | Completion | Insert |
Ctrl+x Ctrl+l | Whole line completion | Completion | Insert |
Ctrl+x Ctrl+f | File path completion | Completion | Insert |
Ctrl+x Ctrl+o | Omni completion | Completion | Insert |
Ctrl+x Ctrl+v | Command line completion | Completion | Insert |
Ctrl+x Ctrl+u | User defined completion | Completion | Insert |
Ctrl+x Ctrl+s | Spelling suggestions | Completion | Insert |
Ctrl+x s | Spelling suggestions | Completion | Insert |
:set spell | Enable spell checking | Spell | Command |
:set nospell | Disable spell checking | Spell | Command |
:set spelllang=en_us | Set spelling language | Spell | Command |
]s | Next misspelled word | Spell | Normal |
[s | Previous misspelled word | Spell | Normal |
z= | Suggest corrections | Spell | Normal |
zg | Add word to spell file | Spell | Normal |
zw | Mark word as wrong | Spell | Normal |
zug | Undo zg or zw | Spell | Normal |
:spellr | Repeat last z= | Spell | Command |
:spelldump | Create spell file | Spell | Command |
:spellinfo | Show spell file info | Spell | Command |
== | Format current line | Format | Normal |
=% | Format code block | Format | Normal |
gg=G | Format entire file | Format | Normal |
:retab | Convert tabs to spaces | Format | Command |
:set expandtab | Use spaces instead of tabs | Format | Command |
:set noexpandtab | Use tabs | Format | Command |
:set shiftwidth=n | Set indentation width | Format | Command |
:set tabstop=n | Set tab width | Format | Command |
gq{motion} | Format text to textwidth | Format | Normal |
gw{motion} | Format text and keep cursor | Format | Normal |
:left | Left align text | Format | Command |
:center | Center align text | Format | Command |
:right | Right align text | Format | Command |
gR | Enter Replace mode | Special | Normal |
gh | Enter Select mode | Special | Normal |
gH | Enter Line Select mode | Special | Normal |
Ctrl+v | Enter Visual Block mode | Special | Normal |
Q | Enter Ex mode | Special | Normal |
gQ | Enter Ex mode | Special | Normal |
:terminal | Enter Terminal mode | Special | Command |
:help {plugin-name} | Show plugin help | Plugin | Command |
:scriptnames | List all loaded scripts | Plugin | Command |
:packadd {plugin} | Load optional plugin | Plugin | Command |
:packloadall | Load all plugins | Plugin | Command |
:runtime {file} | Source runtime files | Plugin | Command |
:Explore | Open file explorer | Netrw | Command |
:Sexplore | Split and explore | Netrw | Command |
:Vexplore | Vertical split and explore | Netrw | Command |
:Texplore | Tab explore | Netrw | Command |
:Lexplore | Left explorer toggle | Netrw | Command |
% | Create new file | Netrw | Normal |
d | Create new directory | Netrw | Normal |
D | Delete file/directory | Netrw | Normal |
R | Rename file/directory | Netrw | Normal |
P | Open in previous window | Netrw | Normal |
i | Cycle view mode | Netrw | Normal |
gh | Toggle hidden files | Netrw | Normal |
mf | Mark file | Netrw | Normal |
mr | Mark files using regex | Netrw | Normal |
mt | Current target directory | Netrw | Normal |
mm | Move marked files | Netrw | Normal |
mc | Copy marked files | Netrw | Normal |
% | Jump between matching pairs | Matchit | Normal |
g% | Jump backwards between matches | Matchit | Normal |
[% | Jump to previous unmatched group | Matchit | Normal |
]% | Jump to next unmatched group | Matchit | Normal |
a% | Select between matching pairs | Matchit | Visual |
:Man {topic} | View man page | Man | Command |
K | View man page for word under cursor | Man | Normal |
\K | View custom keywordprg for word | Man | Normal |
:make | Run make command | Compiler | Command |
:compiler {name} | Set compiler | Compiler | Command |
:copen | Open quickfix window | Compiler | Command |
:cclose | Close quickfix window | Compiler | Command |
:cnext | Next error | Compiler | Command |
:cprevious | Previous error | Compiler | Command |
:cfirst | First error | Compiler | Command |
:clast | Last error | Compiler | Command |
:terminal | Open terminal window | Terminal | Command |
Ctrl+w N | Terminal Normal mode | Terminal | Terminal |
i or a | Return to Terminal mode | Terminal | Terminal-Normal |
:term {cmd} | Run command in terminal | Terminal | Command |
Ctrl+\ Ctrl+n | Enter Terminal-Normal mode | Terminal | Terminal |
:TOhtml | Convert to HTML | Plugin | Command |
:RefreshGuiFont | Refresh GUI font | Plugin | Command |
:LoadProfiles | Load color profiles | Plugin | Command |
:SaveProfiles | Save color profiles | Plugin | Command |
:DoMatchParen | Enable match parentheses | Plugin | Command |
:NoMatchParen | Disable match parentheses | Plugin | Command |
:helptags ALL | Generate help tags | Plugin | Command |
:runtime! plugin/**/*.vim | Load all plugins | Plugin | Command |
:verbose scriptnames | List scripts with source | Plugin | Command |
:finish | Stop sourcing script | Plugin | Command |
:profile start {file} | Start profiling | Plugin | Command |
:profile func * | Profile all functions | Plugin | Command |
:profile file * | Profile all files | Plugin | Command |
Basic Vim Commands
Let’s start with an easy set of Vim commands to open, save, and exit Vim.
:e filename | Open filename for edition |
:w | Save file |
:q | Exit Vim |
:q! | Quit without saving |
😡 | Write file (if changes has been made) and exit |
:sav filename | Saves file as filename |
. | Repeats the last change made in normal mode |
Moving in the File
While in command mode, the following set of commands will allow you to easily move the cursor in the file, jump to a particular line number, or set the cursor position at the beginning of the file.
k or Up Arrow | move the cursor position up one line |
j or Down Arrow | move the cursor down one line |
e | move the cursor to the end of the word |
b | move the cursor to the begining of the word |
0 | move the cursor to the begining of the line |
G | move the cursor to the end of the file |
gg | move the cursor to the begining of the file |
L | move the cursor to the bottom of the screen |
:59 | move cursor to line number 59. Replace 59 by the desired line number. |
% | Move cursor to matching parenthesis |
[[ | Jump to function start |
[{ | Jump to block start |
Cut, Copy & Paste
Here are some basic Vim commands to cut, copy and paste portions of text. All the commands below has to be ran in command mode.
y | Copy the selected text to clipboard |
p | Paste clipboard contents |
dd | Cut current line |
yy | Copy current line |
y$ | Copy to end of line |
D | Cut to end of line |
Search
In command mode, you can easily search for any string within a file. This is extremely useful for developers and sysadmins alike.
/word | Search word from top to bottom |
?word | Search word from bottom to top |
* | Search the word under cursor |
/cstring | Search STRING or string, case insensitive |
/jo[ha]n | Search john or joan |
/< the | Search the, theatre or then |
/the> | Search the or breathe |
/fred|joe | Search fred or joe |
/<dddd> | Search exactly 4 digits |
/^n{3} | Find 3 empty lines |
:bufdo /searchstr/ | Search in all open files |
bufdo %s/something/somethingelse/g | Search something in all the open buffers and replace it with somethingelse |
Replace
Vim command line tool is extremely useful to replace many occurences of a string by another within a file. Using more advanced commands, there are a lot of search and replace options available.
:%s/old/new/g | Replace all occurences of old by new in file |
:%s/onward/forward/gi | Replace onward by forward, case unsensitive |
:%s/old/new/gc | Replace all occurences with confirmation |
:%s/^/hello/g | Replace the begining of each line by hello |
:%s/$/Harry/g | Replace the end of each line by Harry |
:%s/onward/forward/gi | Replace onward by forward, case unsensitive |
:%s/ *$//g | Delete all white spaces |
:g/string/d | Delete all lines containing string |
:v/string/d | Delete all lines containing which didn’t contain string |
:s/Bill/Steve/ | Replace the first occurence of Bill by Steve in current line |
:s/Bill/Steve/g | Replace Bill by Steve in current line |
:%s/Bill/Steve/g | Replace Bill by Steve in all the file |
:%s/^M//g | Delete DOS carriage returns (^M) |
:%s/r/r/g | Transform DOS carriage returns in returns |
:%s#<[^>]+>##g | Delete HTML tags but keeps text |
:%s/^(.*)n1$/1/ | Delete lines which appears twice |
Ctrl+a | Increment number under the cursor |
Ctrl+x | Decrement number under cursor |
ggVGg? | Change text to Rot13 |
Case
Vim has some powerful commands to modify the case of text. All the commands below have to be run in command mode.
Vu | Lowercase line |
VU | Uppercase line |
g~~ | Invert case |
vEU | Switch word to uppercase |
vE~ | Modify word case |
ggguG | Set all text to lowercase |
gggUG | Set all text to uppercase |
:set ignorecase | Ignore case in searches |
:set smartcase | Ignore case in searches excepted if an uppercase letter is used |
:%s/<./u&/g | Sets first letter of each word to uppercase |
:%s/<./l&/g | Sets first letter of each word to lowercase |
:%s/.*/u& | Sets first letter of each line to uppercase |
:%s/.*/l& | Sets first letter of each line to lowercase |
Read and Write Files
Vim is clearly one of the most powerful text editors available. This section shows how you can manipulate files, insert the content of a file into another, and export portions of a file into a new file.
:1,10 w outfile | Saves lines 1 to 10 in outfile |
:1,10 w >> outfile | Appends lines 1 to 10 to outfile |
:r infile | Insert the content of infile |
:23r infile | Insert the content of infile under line 23 |
File Explorer
Vim features a built in file explorer, which allows you to explorer the content of your server without exiting the text editor.
:e . | Open integrated file explorer |
:Sex | Split window and open integrated file explorer |
:Sex! | Same as :Sex but split window vertically |
:browse e | Graphical file explorer |
:ls | List buffers |
:cd .. | Move to parent directory |
:args | List files |
:args *.php | Open file list |
:grep expression *.php | Returns a list of .php files contening expression |
gf | Open file name under cursor |
Interact With Unix
Vim is installed by default on most Unix based operating systems, including Mac OS and most GNU/Linux distros. It therefore feature various commands that allows you to interact with the OS.
:!pwd | Execute the pwd unix command, then returns to Vi |
!!pwd | Execute the pwd unix command and insert output in file |
:sh | Temporary returns to Unix |
$exit | Retourns to Vi |
Alignment
In command mode, you can quickly and easily align a file’s lines for better clarity.
:%!fmt | Align all lines |
!}fmt | Align all lines at the current position |
5!!fmt | Align the next 5 lines |
Tabs and Windows
One of my favorite Vim options is the ability to use tabs to edit various files at the same time. The following Vim commands will let you open, close, and organize your tabs for better productivity.
:tabnew | Creates a new tab |
gt | Show next tab |
:tabfirst | Show first tab |
:tablast | Show last tab |
:tabm n(position) | Rearrange tabs |
:tabdo %s/foo/bar/g | Execute a command in all tabs |
:tab ball | Puts all open files in tabs |
:new abc.txt | Edit abc.txt in new window |
Window Spliting
Vim allows you to split the screen horizontally or vertically, so you can edit many files at once using the insert mode.
:e filename | Edit filename in current window |
:split filename | Split the window and open filename |
ctrl-w up arrow | Puts cursor in top window |
ctrl-w ctrl-w | Puts cursor in next window |
ctrl-w_ | Maximize current window vertically |
ctrl-w| | Maximize current window horizontally |
ctrl-w= | Gives the same size to all windows |
10 ctrl-w+ | Add 10 lines to current window |
:vsplit file | Split window vertically |
:sview file | Same as :split in readonly mode |
:hide | Close current window |
:nly | Close all windows, excepted current |
:b 2 | Open #2 in this window |
Auto-Completion
Vim can use external dictionaries to provide auto-completion. This can be a real time saver, so pay attention to the commands below if you want to speed up your workflow.
Ctrl+n Ctrl+p (To be used in insert mode) | Complete word |
Ctrl+x Ctrl+l | Complete line |
:set dictionary=dict | Define dict as a dictionnary |
Ctrl+x Ctrl+k | Complete with dictionnary |
Marks
When editing large files, it can be tricky to move in the file and remember important sections. Happily, Vim allows its users to create marks that can easily be accessed later. No need to remember a dozen of line numbers anymore!
m {a-z} | Marks current position as {a-z} |
‘ {a-z} | Move to position {a-z} |
” | Move to previous position |
Abbreviations
This little known trick lets you define abbreviations that can be reused later and as many times as needed.
:ab mail mail@provider.org | Define mail as abbreviation of mail@provider.org |
Text Indentation
Text indentation is vital when it comes to code readability. Luckily, Vim has a set of commands for the text editor to indent your lines in a clear and readable manner.
:set autoindent | Turn on auto-indent |
:set smartindent | Turn on intelligent auto-indent |
:set shiftwidth=4 | Defines 4 spaces as indent size |
ctrl-t, ctrl-d | Indent/un-indent in insert mode |
>> | Indent |
<< | Un-indent |
=% | Indent the code between parenthesis |
1GVG= | Indent the whole file |
Frequently Asked Questions (FAQ)
How do I Type Commands in Vim?
To type commands, you have to first activate Vim’s command mode. To do so, press the Esc
key of your keyboard. You can then type any command of your choice.
How do I Start Typing Text in Vim?
Vim must be in insert mode for you to type text. Simply press the i
key when in command mode to enter the insert mode.
On Which Hosting Plans Can You Use Vim?
Basically any Linux hosting will have Vim installed on the server. As long as you are able to access your server via SSH, you’ll be able to use Vim. Please refer to our best web hosting for developers guide to find out which hosts provide a SSH access.