Vim Cheatsheet

Thu, Jun 30, 2016 Last Modified: Jul 7, 2016
Category: cheatsheet Tags: [linux] [vim]

For Ubuntu Linux,

Terms:

C-x stands for ctrl-x.

Generally, use :help <cmd>" for quick ref, e.g.:help undo`.

Configuration

Configuration file default ~/.vimrc. Can use source <another file> and put the actual vimrc in cloud like dropbox.

# to reload an edited vimrc
:so $MYVIMRC

File operations

# to rename a file
:E or :Explorer
:Te or :Texplorer to open explorer in new tab then :bd to close the new tab
R # rename at bottom
:bp # go back previous buffer
# save the current session including buffers, tabs, and settings
:mksession ~/vimSessions/session1.vim
:mks! # to override existing session file

Copy/Pasting

In normal mode:

command effect
3y, p copy 3 lines, paste after cursor
“ayy, “ap copy current line to buffer a, paste from buffer a
v/V start selecting character, whole line
5ly yanks into default buffer 5 characters from cursor
“hy yanks into register h, use + register for system clipboard

In insert mode:

command effect
`C-r{register} paste contents of the register
C-r” to paste from default register
C-u to delete everything before the cursor on this line
C-w to delete from cursor to the beginning of previous word

Move Around

In normal mode:

command effect
100l go right 100 positions, useful to navigate a long line.
10w/10b/10e go forward/backward 10 words, e end of word
fa, ta move to or just before the next letter a
/pattern move to the next word matches, n/N to repeat search
H,M,L # to go to top/mid/bottom of screen
1G(1gg), G go to beginning/end of file
),} jump forward one sentence/paragraph
% jump to matching bracket

Editing

In normal mode:

command effect
dw/W delete word before/after cursor
x,r delete,replace character at cursor
.,u,ctrl-r repeat, undo, redo
q < letter >, @< letter > record operations and reapply, type q again to quit
* to search for word under cursor
# to count number of occurances
:%s/pattern//gn
# to count number of lines containing pattern
:%s/pattern//n
# change each 'foo' to 'bar', i: case insensitive, c: conformation, %: all lines
:%s/foo/bar/gci

Printing

For unicode error during printing to pdf.

http://stackoverflow.com/questions/11954241/unicode-printing-in-vim

Tried :set printencoding=utf-8, does not work on mac. :TOhtml :w print.html

Open print.html with chrome and print without background graphics.

comments powered by Disqus