" Find .vim files
set rtp+=~/.vim
" Switch on syntax highlighting.
syntax on
" Plugins
filetype plugin on
set shellslash
filetype indent on
" Hide the mouse pointer while typing
set mousehide
" VIM info
set viminfo='20,\"50,/0
" Show column/line
set ruler
" Command height is 2 lines height
set ch=2
" Nice status line
set statusline=%F%m%r%h%w\ [%{&ff}]\ %y\ [%l:%c]
set laststatus=2
" File backup?
set nobackup
" Ignore case in search
set ignorecase
" show match
set smartcase
" scroll margin 5 lines
"set scrolloff=5
" Backspace works as usual
set backspace=2
" Show matching parenthesis
set showmatch
" Allow reverse insert
set allowrevins
" Not compatible mode
set nocompatible
" Incremental search
set incsearch
" Tab stuff
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
" Use custom "make"
set makeprg=mk
" Printing
set printoptions=paper:letter
" Don't highlight search
set nohls
" Use system clipboard
set clipboard=unnamed
" Use CSS in generated HTML (TOhtml)
let html_use_css = 1
" GUI Stuff
if has("gui_running")
" No toolbar for me
set guioptions-=T
" No menu for me
set guioptions-=m
" Color scheme
colorscheme midnight
" Set font
if $HOSTNAME =~ "bugs"
set guifont=Monospace\ 20
"set guifont=Courier\ 20
elseif $HOSTNAME =~ "kurma"
set guifont=Courier\ 16
elseif $HOSTNAME =~ "tom"
set guifont=Courier\ 16
elseif has("gui_mac")
set guifont=Courier:h24
endif
if has("gui_win32")
" Maximize window on startup
au GUIEnter * simalt ~x
set guifont=Courier_New:h18
" TagList
let g:Tlist_Ctags_Cmd="$HOME/bin/wctags.exe"
endif
endif
" Automatic file type
filetype on
" C/C++
au BufNewFile,BufRead *.c,*.cc,*.h,*.cpp,*.hpp,*.cxx setlocal cindent
au BufNewFile,BufRead *.c,*.cc,*.h,*.cpp,*.hpp,*.cxx setlocal comments=
au BufNewFile,BufRead *.c,*.cc,*.h,*.cpp,*.hpp,*.cxx setlocal et
" ClearCase Perl files end with .prl
au BufNewFile,BufRead *.prl setlocal ft=perl
" Latex
au BufNewFile,BufRead *.tex,*.latex setlocal et
" Java
au BufNewFile,BufRead *.java call SetJavaMake()
" Turn on spelling in subversion commits
au BufNewFile,BufRead svn-commit.* set spell
" JavaScript
au BufNewFile,BufRead *.js set autoindent
au BufNewFile,BufRead *.js set smartindent
func! ASCII_Clean()
silent %! iconv -c -t ASCII
endfunc
" Email
au BufNewFile,BufRead *.eml set spell
au BufNewFile,BufRead *.eml set tw=72
au BufNewFile,BufRead *.eml set smartindent
au BufNewFile,BufRead *.eml set autoindent
" FIXME: Do we *want* this?
au BufNewFile,BufRead *.eml call ASCII_Clean()
func! MuttCfg()
map <C-J> {gq} " Ctrl+J rejustifies current paragraph
set formatoptions=tcroqv " see :help formatoptions
set comments=nb:> " rejustify quoted text correctly
set tw=75 " wrap lines to 75 chars
set ft=mail " mail file type
colorscheme koehler " nice colors
endfunc
au BufNewFile,BufRead /tmp/mutt* call MuttCfg()
" Unix file format
au BufNewFile * set fileformat=unix
" Window movement
noremap <C-TAB> :bn<CR>
noremap <C-F4> :bd<CR>
noremap <S-C-TAB> :bN<CR>
" Space for page up/down
noremap <SPACE> <C-F>
noremap <S-SPACE> <C-B>
" Hebrew composing
func! SetHebrew()
set hkmap
set rl
endfunc
comm! He call SetHebrew()
func! SetEnglish()
set nohkmap
set norl
endfunc
comm! En call SetEnglish()
" Reply
noremap <F10> :g/^/s//>/<CR>
" Text width
set textwidth=80
" Explorer to show full info
let g:explDetailedList=1
" Use hidden (allow buffer switch when modified)
au BufNewFile,BufRead * set hidden
" Add Python Author + ID
" Add Copyright and the above
map <F3> :Cr<CR>jjjj<F2>
func! SP()
w
!aspell -e -c `cygpath -u %`
e
endfunc
comm! Spell call SP()
" Find
set grepprg=vimfind
" Aliases file is a muttrc file
au BufNewFile,BufRead aliases set ft=muttrc
au BufNewFile,BufRead .addressbook set ft=muttrc
" Add signature
comm! Sig :r~/.signature
comm! Fsig :r~/.formal-signature
" Add copyright notice
comm! Cr :r ~/.miki-copyright.txt
" Aliases file is a muttrc file
au BufNewFile,BufRead *.txt set autoindent
" Email abbriviation
abb _me_ Miki Tebeka <miki@fattoc.com>
abb _gme_ Miki Tebeka <miki.tebeka@gmail.com>
abb _fme_ Miki Tebeka <miki@feedbetter.com>
" Other abbriviation
abb _py_ #!/usr/bin/env python
abb _lpy_ #!/usr/local/bin/python
abb _sh_ #!/bin/bash
" SConstruct file is a Python file
au BufNewFile,BufRead SConstruct,SConscript set ft=python
" .i are SWIG files (C is closest)
au BufNewFile,BufRead *.i set ft=c
" Python stuff
au BufNewFile,BufRead *.py,*.pyw set makeprg=pychecker\ --only\ %
au BufRead,BufNewFile * if &ft == 'python' | set ft=pymulti | endif
" Indent in lex files
au BufNewFile,BufRead *.l set autoindent
au BufNewFile,BufRead *.l set smartindent
" Comments
comm! -range Comment :'<,'>s/^/#/
comm! -range Uncomment :'<,'>s/^#//
comm! -range Ecomment :'<,'>s/^/>/
" Replace line with =
noremap & yyp:s/./=/g<CR>o
noremap ^ yyp:s/./-/g<CR>o
" Search for tags in parent directory
set tags+=../tags
" Add date
comm! AD :r !date +\%m/\%d/\%Y
" wildmenu command-line completion shows a list of matches
set wildmenu
" Change file to writable
func! MakeWritable()
w
!chmod +w %
e
endfunc
comm! WR silent call MakeWritable()
" Make file executable
func! MakeExecutable()
w
!chmod +x %
e
endfunc
comm! MX silent call MakeExecutable()
" New Class in Python
func! PyNC(name, ...)
python << EOF
import vim
append = vim.current.range.append
args = []
for i in range(1, int(vim.eval("a:0")) + 1):
args.append(vim.eval("a:{%d}" % i))
append("class %s:" % vim.eval("a:name"))
init = " def __init__(self"
for arg in args:
init += ", %s" % arg
append(init + "):")
for arg in args:
append(" self.%s = %s" % (arg, arg))
EOF
endfunc
comm! -nargs=+ NC call PyNC(<f-args>)
func! ProcmailRule(where, to)
python << EOF
template = ''':0
* ^(To|CC): .*%s.*
%s/
'''
import vim
where = vim.eval("a:where")
where = where.replace(".", "\\.")
to = vim.eval("a:to")
vim.current.range.append((template % (where, to)).split("\n"))
EOF
endfunc
comm! -nargs=+ NR call ProcmailRule(<f-args>)
" New Python interface function
func! PyInt(name)
python << EOF
import vim
template = '''static PyObject *
%s(PyObject *self, PyObject *args)
{
if (!PyArg_ParseTuple(args, "")) {
return NULL;
}
return Py_BuildValue("");
}
'''
vim.current.range.append((template % vim.eval("a:name")).split("\n"))
EOF
endfunc
comm! -nargs=1 PI call PyInt(<f-args>)
func! PyNewTest(name)
python << EOF
import vim
template = """def test_%s(self):
assert 1 == 0, "wrong universe"
"""
vim.current.range.append((template % ((vim.eval("a:name"), )* 2)).split("\n"))
EOF
endfunc
comm! -nargs=1 NT call PyNewTest(<f-args>)
comm! SP setlocal spell spelllang=en_us
comm! Fcd cd %:p:h
func! CTags()
!ctags -R %:p:h
endfunc
comm! CT call CTags()
" .tac are Python files
au BufNewFile,BufRead *.tac set ft=python
func! SetJavaMake()
" First check for scons
let scons = findfile("SConstruct", ".")
if strlen(scons) > 0
set makeprg=scons\ -Q
return
endif
" Now check for ant
let ant = findfile("build.xml", ".")
if strlen(ant) > 0
set makeprg=ant
return
endif
set makeprg=javac\ %
endfunc
func! PutPath()
silent !putpath %
endfunc
comm! PU call PutPath()
func! PyMainTemplate()
python << EOF
import vim
template = """
def main(argv=None):
if argv is None:
import sys
argv = sys.argv
from optparse import OptionParser
parser = OptionParser("usage: %prog ")
opts, args = parser.parse_args(argv[1:])
if len(args) != 1:
parser.error("wrong number of arguments") # Will exit
if __name__ == "__main__":
main()
"""
for line in reversed(template.splitlines()):
vim.current.range.append(line.rstrip())
EOF
endfunc
comm! PYM call PyMainTemplate()
func! HTMLEscape()
silent :'<,'>s/&/\&/eg
silent :'<,'>s/</\</eg
silent :'<,'>s/>/\>/eg
endfunc
comm! -range HE call HTMLEscape()
func! HTMLUnEscape()
silent :'<,'>s/</</eg
silent :'<,'>s/>/>/eg
silent :'<,'>s/&/\&/eg
endfunc
comm! -range HU call HTMLUnEscape()
func! SVNDiff()
let dirname = expand('%:p:h')
let filename = expand('%')
execute ":vert diffsplit" . dirname . "/.svn/text-base/" . filename . ".svn-base"
unlet filename dirname
return
endfunc
comm! SD call SVNDiff()
func! BZRDiff()
let filename = expand("%")
let tempfile = "/tmp/" . expand("%:t")
let shell_command = "bzr cat -r-1 " . filename . " > " . tempfile
call system(shell_command)
execute ":vert diffsplit " . tempfile
unlet filename tempfile shell_command
endfunc
comm! BD call BZRDiff()
" Tags file (in sigscope)
function FATtags()
let old_tags = &tags
let bzr_root = substitute(system("bzr root"), '\n', '', 'e')
let &tags = old_tags . ',' . bzr_root . "/tags"
unlet old_tags bzr_root
endfunc
au BufNewFile,BufRead */fattoc/* call FATtags()