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

motion description
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 the counth character occurrence to the right F<char>
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

buffer management

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

##split windows

command description
<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

##spelling

command description
]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

command description
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
"+p paste from system clipboard
:0,$d delete every line in a file
<C-a> increment number
<C-x> decrement number

##quickfix window

command description
: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&lt;num> Go to the error by number

##Addon References

###ctags http://ctags.sourceforge.net/

command effect
:!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

###tcomment https://github.com/tomtom/tcomment_vim

command description
gc{motion} Toggle comments (for small comments within one line the &filetype_inline style will be used, if defined)
gcc Toggle comment for the current line
gC{motion} Comment region
gCc Comment the current line
<C- _ ><C- _ > :TComment
<C- _ >b :TCommentBlock

###vim-rails https://github.com/tpope/vim-rails

command description
:A Alternate
:R Related
:Rmodel
:Rview
:Rcontroller
:help rails-navigation

###vim-surround https://github.com/tpope/vim-surround

command description
cs<current><new> change old delimeter to new
ds remove delimeters
ysiw<delimiter> wrap current word
S<delimiter> while in visual mode
S= in visual mode, rails ERB tag (requires vim-rails)
S- in visual mode, rails ERB tag (requires vim-rails)
S# in visual mode, rails ERB tag (requires vim-rails)
<C-s>= rails ERB tag (requires vim-rails)
<C-s>- rails ERB tag (requires vim-rails)
<C-s># rails ERB tag (requires vim-rails)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment