What most need is just a quick guide to set up VIM so that it can rival most heavy GUI editors in features. And here it is. There's also GVim, a GUI version of VIM, but IMHO the main advantage of VI is that it can run in a terminal and is very quick on remote connections, where GVim would be too slow or not installed at all.
Firstly, avoid using ancient VI version adding this to your .bashrc:
Some useful keystrokesEsc: return to normal mode
i: insert at current location
I: insert at start of current line
a: insert after current location (append)
A: insert after end of current line (shortcut for $a)
o: insert line below current line (open)
O: insert line above current line
s: delete character under cursor and start inserting in its place (substitute text, shortcut for xi)
S or cc: delete all text on line and start inserting in its place (substitute or change line)
.: repeats last operation
*: search forward for the next occurrence of the word under the cursor
ci": replace what’s inside the next set of
"and go into insert mode. You can also use ' instead of ", etc (any character, you choose)
^: go to the beginning of line
$: go to the end of line
q: stop recording and save a macro. Make sure you end up in a state that allows running next iteration, e.g. same position as initial but on the next line.
Ctrl^N: complete current word with first match in text (press again to select the next match). INSERT mode only.
Ctrl^P: complete current word with last match in text (press again to select the previous match). INSERT mode only.
How to use a dictionary for word completion. E.g. I am bilingual Italian-English and I have in my .vimrc:
set dictionary=/usr/share/dict/british-english,/usr/share/dict/italian set complete-=k complete+=k
Useful colon commands
:n edit next file in argument list
:N edit previous file in argument list
Useful .vimrc commandsTo use your mouse to move the text cursor or select, in all modes:
You can still copy and paste the X primary selection by holding the shift key before selecting or middle-clicking, respectively. Your mouse wheel, if any, will work even when mouse="". If your mouse does not have a middle button, you may find the keyboard short-cut to paste (shift-ins) more convenient.
Turn on the Highlight Search option:
Enable syntax highlighting:
If you are using a dark background for your terminal you may want to:
Display commands or file name completion in a one-line menu at the bottom, so that you can more easily see what the options are when cycling through alternatives with the Tab key:
Set the currently edited file name and path (directory) in terminal title. On exit, the old terminal title is restored.
Show partial commands in the last line of the screen:
Features you may want to toggle manuallyEnable syntax highlighting if your file has the wrong extension, e.g. not .php for a PHP file:
Switch off search highlighting for the current search. It can be shortened up to
Makes vim show hidden characters: '$' indicates EOL, '^I' tabspace
Toggles back to normal mode:
When creating documentation rather than source code, you may want VIM to automatically break lines for you, e.g. to have a textwidth of 70 characters:
Scripts and add-onsvimfortune - displays a VIM usage tip every time you start vim with an empty buffer. The only drawback: some tips are quite long and take time to read, but you can skip it (press q if the tip is more than one page long)
set cindent ” for c indentation(correct spacing)
See other basic stuff here: