Skip to content

Instantly share code, notes, and snippets.

@jasim
Created March 29, 2012 10:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jasim/2235800 to your computer and use it in GitHub Desktop.
Save jasim/2235800 to your computer and use it in GitHub Desktop.
Shortcuts for VimGet

#Basic Stuff#

##Movements##

  • Goto next word w
  • Goto previous word b
  • Select inner word viw
  • Select the inner block - vi{
  • Go to closing or opening tag - %
Use 'iw' as a motion command with any action. example: 'diw' deletes the inner word.

Quick Moves

####Markers####

  • set mark m

  • go to mark `

  • Go to the next occurence of a letter in current line: f eg: 2fx will take me to the second 'x'

  • Go one letter before the occurence of a character - t - will reach the letter just before char.

  • Use F, T for search letter, but in reverse directions.

  • Repeat the same line search - ;

  • Search for the next occurence of the current word in current file - asterisk (ie: *)

####Search & Replace####

search for text in entire file: / next instance of search result : n previous instance of search result : N

Text Editing

delete till end of line - D change till end of line - C paste from system clipboard - ,p paste from Vim clipboard while in Insert mode - ctrl+r create a blank line below - (this actually is o)

Misc

(seriously awesome) go to escape mode - press jj in insert mode.
(very useful) repeat your last edit action - .

File Management

Open file through directory tree (CtrlP) - ,p open the project drawer at current location (nerdtree) - ,/ toggle the project drawer - ,n (latest) fuzzy search - see list of files and jump to it - ,p (vim plugin: ctrl p) refresh ctrl p fuzzy search cache - :clear

Text Alignment

align current line - == align current block - {=}
'{' will take you to the beginning of the block. '=' will align, '}' is the movement character asking the align command to align till the end of the block.

Ruby Specific

Autocomplete - ctrl+n (default). with SuperTab, press Tab.
go to definition - g] go to file - gf toggle comment - ,c (from NerdCommenter plugin)

Rails Specific

toggle between spec and code - :A toggle between controller, view and model - :Rcontroller, :Rmodel, :Rview [rails-vim plugin] go to specific model/controller/view - :Rmodel employee etc. go to specific migration - :Rmigration rails generate - :Rgenerate <migration/model/etc.> - will generate and take you to the generated file.

Specs

run specs for current context : ,s (leader s) run for whole file: ,S (leader shift s) re-run whatever was last run: ,- (leader hyphen)

Multi File Editing

currently open buffers - ,b close an open buffer - :bd toggle between two files - ctrl + 6

window navigation

ctrl+w w - cycle between all windows ctrl+w (left/right.. arrow keys/hjkl) - switch to window in that direction

:%s/foo/bar/g Find each occurrence of 'foo', and replace it with 'bar'. :%s/foo/bar/gc Change each 'foo' to 'bar', but ask for confirmation first. :%s/<foo>/bar/gc Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation. :%s/foo/bar/gci Change each 'foo' (case insensitive) to 'bar'; ask for confirmation. :%s/foo/bar/gcI Change each 'foo' (case sensitive) to 'bar'; ask for confirmation.

Visual Mode

visual mode - v (not very useful - it selects just one character from the next line too.) visual line mode - V (selects only full lines) block visual mode - you want to select columns? dude, ctrl+v

Moving Around Edit Points

go to previous point of edit - ctrl + o go to next point of edit - ctrl + i

CScope

Jump to method definition: "<C-> s" alias refreshctags = ctags -f tags --recurse=yes . && find . -name '.rb' -o -name '.java' -o -name '.cs' -o -name '.js' -o -name '.haml' -o -name '.erb' >| cscope.files && cscope -b -q

(you'll need to install Exuberant Ctags. the one that comes as default on a mac wont work. do brew install ctags)

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