Home · Linux · Vim · Programming · Trees · Quests

Vim Quick Reference

Work in progress. This is a good one, too: https://vim.rtorr.com/

Modes

Esc Enter normal/default mode
i Insert mode
R Replace mode
v Visual/select mode
V Select whole lines

Files, Buffers, Tabs, Shell

e file Open file in new buffer
:ls List buffers
:b# Switch to buffer #
bd Close current buffer
:tabnew [file] Open a new tab with optional file name
gt gT Go to next, previous tab
:tabclose Close current tab
cd dir, pwd Change directory to dir, display current directory path
!cmd Execute shell command cmd
:term Open a terminal pane; exit to close

Basic Navigation

h j k l Move left, down, up, right
CTRL-u,d,f,b Move up or down half screen, full screen
w b e Move to next, previous word; use W, B to include punctuation; e, E goes to end of word rather than beginning
H L gg G Move to top, bottom of screen, file
/regex n N Search for regex, go to next result, previous result
fx, Fx Jump to next/previous character x on current line
0 ^ $ Move to beginning or first character of line, end of line
:# Jump to line number
{ } Jump to beginning, end of paragraph

Editing Tricks

#x Perform command x # times, ex: 3j moves down 3 lines
. Repeat the last action
u, CTRL-R Undo, redo the last action
rx Replace character at cursor with x
cw Delete word at cursor and enter insert mode
:%s/x/y/g Replace all instances of regex x with y
x Delete/yank/cut character under cursor
dd Delete/yank/cut current line
U, u Make selected text upper, lower case
~ Toggle capitalization of character or selection
"+y Yank selection to system clipboard

File Explorer

Read this post

:Explore Opens the file explorer
:Vexplore/Sexplore File explorer in vertical/horizontal split
:Lex/Sex Like Vexplore/Sexplore but uses current pwd rather than location of current file

Screen Splits (Windows)

:sp Splits current file in two horizontal panes
:vsp Splits current file in two vertical panes
:q Close current pane
CTRL-w h,j,k,l Move pane focus down, up, right, left
CTRL-w # <, > Move vertical split left or right # columns
CTRL-w # +, - Move horizontal split up or down # rows
CTRL-w = Rearrange panes with equal spacing

Options

:set number/nonumber Display or hide line numbers
:colorscheme blue Change color scheme, use TAB to scroll through options

Clipboard

x, dd, d w Cut character, line, word
y, yy Copy visual selection, yy copies current line
y3w Copy next 3 words
p, P Paste at insert point in default mode, P pastes just before insert point
CTRL-R " Paste most recent yank when in insert or command mode; use * instead of " for clipboard contents

Spelling

:set spell [spelllang=en_us] Enable spell-checking, optionally specifying lang/culture
:set nospell Disable spell-checking
[s ]s Jump to next, previous spelling error
zg zw Add word to, remove word from dictionary
z= Select from suggested correct spellings
:spellr Repeat last spelling correction for all instances in file

Word Wrapping

:set tw=79 Turn on line wrapping (textwidth) to 79 characaters
:set tw=0 Disable line wrapping
{V}gq Select current paragraph and re-wrap lines

Sessions

Sessions save current state of running vim (buffers, tabs, splits, settings, etc.) to a file for later re-loading.

:mks <file> Saves current session to the file <file>
:source <file> Restore a saved session from the file <file>

TBD