Cheatsheet: vi/vim

I just started to learn how to boost my productivity skill making some tasks faster and faster not by quality reduction, but by routine reduction.

It’s thought that I don’t know any text editor as a usual developer should know. I’ve got a choice between emacs, Sublime Text and vim. I can’t describe why, but I tried vim. May be because of enhanced command choice and full keyboard use.

So, I started to learn Vim and fill the personal cheatsheet at the same time. Here we go! I just splitted the table on 2 logical parts: commands which can be used either on vi either on Vim and commands used only in Vim.

Command

Description

Regexp

:%s/foo/bar/g Replace all “foo” occurrences to “bar”
:g/^$/d Remove all empty lines
:s/\s\+$// Regexp to remove trailing whitespaces
:s/./\u&/g Make the Caps Lock style of your line
:%s/pattern-here//gn Count occurrences of pattern-here pattern
:%s//joe/igc Substitute what you last searched for
:%s/~/sue/igc Substitute your last replacement string
/fred\|joe Search for FRED OR JOE
:g/gladiolli/# Find all pattern occurrences with line numbers
/\(fred\).*\(joe\).*\2.*\1 using rexexp memory in a search
/\%>20l\%<30lgoat Search for goat between lines 20 and 30
:%s/^\(.*\)\n\1$/\1/ delete duplicate lines

vi

ZZ Exit from vi
J Lines concatenation
15G Go to the 15th line
o/O Create new empty line below/above cursor
/hello Search pattern “hello”
d5d Delete 5 lines saving to the clipboard
“+y3y Copy 3 lines to clipboard
“+gp Paste the text from clipboard
:50,65mo77 Move the text block from 50 to 65 line below 77 line
Ctrl-F/Ctrl-B Full screen scroll (up/down)
Ctrl-D/Ctrl-U Half screen scroll (up/down)
z + ENTER Move the current line up to the top of screen
z + . Move the current line to the middle of screen
z + / Move the current line down to the bottom of screen
Go back to the previous cursor layout
:map K qWWp Set the command K to flip 2 words
:set shiftwidth=4 Set autoindent width
:noh Remove highlighting from the window
:e#n Open n-th file of all you have in session
/joe/e cursor set to End of match
:qa Close all windows

vim

e! Rollback to the original file version
Ctrl-W + arrow Change the window
Ctrl-W + h/j/k/l Change the window
Ctrl-W + p Switch to the previous window
Ctrl-W + r Rotate windows
Ctrl-W + +/-/ Resize selected window
Ctrl-W + = Equal windows size
Ctrl-W + >/< Change the window width
Ctrl + HOME/Ctrl + END Go to the top/bottom of file
vim -O file1 file2 Load vim with vertical window split
vim -o file1 file2 Load vim with horizontal window split
v Call visual mode
* Highlight all occurrences if word under the cursor
:split/:vsplit Split the window during the session
:tabnew/:tabclose Open/close the tab
:tabonly Close all tabs except the current one
gt/gT Switch between tabs
:10,20 normal command Call vim command for multiple lines
:cd %:p:h Change directory to current working file

vim-bootstrap

,. Set path working directory
SHIFT+t Create a tab
TAB/SHIFT+TAB Next/previous tab navigate
F3 Open/Close tree navigate files
gc Comment or uncomment lines that {motion} moves over
YY Copy to clipboard
,n Show where command is usage
,ga Git add
,gc Git commit
,gsh Git push

PyMode

let g:pymode_python = ‘python’ Switch to the Python 3
[[  /  ]] Jump to previous/next class or function
:PyModeDoc Show documentation
:PyModeRun Run current buffer
:PymodeLint

Check code in current buffer

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s