- Indicate what you want to do ie actions you want to take
- d : Delete
- c : Change
- v : visual mode, V for visual line mode
- y : Yank (copy)
- Modifers indicate how you want to take action.
- i : inside
- a : around
- t : till, finds a character and stops just before it
- f : find, finds a character and stop right on top of it
- / : find a string or use a regex (foward-slash)
- Represents object acted upon.
- w : word
- s : sentence or )
- p : paragraph
- b : block/parentheses
- t : xhtml tags
In vim (language), we can combine verbs+modifiers+objects to perform
efficient actions in vim:
- diw : delete inside word (inside means the word you are in)
- yis : yank(copy) contents inside sentence
- cit : change the contents inside tags
- ci" : change inside quotes
- dat : delete around tags
- yt' : yank(copy) till(before) the ' character
- c/< : Change till the occurance of {
- vap : Visually select tags you are in
- vi{ : Select function blocks in c-style language
:help <command> show help info for a command
:tabedit ~/.vimrcand do:so %where%stands for current file (better yet, make a mapping for it):tabedit $MYVIMRC[src]
:tabedit file.html
- Position the cursor where you want to begin cutting.
- Press
v(or upper caseVif you want to cut whole lines). - Move the cursor to the end of what you want to cut.
- Press
d. - Move to where you would like to paste.
- Press
pto paste after the cursor, orPto paste before.
- Go to start location and set mark using
mawhereais the marker. - Then go to end location and type
y'ato yank from line containingato the end location line(the line from where you rank the yank command). - OR to yank to the precise point where mark was set, use
`instead of'
{d} : { moves to the start of paragraph,d starts deletion and } ends
deletion at end of paragraph.
- Enter visual mode
- Select the text
- Use
Ufor uppercase orufor lower
bto go to beginning of current or previous wordwto go the beginning of next wordeto go to the end of current or next word:22- go to line 22
gt= next tabgT= previous tab
gg"*yG- Copy whole file to clipboard"*y$- Copy to the end of the line in clipboard
Ctrl-6to switch between files- Press
gfwhile cursor on a file path to go to a file :bfto go back to previous fileCtrl-ogo to previous curson position
t- opens selected files in tab:tabm n- moves tab to n-th position(base 0), short for :tabmove:h word-motionsfor more
2J to join 2 lines.
ctrl+ws- Split windowsctrl+ww- switch between windowsctrl+wq- Quit a windowctrl+wv- Split windows vertically
Combination Ctrl+w+ J,K,L,M moves the window around. [src]
In insert more,Ctrl-o immediately followed by A
[src]
- to replace first occurrence of OLD to NEW on current line
:s/OLD/NEW - to replace all occurrence of OLD to NEW on current line
:s/OLD/NEW/g - to replace all occurrence of OLD to NEW between two line numbers (# are the line numbers)
:#,#s/OLD/NEW/g - to replace every occurrence of OLD to NEW on current file
:%s/OLD/NEW/g
:nohl Turns off highlight of a previous search if using set hlsearch in .vimrc
:%s/<c-r><c-w>/new value/g where <c-r><c-w> means to literally type <ctrl-r><ctrl-w> to insert the word under the cursor.
- When
\cappears anywhere in a search pattern, the whole pattern is treated as case insentitive, as if usingset ignorecase - When
\Cappears anywhere in a search pattern, the whole pattern is treated as case sensitive. It forces matching case for the whole pattern - See:
help /\c
- Disable using
:set nofoldenable za- toggleszc- closeszo- openszR- open allzM- close all [src]
Place cursor in the line and pres cit(change inside tag)
vit (select visually inside tag) or vitp (select visually inside tag and paste)
dit (delete inside tag)
dst (delete surrounding tag)
Deletes a tag, leaving behind only surrounding elements
dfx (delete upto and including x, f stands for find) where x is a character
dtx (delete till x) where x is a character
<C-w> will delete a word just mistyped.[src]
- Press
qto start recording. - Then press any letter to use as a register for the recording
(say a). - Type commands you wish to record.
- Press
qagain to stop recording. - Play the recording using
@a.
:5,10norm! @a which runs the macro stored in register @a from line 5 to 10 in normal mode. [[src]] (http://stackoverflow.com/a/390194)
@@
10@e Runs the macro stored in register @e 10 times
Ctrl o jumps backward to previous cursor location
Ctrl i jumps forward to newer cursor location
vitp Select content inside tag in visual mode and paste over (replace) earlier content to it.
See :help text-objects
- M : move to the middle of the screen
- L : move to the end of the screen
%: moves to matches parentheses([{}])
>%or<%
:read !ls tests writes output from ls tests to current buffer [[src]] (http://vim.wikia.com/wiki/Append_output_of_an_external_command)
autocmd BufEnter * lcd %:p:h here % gives the name of the current file, %:p gives its full path, and %:p:h gives its directory (the "head" of the full path).
source
tabm 0 moves current tab to the first position, tabm 1 moves current tab to second position.
In general tabm N moves tab to N position in a zero based index.
tabm +N moves current tab N places to the right
tabm -N moves current tab N places to the left
http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118 http://danielmiessler.com/study/vim/
===
<Ctrl-e>
td*n repeats the tag n time
So pressing td*3 and expansion key will produce:
<td></td>
<td></td>
<td></td>===
- Select the letter, word or line in visual mode.
- Press
S - Press character to surround with