VIM Tips
Select
- toggle character selection: v
- toggle row selection: shift+v
- toggle block selection: ctrl+v
Copy
- Copy the whole line: yy
- Copy from the cursor to the EOL: y$
- Copy selected text: select the text then y
Paste
- Paste one line below the cursor: p
- Paste on the line of the cursor (push down the current line): shift+p
- Paste onto the selected text (overwriting them): select the text then p
Delete
- Delete the whole line: dd
- Delete from the cursor to the EOL: shift+d or d$
- Delete selected text: select the text then d
Search
- Find the text at the cursor: *
- Find a string /someText<ENTER>
- Find a string (case insensitive) /someText\c<ENTER>
- Find and place the cursor at the end of the string /someText/e<ENTER>
Replace
- Replace the character pointed by the cursor: r then the new character
- Start overwriting mode: shift+r
Substitute
- Substitute the character pointed by the cursor: s then the new character
- Substitute all occurances of a string: :%s/pattern/newString/g
- Confirm each substitution for all occurances of a string: :%s/pattern/newString/gc
- Substitute the first occurance of a string from every line: :%s/pattern/newString/
- Substitute all occurances of a string from the selected text: select the text then :’<,’>s/pattern/newString/g
Capitalize
- Change the case of a character pointed by the cursor: ~
- Toggle between upper and lower case for selected text: Select the text then ~
- Change to uppercase for selected text: Select the text then shift+u
- Change to lowercase for selected text: Select the text then u
Find matching bracket
- Find the matching bracket pointed by the cursor: %
Open files
- Open the file where its path is pointed by the cursor: gf
- Navigate the directory structure to locate the file: :E<ENTER>
Split window
- Horizontal split: :sp<ENTER>
- Vertical split: :vsp<ENTER>
Indentation
- Indent the line where the cursor is placed: >>
- Indent the selected lines: select the text (lines) then >>
Get the unicode value of a character
- Unicode value of the character pointed by the cursor: :asc<ENTER> or ga
- UTF-8 value of the character pointed by the cursor: g8
Move the page
- Move the page so that the cursor is at the top of the screen: z<ENTER>
- Move the page so that the cursor is at the bottom of the screen: z-
- Move the page so that the cursor is in the middle of the screen: z.
Move the file from one window to another
- Move a file from the left window to the right window (vertical split): ctrl+w shift+l
- Move a file from the right window to the left window (vertical split): ctrl+w shift+h
- Move a file from the top window to the bottom window (horizontal split): ctrl+w shift+j
- Move a file from the bottom window to the top window (horizontal split): ctrl+w shift+k
Error list
- Open the error list after compilation: :cw
- Go to the next item in the error list: :cn
xxx
- xxx:
- xxx: