User Interface
Vim can be made easier to use with a few tweaks to its user
interface, as explained below. These are all included in the
sample .vimrc configuration file. Note that
separate pages deal with
keystrokes and
gui settings.
Syntax Highlighting
Syntax highlighting is A Good Thing, but only if the
Vim
binary being run has the facility, and only in terminals that can display
colours:
if has('syntax') && (&t_Co > 2)
syntax on
endif
Command-Line History
Having fifty lines of command-line (and search expression) history to
scroll through saves retyping previous commands:
set history=50
This is particularly useful when it is preserved between sessions. This
command remembers all the command-line history, though makes do with just
ten search expressions. It remembers info for ten files, though not
those on removable disks, it doesn’t save file marks, and it
doesn’t rehighlight previous search strings. It saves registers,
but only up to 100 lines:
set viminfo=/10,'10,r/mnt/zip,r/mnt/floppy,f0,h,\"100
(According to the documentation, sticking
@10 in there
should limit the amount of input-buffer history it bothers to store,
though this generates an error when I try it.)
Command-Line Completion
<Tab> can be used for command-line completion of
commands, help topics, option names, and filenames; an unambiguous
partial name will be completed by pressing it once. With the following
setting, pressing
<Tab> after an ambiguous partial name
will list the available options and complete as much as it can which is
common to all the possibilities; further presses of
<Tab> will then cycle through them:
set wildmode=list:longest,full
For example, after typing
:help getw pressing
<Tab> once will list the matching help topic names,
”getwinposx()” and “getwinposy()” and change the
command line to read
:help getwinpos, the longest common
part. The second match can then be written in full either by pressing
y (to make it unambiguous) then
<Tab> to
complete it, or simply by pressing
<Tab> twice to cycle
to it.
How Things are Displayed
Having the current mode indicated in the status line can help avoid
confusion, and in normal mode it can be useful to have partially-typed
commands entered (so when doing something like
gq3} you can
see how much has been typed). These commands do this:
set showmode
set showcmd
When displaying file information (EG with
<Ctrl>+G),
using the abbreviation “RO” for “readonly”
reduces the chance of it spilling over on to two lines and requiring a
‘hit return’ prompt:
set shortmess+=r
If
list is being used to show non-printing characters, it
can be nicer if instead of being shown as
^I, tab characters
are represented by
»··· (where the
number of dots used fills out to the next tabstop):
execute 'set listchars+=tab:' . nr2char(187) . nr2char(183)
Miscellaneous
The mouse can be enabled in terminals (where possible) with:
set mouse=a
This means that the mouse can be used to move the cursor and make visual
selections, like it does when using
Vim’s gui. To use
‘ordinary’
XTerm-style select and paste mouse
actions, hold down
<Shift<.
To prevent (other people’s?) files from being able to modify your
nice
Vim settings, do this:
set nomodeline
(If you want to have different
Vim settings for different
types of files, then do this properly —
use autocommands.)