Created
October 19, 2011 17:33
-
-
Save vpetro/1299039 to your computer and use it in GitHub Desktop.
my vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filetype off | |
call pathogen#helptags() | |
call pathogen#runtime_append_all_bundles() | |
filetype on | |
set nocompatible | |
set hidden | |
set t_Co=256 | |
" Indenting { | |
set autoindent | |
set smartindent | |
" set how many lines to to keep when scrolling | |
set scrolloff=4 | |
" scroll the terminal faster | |
nnoremap <C-e> 3<C-e> | |
nnoremap <C-y> 3<C-y> | |
set previewheight=20 | |
" make searches case-sensitive only if they contain upper case stuff | |
set ignorecase | |
set smartcase | |
" set the tab width to 4 chars | |
set tabstop=4 | |
" set the number of space characters used for identation | |
set shiftwidth=4 | |
" } | |
" set the backspace to something sane | |
set backspace=2 | |
set whichwrap+=<,>,h,l | |
" convert the tabs to spaces | |
set expandtab | |
" visually show matching parens | |
set showmatch | |
" Searching { | |
" visually highlight search results | |
set hlsearch | |
" turn off the highlighting with ctrl-n | |
nmap <silent> <C-n> :noh<CR> | |
" use incremental search | |
set incsearch | |
" } | |
" turn on syntax highlighting | |
syntax enable | |
" better word handling | |
set iskeyword=~,@,48-57,_,192-255 | |
" more history | |
set history=1000 | |
" dont want to edit these files | |
set suffixes=.bak,~,.swp,.o,.info,.aux,.log,.dvi,.bbl,.blg,.brf,.cb,.ind,.idx,.ilg,.inx,.out,.toc,.cmi,.cmo,.cmx,.cmxa,.exe,.ho,.hi,.bc,.out,.annot,.spot | |
" tell vim to figure out the file type | |
filetype plugin on | |
" indent based on the file type | |
filetype indent on | |
" dont wrap the lines | |
set nowrap | |
set ttyfast | |
" save the file when vim loses focus. useful. | |
au FocusLost * :wa | |
" set up the nice command matching | |
set wildmenu | |
set wildmode=list:longest | |
set wildignore+=*.o,*.obj,.git,*.class,*.pyc,bin,*.log,obj,*.pidb | |
set wildignore+=*.aux,*.bbl,*.blg,*.fdb_latexmk,*.bst,*.pdf | |
" set the terminal title | |
set title | |
" switch directory to the same dir has the location of the current file | |
"set autochdir | |
" dont outdent the hashes it is really annoying | |
set smartindent | |
"inoremap # X# | |
" turn off the toolbar and menubar | |
if has('gui_running') | |
set showtabline=1 | |
set guioptions-=m | |
set guioptions-=T | |
set guioptions-=l | |
set guioptions-=L | |
set guioptions-=r | |
set guioptions-=R | |
set guioptions-=e | |
set gfn=Monaco:h12 | |
set linespace=0 | |
" set up the values for solarized | |
let g:solarized_bold=0 "default value is 1 | |
let g:solarized_underline=0 "default value is 1 | |
let g:solarized_italic=0 "default value is 1 | |
let g:solarized_contrast="high" "default value is normal | |
let g:solarized_visibility="high" "default value is low | |
let g:solarized_diffmode="high" "default value is normal | |
let g:solarized_termcolors=256 | |
let g:solarized_menu=0 | |
set background=light | |
colorscheme twilight | |
else | |
colorscheme rubyblue | |
set background=dark | |
end | |
" set the directory for .swp files so that they | |
" dont appear in the current directory of the file being | |
" edited | |
set dir=/Users/petrov/.tmp | |
" show the line numbers by default | |
set number | |
set rnu | |
set ruler | |
" set to auto read when a file is changed from the outside | |
set autoread | |
" no sound on errors. | |
set noerrorbells | |
set novisualbell | |
set visualbell t_vb= | |
" Set mapleader | |
let mapleader = "," | |
let g:mapleader = "," | |
let localleader ="," | |
let maplocalleader = "," | |
" set the map for make | |
map <Leader>m :make<CR> | |
" remap the escape, it is tiny on the macbook keyboard and i miss the ctrl-[ key | |
ino jj <esc> | |
cno jj <C-c> | |
" <cr> doesn't do anything in normal mode, map it to save | |
noremap W :w<cr> | |
nmap <leader>s :setlocal spell! spelllang=en<CR> | |
set laststatus=2 | |
set statusline=%<%f\ %h%w%m%r%y%=L:%l/%L\ (%p%%)\ C:%c%V\ B:%o\ F:%{foldlevel('.')}\ FF:[%{&fileformat}]\ G:%{fugitive#statusline()} | |
" If possible, try to use a narrow number column. | |
if v:version >= 700 | |
try | |
setlocal numberwidth=3 | |
catch | |
endtry | |
endif | |
" Enable fancy % matching | |
if has("eval") | |
runtime! macros/matchit.vim | |
endif | |
" quickfix things | |
nmap <leader>co :botright cwindow<cr> | |
nmap <leader>cq :cclose<cr> | |
nmap <leader>cn :cnext<cr> | |
nmap <leader>cl :clast<cr> | |
nmap <leader>cp :cprevious<cr> | |
" Fast split movement | |
set wmh=0 | |
map <c-j> <c-w>j | |
map <c-k> <c-w>k | |
nmap <c-h> <c-w>h | |
nmap <c-l> <c-w>l | |
"Fast saving | |
nmap <leader>q :q!<cr> | |
nmap <leader>w :w!<cr> | |
nmap <leader>f :find<cr> | |
" Taglist | |
let Tlist_Ctags_Cmd="/opt/local/bin/ctags" | |
let Tlist_Win_Width=50 | |
let Tlist_Show_One_File=1 | |
" nerd tree stuff | |
map <leader>d :NERDTreeToggle<cr> | |
" fugitive.vim | |
nmap <leader>gs :Gstatus<cr> | |
nmap <leader>gw :Gwrite<cr> | |
nmap <leader>gg :Gcommit<cr> | |
nmap <leader>gl :Git log<cr> | |
nmap <leader>gb :Gblame<cr> | |
" external mapping for tests | |
nmap <leader>nt :!nosetests Tests<cr> | |
" set encoding | |
set enc=utf-8 | |
set fileformats=unix,dos,mac | |
" put the search result in the middle of the screen | |
nmap n nzz | |
nmap N Nzz | |
nmap * *zz | |
nmap # #zz | |
nmap g* g*zz | |
nmap g# g#zz | |
set list! | |
set listchars=tab:»·,trail:· | |
" Python { | |
" Run the current buffer through python | |
"Run in the Python interpreter | |
function! Python_Eval_VSplit() range | |
let src = tempname() | |
let dst = tempname() | |
execute ": " . a:firstline . "," . a:lastline . "w " . src | |
execute ":!python " . src . " > " . dst | |
execute ":pedit! " . dst | |
endfunction | |
" } | |
" Completion { | |
autocmd FileType python set omnifunc=pythoncomplete#Complete | |
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS | |
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags | |
"autocmd FileType css set omnifunc=csscomplete#CompleteCSS | |
"autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags | |
"autocmd FileType php set omnifunc=phpcomplete#CompletePHP | |
autocmd FileType c set omnifunc=ccomplete#Complete | |
" dont display pydoc window | |
set completeopt=longest,menuone | |
set completeopt-=preview | |
" limit the popup menu height to 15 | |
set pumheight=15 | |
" } | |
" shut up the NERD commenter when it doesn't understand the filetype | |
" NERDCommenter { | |
let NERDShutUp=1 | |
" } | |
" Haskell { | |
let g:haddock_browser = "open" | |
let g:haddock_browser_callformat = "%s %s" | |
let g:haddock_docdir = "/Library/Frameworks/HaskellPlatform.framework/share/doc" | |
" } | |
" paying around with functions from http://bitbucket.org/garybernhardt/dotfiles/src/tip/.vimrc | |
function! RedBar() | |
hi RedBar ctermfg=white ctermbg=red guibg=red | |
echohl RedBar | |
echon repeat(" ", &columns - 1) | |
echohl | |
endfunction | |
function! GreenBar() | |
hi GreenBar ctermfg=white ctermbg=green guibg=green | |
echohl GreenBar | |
echon repeat(" ", &columns - 1) | |
echohl | |
endfunction | |
function! ConvertRstToHtml() | |
:!/opt/local/bin/rst2html-2.6.py --stylesheet-path=/Users/petrov/blog/style/lsr.css <afile> <afile>:p:r.html && python /Users/petrov/.rst/insert_jsmath.py <afile>:p:r.html | |
endfunction | |
" change the tab settings for html/xml files and templates | |
augroup stuff | |
autocmd! | |
autocmd FileType python map <buffer> <leader><space> :w!<cr>:!python %<cr> | |
autocmd FileType python vmap <F7> :call Python_Eval_VSplit()<cr> | |
autocmd FileType html,xhtml,xml,htmldjango,htmljinja,mako setlocal expandtab shiftwidth=2 tabstop=2 softtabstop=2 | |
autocmd BufWritePost,FileWritePost *.blog :silent! call ConvertRstToHtml() | |
autocmd BufEnter *.hs compiler ghc | |
autocmd BufRead *.tex set ft=tex | |
augroup END | |
autocmd FileType python set nosmartindent | |
autocmd FileType python set makeprg=pylint-2.6\ -d\ C0111\ --reports=n\ --output-format=parseable\ %:p | |
autocmd FileType python set errorformat=%f:%l:\ %m | |
"autocmd BufWritePost,FileWritePost *.py :silent! make | |
"nmap <leader>b :python import vim; vim.command('vertical resize %d' % max([len(line)+10 for line in vim.current.buffer])) | |
nmap <leader>b :exe "normal " . (winwidth(0)*3/2) . "\<C-W>|" | |
" open a terminal the directory where the current file is | |
nmap <leader>o :silent! !term shell<cr> | |
autocmd FileType tex nmap <leader>f vipgq | |
"autocmd FileType tex :source ~/.vim/abbreviations | |
autocmd BufEnter *.tex :source ~/.vim/abbreviations | |
autocmd FileType xml nmap <leader>x :execute "!tidy -m -xml -i -utf8 " . expand("%:p") | |
" Pull word under cursor into LHS of a substitute | |
nmap <leader>z :%s#\<<c-r>=expand("<cword>")<cr>\># | |
"nmap <leader>x /def <c-r>=expand("<cword>")<cr> | |
nmap <leader>hs :!hg st<cr> | |
nmap <leader>hc :!hg ci -m ''<Left> | |
nmap <leader>g :TlistToggle<cr> | |
" test function for running the file | |
function! RunPythonAndOutputToBuffer() | |
" the name of the temporary file | |
let dst = tempname() | |
"execute ": " . a:firstline . "," . a:lastline . "w " . src | |
execute ":silent ! python " . expand("%:p") . " > " . dst . " 2>&1 " | |
execute ":pedit " . dst | |
endfunction | |
function! WriteParams() | |
python << endpython | |
import re | |
import vim | |
# get the function definition line | |
line = vim.eval("getline(line('.'))") | |
# get the number of spaces to add to the start of the line | |
num_spaces = 4 + len(line) - len(line.lstrip()) | |
# get the line number wher to do the insertion | |
line_number = int(vim.eval("line('.')")) | |
# find the parameter names in the function definition | |
params = re.findall("[\w=]+", line)[2:] | |
# the header and the footer of the doctstring | |
lines = ['"""', ""] | |
for param in params: | |
# skip the 'self' since it doesn't have to be documented. | |
if param == "self": | |
continue | |
# handle the default argument parameters | |
if "=" in param: | |
param_name = param.split('=')[0] | |
param_default_value = "".join(param.split('=')[1:]) | |
lines.append(":param %s: (Default value: %s)" % (param_name, param_default_value)) | |
lines.append(":type %s:" % param_name) | |
else: | |
lines.append(":param %s:" % param) | |
lines.append(":type %s:" % param) | |
lines.append(":returns:") | |
lines.append('"""') | |
# insert the contents of the list into the buffer | |
vim.current.buffer[:] = vim.current.buffer[:line_number] + [(" "*num_spaces)+line for line in lines] + vim.current.buffer[line_number:] | |
endpython | |
endfunction | |
"nmap <leader>r :execute "!/Applications/Skim.app/Contents/SharedSupport/displayline -r " . line('.') . " | |
" . expand("%:r") . ".pdf " . expand("%") | |
" | |
" function to find the test file name | |
" when working on the extractor | |
function! GetExtractorTestFilename() | |
" get the filename | |
let site_name = expand("%:t") | |
" get rid of the 'www' from the front of the extractor name | |
let site_name = substitute(site_name, "www", "", "g") | |
" get rid of the 'Extractor.py' from the end of the extractor name | |
let site_name = substitute(site_name, "Extractor.py", "", "g") | |
" return the path and name to the test file | |
return "Tests/test_" . site_name . ".py" | |
endfunction | |
nmap <leader>st :exe "vsplit " . GetExtractorTestFilename() | |
nmap <leader>rt :exe "!python " . GetExtractorTestFilename() | |
" write the empty doc string for a python function in docstring format | |
nmap <leader>wp :call WriteParams()<cr><down><down><end> | |
" increase the vertical size of the current window by 1.5 times. | |
nmap <leader>b :exe "vertical resize" (winwidth(0)*3/2) | |
" reload all snipmate snippets | |
nmap <leader>rr :call ReloadAllSnippets()<cr> | |
" break the function call line so that every parameter is on its own line | |
function! BreakParameters() | |
" move the start of the line and set a mark 'a' | |
normal ^ma | |
" get break the parameters onto their own line | |
normal f(a | |
jj | |
" replace the commas with linebreaks | |
:s/\v,[\s\n]?/, | |
/g | |
" reformat the paragraph | |
normal V`'= | |
" clean up by deleting the mark | |
:delmarks a | |
" turn off the highlighting | |
:nohl | |
endfunction | |
nmap <leader>bl :call BreakParameters() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment