You are on page 1of 5

set nocompatible " must be the first line

filetype on
filetype indent on
filetype plugin on

"autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete


"autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
"if you want rails support add the following in addition
"autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
"if you want classes included in global completions add the following
"autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
"autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

" saves and restores things like folds when closing a file
au BufWinLeave * silent! mkview
au BufRead * silent loadview
au BufRead * set autoindent
au BufWinEnter * silent set nopaste
au BufWinEnter * set autoindent
au BufWinEnter * set nu
au BufWinEnter * silent set sw=4
au BufReadPost SCons* set syntax=python
au BufReadPost *py set syntax=python
au BufReadPost *rb set syntax=ruby
au BufReadPost *html set syntax=html
"au BufReadPost *py set complete+=k/home/mats/.vim/pycmpl/pydiction
au BufReadPost *py vmap \em :call PythonExtractMethod()<cr>
"au BufWritePost *py set complete=k/home/mats/.vim/pycmpl/pydiction
"au BufWritePost *py set complete+=k/home/mats/.vim/allwords

"column of cursor
set nocuc
colo delek
"for vim windows
set noea
set scs
set nu
set dict=/home/mats/.vim/allwords
set expandtab
set autoindent
set history=50
set ruler
set showcmd
set incsearch
set tabstop=4
set sw=4
set scrolloff=6
"set mouse=
let NERDTreeIgnore=['\.vim$', '\~$', '\.pyc$']

command! -range Bash :!bash<Space>-c<Space>"`sed<Space>-


ne<Space>'<line1>,<line2><Space>p'<Space>%`"
command! -range Tidy :<line1>,<line2>!tidy -iq --indent-spaces 4 -xml -omit -w 120
command! -range Filter :<line1>,<line2>!bash

"MAPS
map <F2> :!python %<CR>
map <F3> .j|1
map <F4> :winc p<cr>
map <F7> :Filter<CR>
map <F8> :NERDTree<cr>:set nonu<cr>
"map kj
:set<space>cul!<cr>:set<space>cuc!<cr>:set<space>cul!<cr>:set<space>cuc!<cr>
map <BS> g;
map \s :Swap(0)<cr>
map \S :Swap(1)<cr>
map <F9> I#<Esc>j
map <F10> I<del><esc>j
map \<F11> :w! /tmp/a<CR>
map \<F12> :w<CR>:Bash<CR>
" map <F5> :let g:file=expand('%').'/'.getline('.') <bar> wincmd p <bar> exec ':e
'.g:file<cr>
map <F5> :tabp<cr>
map <F6> :tabn<cr>
map <F11> :q<cr>
map <F12> :w<cr>
map <S-Tab> <C-W><C-W>
map \<Tab> <C-W>W
imap <F11> <esc><F11>
imap <F12> <esc><F12>a
map \<Ins> :set invpaste<cr>
map \f "syiw:Find<space>^Rs<cr>
map \* "syiw:Grep<space>#s<cr>
imap \\ ()<esc>i
imap '' ''<esc>i
imap "" ""<esc>i
imap [] []<esc>i
imap \<Ins> <Esc>:set invpaste<cr>i
imap <C-s> <C-o>:w<CR>
imap #TO #TODO:<space>
imap <table> <table><tr><td></td></tr></table><esc>17h
map <C-s> :w<CR>
map <space> 10j
map #<space> 10k

"LANGUAGE-RELATED
imap ~try except:<Esc>Otry:
imap ~init def __init__(self,
imap ~im def (self,<Esc>hhhhhi
imap ~ife if: <cr>else:<Esc>kA

set path=.,**
"set completefunc=rubycomplete#Complete
"set omnifunc=htmlcomplete#CompleteTags
set laststatus=2
set statusline=%<%f\%h%m%r%=%-20.(line=%l\ \ col=%c%V\ \ totlin=%L%)\ \
\%h%m%r%=%-40(bytval=0x%B,%n%Y%)\%P
hi StatusLine ctermbg=7 ctermfg=0 gui=undercurl guisp=Yellow
hi ModeMsg ctermbg=1 ctermfg=3
function! Grep(name)
let l:pattern = input("Other pattern: ")
"let l:_name = substitute(a:name, "\\s", "*", "g")
let l:list=system("grep -nIR '".a:name."' * | grep -v 'svn-base' | grep '"
.l:pattern. "' | cat -n -")
let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))
if l:num < 1
echo "'".a:name."' not found"
return
endif

echo l:list
let l:input=input("Which?\n")

if strlen(l:input)==0
return
endif

if strlen(substitute(l:input, "[0-9]", "", "g"))>0


echo "Not a number"
return
endif

if l:input<1 || l:input>l:num
echo "Out of range"
return
endif

let l:line=matchstr("\n".l:list, "".l:input."\t[^\n]*")


let l:lineno=matchstr(l:line,":[0-9]*:")
let l:lineno=substitute(l:lineno,":","","g")
"echo "".l:line
let l:line=substitute(l:line, "^[^\t]*\t", "", "")
"echo "".l:line
let l:line=substitute(l:line, "\:.*", "", "")
"echo "".l:line
"echo "\n".l:line
execute ":e ".l:line
execute "normal ".l:lineno."gg"
endfunction
command! -nargs=1 Grep :call Grep("<args>")

function! Find(name)
let l:_name = substitute(a:name, "\\s", "*", "g")
let l:list=system("find . -iname '*".l:_name."*' -not -name \"*.class\" -and
-not -name \"*.swp\" | perl -ne 'print \"$.\\t$_\"'")
let l:num=strlen(substitute(l:list, "[^\n]", "", "g"))
if l:num < 1
echo "'".a:name."' not found"
return
endif

if l:num != 1
echo l:list
let l:input=input("Which ? (<enter>=nothing)\n")

if strlen(l:input)==0
return
endif

if strlen(substitute(l:input, "[0-9]", "", "g"))>0


echo "Not a number"
return
endif
if l:input<1 || l:input>l:num
echo "Out of range"
return
endif

let l:line=matchstr("\n".l:list, "\n".l:input."\t[^\n]*")


else
let l:line=l:list
endif

let l:line=substitute(l:line, "^[^\t]*\t./", "", "")


"echo "".l:line
execute ":e ".l:line
endfunction
command! -nargs=1 Find :call Find("<args>")

function! Swap(reverse)
let l:chars = ',:()\[\]{}'
let l:search = "[".l:chars."]"
let l:reverse = a:reverse
if l:reverse == 1
echo 'backwards'
let l:col=search(l:search,"bW")
exe "normal h"
"echo col(".")
endif
let l:line=getline(".")
let l:oldcol=col(".")
"exe "normal f,"
let l:col=search(l:search,"W")
let l:rightcol=col(".")
"echo "first rightcol " . l:rightcol
"exe "normal T,"
let l:col=search(l:search,"bW")
let l:leftcol=col(".")
"echo "first leftcol " . l:leftcol
exe "normal l\"sd" . l:rightcol . "|"
"we have the first word
exe "normal " . (l:rightcol-(l:rightcol-l:leftcol)) . "|l"
let l:leftcol=col(".")+1
"echo "second leftcol " . l:leftcol
"exe "normal f,"
let l:col=search(l:search,"W")
exe "normal \"td" . l:leftcol . "|"
"we have the second word
"echo "swapping " . @s . " and " . @t
"do the pasting
exe "normal h\"tPl\"sp"
"echo "done"
endfunction
command! -nargs=1 Swap :call Swap(<args>)

"refactoring
function! PythonExtractMethod() range
let name = inputdialog("Name of new method: ")
let args = inputdialog("Argument list: ")
'<
exe "normal O\<cr>def " . name ."(" . args . "):\<esc>"
'>
exe "normal o#return \<cr>\<esc>"
normal >'<
endfunction