Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
Forked from socketwiz/vim.markdown
Created November 27, 2015 18:29
Show Gist options
  • Select an option

  • Save mostlygeek/930c03c38e6b22f42f96 to your computer and use it in GitHub Desktop.

Select an option

Save mostlygeek/930c03c38e6b22f42f96 to your computer and use it in GitHub Desktop.
Vim cheat sheet

##motions h count characters left
l count characters right
^ to the first character of the line
$ to the last character of the line
f<char> to t he counth character occurrence to the right
F<char> to t he counth character occurrence to the left
t<char> to 1 character just before the counth character occurrence to the right
T<char> to 1 character just before the counth character occurrence to the left
w count words to the right
W count words to the left
e forward to the end of a word count
b backward to the end of a word count
i<{<"'> inside something like inside brackets or parenthesis for example

##trigger effect c<motion> change
d<motion> delete
y<motion> yank into register
g~<motion> swap case
gu<motion> make lowercase
gU<motion> make uppercase
><motion> shift right
<<motion> shift left
=<motion> auto-indent

##command effect v enable characterwise Visual mode
V enable linewise Visual mode
<C-v> enable blockwise Visual mode
gv reselect the last visual selection
o go to other end of highlighted text

buffer management

<C-^> or <C-6> switch to the buffer you just left

##split windows <C-w>s split file horizontally
:sp[lit] <file>

<C-w>v split file vertically
:vsp[lit] <file>

<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

:cl[ose] <C-w>c close the active window
:on[ly] <C-w>o keep only the active window, closing all others

##ctags :!ctags -R jump to first tag that matches word under the cursor
<C-]> Prompt user to select from multiple matches for the word under the cursor.
g<C-]> present a list of choices if there is more than a single tag to jump to
<C-t> like the back button for tag history
:tag <keyword> jump to first tag that matches word under the cursor
:tjump <keyword> Prompt user to select from multiple matches for the word under the cursor.
:pop or <C-t> Prompt user to select from multiple matches for the word under the cursor.
:tselect Prompt user to choose an item from the tag matchlist

##spelling ]s Jump to next spelling error
[s Jump to previous spelling error
z= Suggest corrections for current word
zg Add the current word to spell file
zw Remove the current word from spell file

##miscellaneous "+p paste from system clipboard
:0,$d delete every line in a file

##quickfix window :copen Open the quickfix window
:ccl Close it
:cw Open it if there are "errors", close it otherwise (some people prefer this)
:cn Go to the next error in the window
:cnf Go to the first error in the next file
:cc<num> Go to the error by number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment