Skip to content

Instantly share code, notes, and snippets.

@jlacar
Last active March 21, 2016 21:04
Show Gist options
  • Save jlacar/d7fe8a403fbb122128d2 to your computer and use it in GitHub Desktop.
Save jlacar/d7fe8a403fbb122128d2 to your computer and use it in GitHub Desktop.

Vim Cheat Sheet

Note: Work-In-Progress - I will be updating this as I learn my way around vi. I'll add new entries as and when I find that I'm using them frequently

Working with files

:e .           - edit file, show list to choose from

:e filename    - edit a specific file

:q!            - quit without saving

:x             - save and exit

:w             - save and continue editing

Buffers

:buffers - list buffers

:b N - switch to buffer N

C-^ or C-6 - switch to last buffer

:bn[ext][!] - switch to next buffer

:bp[revious][!] - switch to previous buffer

Useful mapping for :bn and :bp:

:nnoremap <C-n> :bnext<CR>
:nnoremap <C-p> :bprevious<CR>

:[N]bd[elete][!] - delete buffer [(current) | N]

:[N]bun[load][!] - unload buffer [(current) | N]

:[N]bw[ipeout][!] - wipeout buffer [(current) | N]

Cursor movement

(2 backticks) - jump to last edit position

'' - (2 single quotes) jump to last edit position ^

w - jump to start of next word

b - jump to start of previous word

0 - jump to start of line

^ - jump to first non-blank char of line

$ - jump to end of current line

gg - jump to start of first line

G - jump to start of last line

) - jump forward one sentence

( - jump backward one sentence

} - jump forward one paragraph

{ - jump backward one paragraph

Editing

das - delete around a sentence

See Hook's Humble Homepage

Find/Replace

:noh - turn off highlights until next search

Text wrapping

:set tw=N - hard text wrap at column N

:set tw=0 - turn text wrap off

gqq - wraps the current line (inserts hard break)

gqip - wraps the current paragraph (inserts hard breaks)

Visual wrapping only

(From vim.wikia) Wrap text visually but only insert linebreak when ENTER is pressed

:set wrap
:set linebreak
:set nolist  " list disables linebreak

Help

C-] - jump to |topic| at cursor

:q - exit from help

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