Custom .vimrc

For the first time in ages I have used vim again. And, of course, the first thing I did was to customise the default behaviour.

So far there are 3 things that I need regularly:

  • Toggle line numbers with
  • Toggle paste mode (to avoid unintended indenting) with
  • Execute python script in buffer with

All of this can be done with “my” .vimrc.

" .vimrc
"
" in most parts based on Smylers's .vimrc
" http://www.stripey.com/vim/
"

" have syntax highlighting in terminals which can display colours:
if has('syntax') && (&t_Co > 2)
syntax on
endif

" have command-line completion <Tab> (for filenames, help topics, option names)
" first list the available options and complete the longest common part, then
" have further <Tab>s cycle through the possibilities:
set wildmode=list:longest,full

" use "[RO]" for "[readonly]" to save space in the message line:
set shortmess+=r

" display the current mode and partially-typed commands in the status line:
set showmode
set showcmd

" when using list, keep tabs at their full width and display `arrows':
execute 'set listchars+=tab:' . nr2char(187) . nr2char(183)
" (Character 187 is a right double-chevron, and 183 a mid-dot.)

" have the mouse enabled all the time:
set mouse=a

" don't have files trying to override this .vimrc:
set nomodeline


" * Text Formatting -- General

" don't make it look like there are line breaks where there aren't:
set nowrap

" use indents of 4 spaces, and have them copied down lines:
set shiftwidth=4
set shiftround
set expandtab
set autoindent
set tabstop=4

" normally don't automatically format `text' as it is typed, IE only do this
" with comments, at 79 characters:
set formatoptions-=t
set textwidth=79

" get rid of the default style of C comments, and define a style with two stars
" at the start of `middle' rows which (looks nicer and) avoids asterisks used
" for bullet lists being treated like C comments; then define a bullet list
" style for single stars (like already is for hyphens):
set comments-=s1:/*,mb:*,ex:*/
set comments+=s:/*,mb:**,ex:*/
set comments+=fb:*

" treat lines starting with a quote mark as comments (for `Vim' files, such as
" this very one!), and colons as well so that reformatting usenet messages from
" `Tin' users works OK:
set comments+=b:\"
set comments+=n::

" paste mode
set pastetoggle=<F9>

" line number
set number
nnoremap <F2> :set invnumber<CR>

" Execute file being edited with <Shift> + e:
"map <buffer> <F5> :w<CR>:!/usr/bin/env python % <CR>
:nnoremap <f5> :!python %<CR>
comments powered by Disqus