Vim Setup - Tuning Vim To The Environment
February 27, 2008
Vim is best used when it is configured for the users needs. Vim has a slew of configurations to develop the type of environment the user requires to do numerous different tasks from spell checking to color syntaxing. There are thousands of scripts and color themes available on the Vim website that can add even more abilities.
I talked yesterday of learning Vim and perhaps just as important is tailoring one’s own configuration file (~/.vimrc). The best place to start is finding a person’s ~/.vimrc who is already experienced in Vim. Some distro’s may install a custom ~/.vimrc already so it’s best to take a look. I personally use Brians Carpers ~/.vimrc which does a good job for me. There are literally thousands out there and people like to share them, so pick the right one for whatever Vim needs to do.
Aesthetics
Setting up the terminal and Vim correctly are important parts for long periods in front of the terminal. To help ease reading and prevent eye strain a couple things that can help are choosing a lower-contrast colorscheme and properly sizing the width of the terminal
Colorscheme:
To pick a colorscheme that is comfortable for viewing for long periods go ahead and start up Vim - /etc/X11/xorg.conf can provide a good example. Now type:
colorscheme
follow by a space. Now press “tab” for tab-completion - pressing tab will cycle through the available color schemes. For example, this one is called pyte:
72 Section "InputDevice" 73 Identifier "Generic Keyboard" 74 Driver "kbd" 75 Option "CoreKeyboard" 76 # Option "XkbRules" "pc104" 77 Option "XkbLayout" "us" 78 Option "XkbLayout" "en_US" 79 Option "XkbModel" "macintosh" 80 # Option "XkbVariant" "apple" 81 EndSection 82 83 Section "InputDevice" 84 Identifier "Configured Mouse" 85 Driver "mouse" 86 Option "CorePointer" 87 Option "Device" "/dev/input/mice" 88 Option "Protocol" "auto" 89 Option "ZAxisMapping" "4 5" 90 EndSection
For xterm users (gnome-terminal, stjerm, tilda?, others?…) it’s likely that the terminal is set to eight bit color for compatibility reasons (see my post from a couple days ago). Vim though can display in 256 colors and will need to for alot of these colorschemes to work. To set Vim to 256 colors, add the setting to the ~/.vimrc
set t_Co_256
New colorschemes can be found in at the Vim website. To get a good idea what they look like before installed take a look at Vim Color Scheme Test. Color schemes can be permanently added by putting them in the ~/.vimrc:
colorscheme blue
Terminal Width
The width of the terminal is also important. Generally the human eye can only scan about 10 words before it loses focus (i.e. has difficulty scanning to the next line). Most editors use as a soft-standard a text margin of 72 characters, but some people like to go up to 80. Use whatever is best by resizing the window to fit this many characters. Vim unfortunately uses the window to control returns and though it has settings like “textwidth” and “wrapmargin” they enable soft-returns which create bad formatting to transfer text - so having a wide terminal is not a good idea with Vim.
V Tips
Now that we can read on to something functional.
A few tips I picked up along the line.
* Vim has great help documentation. :help topic can be done on about anything.
* Vim has tab-completion for entering commands and bash-completion for files (e.g. :w ~/Desktop/myblog.txt)
* The mouse can be used in Vim for some functions, but it needs to be enabled. I use this setting as I find that moused in visual mode can be distractive.
set mouse=nic
- To be able to select text with the mouse in this mode hold the shift key
A few other tips:
[[ start of the file ]] end of the file
I Insert at beginning of line A Append to end of line
Tab-mode rules:
vim -p doc1 doc2 gt go through tabs :tabnew To open new tab
Append a file:
:w >> ~/My-lousy-document
Check spelllinng:
:setlocal spell spelllang=en_us :setlocal nospell ]s next word [s previous word z= word suggestions
Spelling can be mapped to a key if used frequently enough, in my ~/.vimrc I mapped spelling the the F7 key:
map <F7> <Esc>:setlocal spell spelllang=en_us map <S-F7> <Esc>:setlocal nospell
My Terminal - Gush
Entry Filed under: Linux. .
6 Comments Add your own
Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed





1.
Necoro | February 27, 2008 at 2:15 pm
“:w ~/My-lousy-document”
This _overwrites_ the file and does not append
you want “:w >> ~/My-louse-document”
And: Please get rid of the “bash” in “bash-completion” …
- you mean “tab-completion” as the vim commands have nothing to do with Bash =)
2.
Dirk Gently | February 27, 2008 at 2:48 pm
Necero wrote:
“:w ~/My-lousy-document”
This _overwrites_ the file and does not append
Then its apt then.
Ok… fixed.
Necero wrote:
And: Please get rid of the “bash” in “bash-completion” …
- you mean “tab-completion” as the vim commands have nothing to do with Bash =)
I see the point, Vim does have bash support but I agree the text was ambiguous - fixed.
3.
tante | February 27, 2008 at 6:34 pm
and btw, the colorthing:
it’s “set t_Co=256″ just if people wonder
4.
xenoterracide | February 29, 2008 at 2:53 pm
bash-completion may be tab-completion but on gentoo the flag to enable it is bash-completion. maybe vim calls it the same.
5.
Steven Oliver | February 29, 2008 at 6:13 pm
Yes, there is nothing worse than a distro with an annoying default vimrc and gvimrc. Drives me crazy. I’ve even filed bug reports about it (to no avail, but I try).
6.
miker | March 31, 2008 at 7:09 pm
Thanks! A few nice tips I hadn’t seen before.