Vim Setup – Tuning Vim To The Environment

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.


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


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:


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
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 need to be put in ~/.vim/colors and then a color scheme can be permanently added by putting them in the ~/.vimrc:

colorscheme blue

Terminal Width

The width of the terminal is also important. The human eye can only scan about 10 words before it loses focus (i.e. has difficulty scanning to the next line). Most text in Linux is written with a margin of 72 or 80 characters. Most editors also use a soft-returns (i.e. not a hard line break). Use whatever is best by resizing the window to fit this many characters. Vim cannot set a soft-return and rather uses the window width. This is unfortunate as some terminal apps (tilda, and yakuake) use the entire width of the screen – yes vim has settings like “textwidth” and “wrapmargin” but they create hard-returns, so having a wide terminal is not a good idea with Vim.

V Tips

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=ni
  • To be able to select text with the mouse in this mode hold the shift key
  • 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
  • I like to alway have tabs so I put these in my ~/.bashrc to have tabs every time I open a file:
  • alias v="vim -p"
    alias sv="sudo vim -p"

My Terminal – Gush

Vim Setup - Tuning Vim To The Environment 


9 thoughts on “Vim Setup – Tuning Vim To The Environment

  1. Necoro

    “: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 Post author

    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. Steven Oliver

    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).

  4. Pingback: VIM – How I started climbing the steep learning cuve « Prog Quest

  5. Pingback: VIM – How I climbed the steep learning curve « Prog Quest

  6. Lambert Hicks

    For full checklist of NERDCommenter commands see SuperTab let us me do all my insert mode end using the key. Type a couple of letters of the term and press important and if it occurs somewhere in the open buffers, SuperTab will autocomplete it.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s