Vim Notes
Current Line (Left-Right) Motions
Section titled “Current Line (Left-Right) Motions”f{char}- move the cursor to the{char}to the rightF{char}- move the cursor to the{char}to the leftt{char}- move the cursor to before the{char}to the rightT{char}- move the cursor to after the{char}to the left;- repeat the latestf,F,t, orTmove,- repeat the latestf,F,t, orTmove in the opposite direction
Copy/Paste within Vim
Section titled “Copy/Paste within Vim”Pasting the word once
yiw- Yank the current wordviwp- Replace the current word (move cursor before pasting)
Pasting the same word multiple times (does not work in VsVim)
yiw- Yank the current wordcw<C-r>0<ESC>- Paste the word in Insert Mode using<C-r>0
Copy/Paste to the Clipboard
Section titled “Copy/Paste to the Clipboard”"+yiw- Yank the current word to the Clipboard -"register+clipboardyankinnerword:%y+- Copy the entire buffer to the Clipboard"+p- Paste from the Clipboard -"register+clipboardput:pu+- Paste from the Clipboard -:command-linepuput+clipboard:0pu+- Paste at the top of the buffer from the Clipboard:$pu+- Paste at the end of the buffer from the Clipboard
Normal Mode
Section titled “Normal Mode”<C-g>- Prints current filename (Go To Linein VsVim)1<C-g>- Prints current filename with full path (Go To Linein VsVim)2<C-g>- Prints current filename with full path and buffer number (Go To Linein VsVim)g<C-g>- Prints column, line, word, and byte counts (Go To Linein VsVim)gx- Opens the URL under the cursor using the web browser
Normal Mode to Visual Mode
Section titled “Normal Mode to Visual Mode”v- Enable character-wise Visual ModeV- Enable line-wise Visual Mode<C-v>- Supposed to enable block-wise Visual Mode (Pastein VsVim)gv- Reselect the last visual selection
Normal Mode to Command-Line Window
Section titled “Normal Mode to Command-Line Window”q/- Open the Command-Line Window with history of searchesq:- Open the Command-Line Window with history of Ex commands
Visual Mode
Section titled “Visual Mode”<C-g>- Toggle between Visual Mode and Select Mode (Go To Linein VsVim)o- Go to other end of highlighted text
Insert Mode
Section titled “Insert Mode”<C-h>- Delete back one character (backspace) (does not work in VsVim)<C-w>- Delete back one word (does not work in VsVim)<C-u>- Delete back to start of line (does not work in VsVim)<Esc>- Switch to Normal mode<C-[>- Switch to Normal mode (does not work in VsVim)<C-o>- Switch to Insert Normal mode for a single command (does not work in VsVim)<C-r>{register}- Paste text from register (does not work in VsVim)<C-r><C-p>{register}- Paste text from register & fix any unintended indentation (!VsVim)<C-r>={expression}<CR>- Paste result of expression (does not work in VsVim)
Digraphs
Section titled “Digraphs”<C-k>{char}{char}- Insert character using a digraph (:digraphsto list digraphs) (!VsVim)12for ½.P,.M,Ob,0m,sB,Db,Dw,*2,*1for ⋅ · ∘ ○ ▪ ◆ ◇ ★ ☆OK,XXfor ✓ ✗!=,/\,-:for ≠ × ÷A*,a*,B*,b*for Α α Β β (generate Greek letters with letter followed by*)2s,2Sfor ₂ ²>>for »<-,->,-!,-v,UD,<>for ← → ↑ ↓ ↕ ↔<=,=>,==for ⇐ ⇒ ⇔UT,Dt,PR,PLfor ▲ ▼ ▶ ◀uT,dT,Tr,Tlfor △ ▽ ▷ ◁
- Vim Digraphs Cheatsheet
Unicode Characters
Section titled “Unicode Characters”<C-q>u{4-digits}- Insert character using its 4-digit hexadecimal Unicode value2611,2705for ☑, ✅
Formatting
Section titled “Formatting”:set expandtab- Insert space characters whenever the tab key is pressed
(use<C-v><Tab>to insert a tab character):set tabstop=4- Number of spaces to be inserted when the tab key is pressed:set shiftwidth=4- Number of space characters inserted for indentation:retab- Change all the existing tab characters to match the current tab settings
Display
Section titled “Display”:set listchars=eol:$,space:-,tab:>#,trail:~- Use inlistmode &:listcommand:set listchars=multispace:---+- Characters to show for multiple consecutive spaces:set [no|inv]list- Turn onlist modeto display listchar strings (show spaces, tabs, etc):set [no|inv]wrap- Turn on wrap to display a long line on multiple lines:set textwidth=0- Turn off automatic line wrapping:set [no|inv]number- Show the line number for each line:set [no|inv]relativenumber- Show the line number for each line relative to the cursor
Spell Check
Section titled “Spell Check”set [no|inv]spell- Turn on spell checkingsetlocal spell spelllang=en_us- Turn on spell checking for U.S. English]s- Go to the next misspelled word[s- Go to the previous mispelled word]S- Go to the next bad word (not rare words or words for another region)[S- Go to the previous bad word (not rare words or words for another region)z=- Suggest replacements for the current wordzg- Good Word - Add the current word to the dictionaryzug/zuw- Undo Good / Undo Word - Remove the word from the dictionaryzw- Woops! - Mark the word as a wrong (bad) word:set ft=text- Force text-like spell checking by setting the filetype to text:mkspell! $MYVIMDIR/spell/en.utf-8.add- Generate a Vim spell file (*.spl) from the word list
Complex Repeat (Macro)
Section titled “Complex Repeat (Macro)”q{register}{characters}q- Records typed characters into the register
(use uppercase register to append)@{register}- Execute the contents of the register@@- Repeat the previous@{register}:source {file}- Read Ex commands from{file}:[range]source- Read Ex commands from lines in current buffer (all lines if no[range]):source! {file}- Read Vim commands from{file}
(these are executed from Normal mode, like you type them):args- Print the argument list with the current file in square brackets:argdo source {file}- Execute the Ex commands from{file}for each argument list file
Command-Line Mode
Section titled “Command-Line Mode”:[range]delete {register}- Delete specified lines into{register}:[range]yank {register}- Yank specified lines into{register}:[line]put {register}- Put the text from{register}after the specified line:[range]copy {address}- Copy the specified lines to below the line specified by {address}:[range]t {address}-tis an alias forcopy(think of it as copy to):[range]move {address}- Move the specified lines to below the line specified by {address}:[range]join- Join the specified lines:[range]normal {commands}- Execute Normal mode{commands}on each specified line:[range]substitute/{pattern}/{string}/[flags]- Replace occurrences of{pattern}with{string}on each line:[range]global/{pattern}/[cmd]- Execute the Ex command[cmd]on all specified lines where the{pattern}matches<C-f>- Switch to the Command-Line Window (move to line and hit<CR>to execute command,:qto quit)
Command-Line Completion
Section titled “Command-Line Completion”:{pattern}<C-d>- List names that match the pattern in front of the cursor:set wildmode=longest,list- Complete to longest common substring, list all multiple matches:set wildmode=full- Complete the next full match, cycles through all matches:set wildmenu- Provide navigable list of suggestions
1- The first line$- The last line0- Virtual line above the first line.- Line where the cursor is placed'm- Line containing markm'<- Start of visual selection'>- End of visual selection%- The entire file (same as1,$)
Substitute
Section titled “Substitute”:s/old/new/- Replace the first occurrence on the current line:s/old/new/{flags}- Substitute Flags::s/old/new/i- Ignore case for the pattern search:s/old/new/c- Confirm each substitution
(yes, no, all, quit, last,<C-e>to scroll up,<C-y>to scroll down):s/old/new/g- Global (replace all occurrences) on the current line:%s/old/new/gn- Number of matches (reports without actual substitution):s/old/new/&- Use same flags from previous substitute command - must be first flag
:%s/old/new/g- All lines (%is equivalent to1,$):5,10s/old/new/g- Lines 5 through 10:&- Repeat the last:swithout the flags:&&- Repeat the last:swith the flags
:shell- Start a shell (return to Vim withexit):!{cmd}- Execute{cmd}with the shell:read !{cmd}- Execute{cmd}in the shell and insert its standard output below the cursor:[range]write !{cmd}- Execute{cmd}in the shell with[range]lines as standard input:[range]!{filter}- Filter the specified[range]through the external program{filter}
Arguments
Section titled “Arguments”:args- Display the current files in the argument list, with the current file in square brackets.:next- Edit the next file in the argument list:previous- Edit the previous file in the argument list:first- Edit the first file in the argument list (same as:rewind):last- Edit the last file in the argument list:argdo {cmd}- Execute the{cmd}Ex command for each file in the argument list
Buffers
Section titled “Buffers”:ls- List all of the buffers that have been loaded into memory%- Buffer in the current window#- Alternate buffer for:e #and<CTRL-^>a- Active buffer (loaded and visible)h- Hidden buffer (loaded but currently not displayed in a window)=- Readonly buffer+- Modified buffer
:bprevious- Go to the previous buffer in the buffer list:bnext- Go to the next buffer in the buffer list:bfirst- Go to the first buffer in the buffer list (same as:brewind):blast- Go to the last buffer in the buffer list:bdelete- Unload current buffer and delete from buffer list (does not affect associated file):bufdo {cmd}- Execute the{cmd}Ex command for each buffer in the buffer list:write- Write the whole buffer to the current file:edit!- Discard changes to current buffer & read file from disk into buffer (revert changes):qall!- Exit Vim, discarding changes to all buffers without warning or confirmation:wall- Write all modified buffers to disk (same as:argdo write):set hidden- A buffer becomes hidden when abandoned (:argdo,:bufdo,:cfdo):set nohidden- A buffer is unloaded when it is abandoned
Windows
Section titled “Windows”<C-w>s- Split the current window horizontally<C-w>v- Split the current window vertically:split {file}- Split the current window horizontally, loading{file}into the new window:vsplit {file}- Split the current window vertically, loading{file}into the new window<C-w>w- Cycle between open windows<C-w>h- Focus the window to the left<C-w>j- Focus the window below<C-w>k- Focus the window above<C-w>l- Focus the window to the right<C-w>c/:close- Close the active window<C-w>o/:only- Keep only the active window, closing all others<C-w>=- Equalize width and height of all windows<C-w>_- Maximize height of the active window<C-w>|- Maximize width of the active window[N]<C-w>_- Set active window height to[N]rows[N]<C-w>|- Set active window width to[N]columns
Vim Plugins
Section titled “Vim Plugins”Cycle through available colorschemes
- By Marvin Renich
- Vim.org
- Windows Fix by Daniel Moore
<F3>- Cycle Backward<F4>- Cycle Forward
A parser to let you write HTML code faster
- By Rico Sta. Cruz
Easily delete/change/add surroundings
- By Tim Pope
- Documentation
ds{char}- Delete Surroundings -{char}can be"')b}B]r>aortfor tagcs{char}{replacement}- Change Surrounding{char}with{replacement}
(could be tag)ys{motion}{char}- You Surround{motion}with{char}(could be tag)yss{char}- You Surround - operates on current line (ignores leading whitespace)yS{motion}{char}- You Surround - indents the text and places it on a line of its ownySS{char}- You Surround - indents the current line and places it on a line of its ownv{motions}S{char}- wraps the visual selection with{char}v{motions}gS{char}- wraps the visual selection on a line of its own with{char}
Pairs of handy bracket mappings
- By Tim Pope
- Documentation
[a/]a(:previous/:next) - edit previous / next file in the argument list[A/]A(:first/:last) - edit the first / last file in the argument list[b/]b(:bprevious/:bnext) - go to the previous / next buffer in the buffer list[B/]B(:bfirst/:blast) - go to the first / last buffer in the buffer list[<Space>/]<Space>- add blank lines above / below the cursor[e/]e- exchange the current line with the line above / below it[oh/]oh/yoh- on/off/togglehlsearch[oi/]oi/yoi- on/off/toggleignorecase[ol/]ol/yol- on/off/togglelist[on/]on/yon- on/off/togglenumber[or/]or/yor- on/off/togglerelativenumber[os/]os/yos- on/off/togglespell[ow/]ow/yow- on/off/togglewrap