Skip to content

Instantly share code, notes, and snippets.

@khilnani
Last active December 6, 2016 04:37
Show Gist options
  • Save khilnani/6756314 to your computer and use it in GitHub Desktop.
Save khilnani/6756314 to your computer and use it in GitHub Desktop.
" Windows
"------------------------
" :split
" :vsplit
" <C-W>n new
" <C-W>s split
" <C-W>v vsplit
" <C-W>c close
" <C-W>o others
map <C-w>] <C-w>w
map <C-w>[ <C-w>p

" Tabs
" -------------------------
" :tabnew
" :tabedit NAME
" :tabn
" :tabp
" :tabc
" :tabo (others)
map <C-t>] :tabn<CR>
map <C-t>[ :tabp<CR>
map <C-t>n :tabnew<CR>
map <C-t>c :tabc<CR>
map <C-t>o :tabo<CR>

" Shell
"----------------------------
" :! COMMAND
" :! bash - exit to leave
" C-z  - shell
" fg  - return

" Shell
" "--------------------------
" :sh - enter
" C-d - return

map <C-j> :%!python -m json.tool<CR>

Conque Commands

  • :term if using Nik's .vimrc will split and run bash. Use :res[ize] 20 to make the window smaller.
  • :ConqueTerm bash
  • :ConqueTermSplit
  • :ConqueTermTab
  • :ConqueTermVSplit

Auto Completion

  • <C-n> <C-p> - scroll through matches based on 'wildmode'

Execution

  • :python print 'test'
  • :ruby puts 'test'

File Navigation

  • <C-g> - Current file status
  • :e - edit file in curent window
  • :cd [NAME] - Change working directory
  • :f [NAME] - Rename file
  • :w [NAME] - write to file
  • :r [NAME] - Read file and insert after current file
  • :Explore - file browser
  • :E - edit/explore current dir
  • :q - quit

Help

  • |topics| - please cursor and <C-]> to naviagte. to return
  • :help
  • :help quickref
  • :[letter][TAB] - cycle through commands

Exec Shell Console Commands

  • :! COMMAND

Pause VIM

  • <C-z> - pause and go to shell
  • fg - return

Open Files

  • :e NAME - Open file

Windows

  • <C-w>n - :new horizontal split (editing a new empty buffer)
  • <C-w>s - :split window horizontally (editing current buffer)
  • <C-w>v - :vsplit window vertically (editing current buffer)
  • <C-w>c - :close window
  • <C-w>o - close all windows, leaving :only the current window open
  • <C-w>w - go to next window
  • <C-w>p - go to previous window
  • <C-w><Up> - go to window above
  • <C-w><Down> - go to window below
  • <C-w><Left> - go to window on left
  • <C-w><Right> - go to window on right
  • <C-w -N> - decrease by line
  • <C-w +N> - increase by line
  • :res +N - resize
  • :res -N - resize
  • <C-w_> - maximize window
  • <C-w=> - make all equal

Tabs

  • :tabnew
  • :tabc[close]
  • :tabc[close] index
  • :tabo[nly]
  • :tabn[ext] index
  • :tabf[irst]
  • :tabl[ast]
  • [N] gt - go to tab N

Buffers

  • :e - edit file
  • :hide - close current window
  • :only - only keep this window open
  • :ls - list all buffers
  • :b[N] - open buffer N
  • :bn - next buffer
  • :bp - prev buffer
  • :b [N] - cycle through files in buffer by name

Navigation

  • 0 - front of line
  • $ - end of line
  • [N]G - go to line
  • :[N] - go line
  • w - jump word
  • ( - move block up
  • ) - move block down
  • [[ - move section up
  • ]] - move section down
  • <C-b> back one screen
  • <C-f> forward one screen
  • <C-u> - up half screen
  • <C-d> - down one screen

Mark Lines/Code folding

Also see [http://vim.wikia.com/wiki/Using_marks]

  • za - toggle folding at current indent section
  • zA - toggle folding include any parent indents
  • :delmarks a - Delete mark a
  • :marks - List all marks
  • m[k] - mark line
  • '[k] - move to mark k
  • 'a-z - same file
  • 'A-Z - beteween files

Text Manip

  • i - insert
  • ci" or ci' - clear text within " and insert
  • I - insert at beginning
  • a - append
  • A - append to end
  • o - open blank line below
  • O - open blank line after
  • ea - append end of word

Formatting

  • [N]<< - shift line
  • [N]>> - shift line
  • v - select multi
  • V - select lines
  • > - shift
  • < - shift
  • d - delete marked
  • ~ - switch case
  • yy - copy line
  • yw - copy word
  • J - join next line with current

Copy/Paste

  • ci" or ci' - clear text within " and insert
  • x - delete char forward
  • X - deletes char backwards
  • dd - cut line
  • dw - cut cursor till end of word
  • d^ - cut cursor till start of line
  • D - cut from cursor till end of line
  • yy - copy a line
  • [N]yy - copy N lines
  • p - paste after cursor
  • P - paste before cursor
  • [N]dd - cut next N lines
  • . - repeast last command
  • u - undo

Save

  • :w - write
  • :q - quit
  • :wq - write and quit
  • :q! - throw away changes

Search

  • /pattern - search for pattern
  • ?pattern - search backward for pattern
  • n - repeat search in same direction
  • N - repeat search in opposite direction
  • :%s/old/new/g - replace all old with new throughout file
  • :%s/old/new/gc - replace all old with new throughout file with confirmations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment