It is the text editor of my choice. It’s designed to be much different than other editors since it uses different modes for editing (command and editing mode). This makes it more complex for beginners, but if you ship around the first hurdles, you’ll shurely like it!
I’d like to provide a few tricks for VIM, mainly commands I find very useful to work with. All of the commands are to be typed when using command mode (press [esc] to ensure you are in command mode), except when I say otherwise.
### Most common commands ###
i insert text to the left of cursor (change to insert mode) I insert text at beginning of line a append text to the right of cursor A append text at end of line [esc] switch to command mode (being in insert mode) w write to file q quit q! force quit (don’t save) cw change word dd delete line D delete until end of line r replace character R replace mode (like insert mode, but overwrites existing characters)
### Undo, Redo and Undo Undo ###
u undo last action . redo last action [ctrl]+r undo undo action
Highlight, cut, copy and paste text
v select characters of text V select lines of text Y copy selected text p paste copied text after this character/line P paste copied text before this character/line
### Changing case ###
gu{motion} make lowercase gU{motion} make uppercase guu make line lowercase gUU make line uppercase
### Substitute ###
can be any regular expression
:s/pattern/string/ substitute first match of with within this line :s/pattern/string/g substitute all matches of with within this line :%s/pattern/string/g substitute all matches of with within this file v{motion}:s/pattern/string/g substitute all matches of with within highlighted selection
### Splitting vim ###
:split path/to/file split window horizontal with path/to/file as second file :vsplit path/to/file split window vertical with path/to/file as second file [ctrl]+w w switch between viewports
### Special Inserts ###
If you’d like to insert text column-wise, eg. to comment some things out, you could use this nifty trick:
1. [ctrl]+v{motion}: select lines/area where you want to insert text
2. I: insert text to beginning of selection on each line; alternatively use A to append text to end of selection on each line
### Special Substitutions ###
%s/ ([a-z]*)=([^”][^> “}]*)/ 1=”2″/g creates “s around tag-attributes if non existing. makes