Skip to content

Instantly share code, notes, and snippets.

@behrends
Created August 24, 2011 10:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save behrends/1167716 to your computer and use it in GitHub Desktop.
Save behrends/1167716 to your computer and use it in GitHub Desktop.

Using http://github.com/carlhuda/janus so not all of these might be in standard vim

:e - edit file
0 - jump to beginning of line
$ - jump to end of line
^ - jump to first non-whitespace character of a line
e - jump to end of a word
E - jump to whitespace-delimited word
b (B) - jump to previous (whitespace-delimited) word
w (W) - jump to next (whitespace-delimited) word
alt+w/b - same as b/w but treats dots, underscores and camel case as word delimiters
H - jump to first line of the screen
M - jump to middle line of the screen
L - jump to last line of the screen
:n - jump to line number n. For example, to jump to line 42, you'd type :42
A - jump to end of line and enter insert mode
108G - jump to line 108
3fd - got to third occurrence of character 'd' from cursor position
:%s/foo/bar/g - globally replace foo with bar
% - go to matching (,{,[
* (#) - go to next (previous) occurrence of word under cursor
gU (gu) - upper (lower) case
:noh - disable search highlighting

Search
; - last f, t, F or T
, - last f, t, F or T in opposite direction
n - last / or ? search
N - last / or ? search in opposite direction

Combinations of commands
ci" - remove stuff in next quotes (""), jump into quotes and enter insert mode
de - delete until end of current word
dw - delete until beginning of next word dtZ - delete until and excluding next occurrence of character Z
A<type something>ESC<movearound>. - appends something to current line
gg=G - format whole buffer (gg goes to first line, = formats, G until end of file)

Selections
vap - visually select paragraph
vit - visually select text inside tag
vat - visually select text including tags

Plugins
\n - toggle NERDTree project drawer (NERDTree plugin)
command+t (and \t with Janus, needs vim compiled with ruby) - Textmate users know this one, open type (command-t plugin)
vii - mark current indent block, ii will mark surrounding parent block (indent_object plugin)
cst<p> - replaces surrounding tag with <p> (surround plugin)
yss<span> - surround current line with <span> (surround plugin)
cs"' - change surrounding " with '
TAB - context sensitive completion (SuperTab plugin)

Buffers and Windows
ctrl+^ or ctrl+6 or :b# - switch between two buffers
:%bd - delete all buffers
:22,24%bd - delete a range of buffers with number 22 up to number 24
:sp/ctrl+w s (:vsp or ctrl+w v) - split buffer (vertically)
ctrl+w c - close current window (also split buffers)
ctrl+w o - make the current window the only one
ctrl+w x - switch two windows
ctrl+w p - move to last window
ctrl+w h/j/k/l - move current window to the left/bottom/top/right
:h windows - help for working with windows

Important commands I already learned by heart ;-)
u - undo
x - delete character
dd - delete line
. - repeat last command (can be anything, even a sequence of edits!)
v - enter visual mode to select stuff
y - yank into register
p - paste after current line P - paste before current line
o - add new line after current line and enter insert mode
O - add new line before current line and enter insert mode

Links
http://www.tuxfiles.org/linuxhelp/vimcheat.html
http://www.viemu.com/a-why-vi-vim.html
http://www.eng.hawaii.edu/Tutor/vi.html
http://thomer.com/vi/vi.html
http://rayninfo.co.uk/vimtips.html (15 Years of Vi + 7 years of Vim and still learning)
http://tottinge.blogsome.com/use-vim-like-a-pro
http://stevelosh.com/blog/2010/09/coming-home-to-vim/
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
http://mislav.uniqpath.com/2011/12/vim-revisited/

Examples for the surround plugin
http://www.catonmat.net/blog/vim-plugins-surround-vim/

Your problem with Vim is that you don't grok vi (great explanation of vim concepts on stack overflow)
http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

All vimcast episodes: http://vimcasts.org/episodes/archive
http://www.derekwyatt.org/vim/vim-tutorial-videos/

Vim expert talk at boston.rb
http://bostonrb.org/presentations/write-code-faster-expert-level-vim

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