Thursday, January 31, 2013

ViMemory

There are lots of Vim commands that I use only occasionally and always have to look up. Here they are, all in one place, so that I can find them quickly. Help yourself.

# re-indent an entire file (= is the command)
gg=G 
# show tabs and carriage returns
:set list 
# Change to upper/lower case
gU[movement] or gu[movement]  
# show changes in the current file
:changes 
# jump back to the position of the previous (older) or next (newer) change
 g; or g, 
# Select contents of entire file
ggVG
# Search for word under cursor
*
# Macro recording & playback of single-key macros
qX   # Record macro 'X'
q    # Stop recording
@X   # Play macro 'X'
@@   # Repeat previous macro
# Count occurrences of a pattern (later versions of Vim)
:% s/[pattern]//n
# Did you know that you can use {Ctrl-C} to break out of insert mode? It works just like {Esc} but is easier to type.

#Handling changes to your .vimrc file (Thanks to http://dailyvim.blogspot.com/2008/11/reload-vimrc.html)

# Manually reload your .vimrc file if it has been changed
:source $MYVIMRC  
 # Show your .vimrc filename           
:echo $MYVIMRC               
# automatically update vim when .virmrc changes
:au! BufWritePost $MYVIMRC source $MYVIMRC 

# a collection of neat/quick commands - very useful
ci[c]      # Change the contents of everything 'inside' the [c] delimiters
di[c]      # Delete 'inside' delimiters
[ctrl]i    # Move 'in' to the next jumplist location (:h jumplist)
[ctrl]o    # Move 'out' to the previous jumplist location
[ctrl]=    # Resize all windows to be equal in size
[ctrl]_    # Make active window as large as possible

# There's a really nice, graphical cheat sheet for basic commands at http://www.viemu.com/vi-vim-cheat-sheet.gif

# And finally, there's an awesome, modern book on Vim from the folks at The Pragmatic Programmer: Practical Vim.