Skip to content

Instantly share code, notes, and snippets.

@tonussi
Last active December 23, 2015 21:48
Show Gist options
  • Save tonussi/6698407 to your computer and use it in GitHub Desktop.
Save tonussi/6698407 to your computer and use it in GitHub Desktop.
.vimrc
" Pathogen
filetype off
call pathogen#incubate()
filetype plugin indent on
execute pathogen#infect()
" Set options regarding the undo history and undo tree depth
set undofile
set undoreload=10000
set undolevels=512
set modelines=0
" Don't try to highlight lines longer than 800 characters.
set synmaxcol=800
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=10
" Make Vim able to edit crontab files again.
set backupskip=/tmp/*,/private/tmp/*"
" Better Completion
set complete=.,w,b,u,t
set completeopt=longest,menuone,preview
" Save when losing focus
au FocusLost * :silent! wall
" Resize splits when the window is resized
au VimResized * :wincmd =
" Only show cursorline in the current window and in normal mode.
augroup cline
au!
au WinLeave,InsertEnter * set nocursorline
au WinEnter,InsertLeave * set cursorline
augroup END
" Only shown when not in insert mode so I don't go insane.
augroup trailing
au!
au InsertEnter * :set listchars+=tab:▸\ ,eol:¬,extends:❯,precedes:❮,trail:·
au InsertLeave * :set listchars-=tab:▸\ ,eol:¬,extends:❯,precedes:❮,trail:·
augroup END
" Wildmode options, for command-line tab completion
set wildmenu
set wildmode=list:longest
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*.luac " Lua byte code
set wildignore+=migrations " Django migrations
set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files
" Clojure/Leiningen
set wildignore+=classes
set wildignore+=lib
" Make sure Vim returns to the same line when you reopen a file.
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" Spacing and tabbing
set expandtab
set smarttab
set softtabstop=4
set shiftwidth=4
set tabstop=4
set wrap
set textwidth=80
set formatoptions=qrn1
" Get those annoying temporary files out of the working directory
set backup " enable backups
set undodir=~/.vim/tmp/undo/ " undo files
set backupdir=~/.vim/tmp/backup/ " backups
set directory=~/.vim/tmp/swap/ " swap files
let g:yankring_history_dir='~/.vim/tmp/yankring'
" Make those folders automatically if they don't already exist.
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
" Leader key remapping
let mapleader = ","
let maplocalleader = "\\"
map <leader><space> :noh<cr>
" Background, colorscheme, etc
syntax on
set background=dark
set t_Co=256
let g:badwolf_tabline = 2
let g:badwolf_html_link_underline = 0
colorscheme tomorrow-night
" Reload the colorscheme whenever we write the file.
augroup color_badwolf_dev
au!
au BufWritePost badwolf.vim color badwolf
augroup END
" Gundo
nnoremap <F5> :GundoToggle<CR>
let g:gundo_width = 60
let g:gundo_preview_height = 40
let g:gundo_right = 1
" <ESC> is really far away
imap <c-d> <ESC>
nnoremap <c-d> <ESC>
vnoremap <c-d> <ESC>
" Kill window
"nnoremap K :q<cr>
" Toggle line numbers
nnoremap <leader>n :setlocal number!<cr>
" Front and center
" Use :sus for the rare times I want to actually background Vim.
nnoremap <c-z> zMzvzz25<c-e>
vnoremap <c-z> <esc>zv`<ztgv
" Sort lines
nnoremap <leader>s vip:!sort<cr>
vnoremap <leader>s :!sort<cr>
" Tabs
nnoremap <leader>( :tabprev<cr>
nnoremap <leader>) :tabnext<cr>
nnoremap <leader>{ :tabnew<cr>
" Show contents of registers
nnoremap <leader>r :registers<cr>
" Clean trailing whitespace
nnoremap <leader>w mz:%s/\s\+$//<cr>:let @/=''<cr>`z
" Key mappings - clean whitespace
map <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Select entire buffer
nnoremap vaa ggvGg_
nnoremap Vaa ggVG
" HTML tag closing
inoremap <C-_> <Space><BS><Esc>:call InsertCloseTag()<cr>a
" Sudo to write
cnoremap w!! w !sudo tee % >/dev/null
" Easy filetype switching
nnoremap _md :set ft=markdown<CR>
nnoremap _hd :set ft=htmldjango<CR>
nnoremap _jt :set ft=htmljinja<CR>
nnoremap _js :set ft=javascript<CR>
nnoremap _cw :set ft=confluencewiki<CR>
nnoremap _pd :set ft=python.django<CR>
nnoremap _d :set ft=diff<CR>
" Insert Mode Completion
inoremap <c-f> <c-x><c-f>
inoremap <c-]> <c-x><c-]>
" Regex fixes
nnoremap / /\v
vnoremap / /\v
" Easy buffer navigation
noremap <C-h> <C-w>h
noremap <C-j> <C-w>j
noremap <C-k> <C-w>k
noremap <C-l> <C-w>l
noremap <leader>v :vsplit<cr><C-w>l
" List navigation
nnoremap <left> :cprev<cr>zvzz
nnoremap <right> :cnext<cr>zvzz
nnoremap <up> :lprev<cr>zvzz
nnoremap <down> :lnext<cr>zvzz
" }}}
" Haskell {{{
augroup ft_haskell
au!
au BufEnter *.hs compiler ghc
setlocal omnifunc=necoghc#omnifunc
let s:width = 80
function! HaskellModuleSection(...)
let name = 0 < a:0 ? a:1 : inputdialog("Section name: ")
return repeat('-', s:width) . "\n"
\ . "-- " . name . "\n"
\ . "\n"
endfunction
nmap <silent> --s "=HaskellModuleSection()<CR>gp
function! HaskellModuleHeader(...)
let name = 0 < a:0 ? a:1 : inputdialog("Module: ")
let note = 1 < a:0 ? a:2 : inputdialog("Note: ")
let description = 2 < a:0 ? a:3 : inputdialog("Describe this module: ")
return repeat('-', s:width) . "\n"
\ . "-- | \n"
\ . "-- Module : " . name . "\n"
\ . "-- Note : " . note . "\n"
\ . "-- \n"
\ . "-- " . description . "\n"
\ . "-- \n"
\ . repeat('-', s:width) . "\n"
\ . "\n"
endfunction
nmap <silent> --h "=HaskellModuleHeader()<CR>:0put =<CR>
augroup END
" }}}
" HTML, Django, Jinja, Dram {{{
let g:html_indent_tags = ['p', 'li']
augroup ft_html
au!
au BufNewFile,BufRead *.html setlocal filetype=htmldjango
au BufNewFile,BufRead *.dram setlocal filetype=htmldjango
au FileType html,jinja,htmldjango setlocal foldmethod=manual
" Use <localleader>f to fold the current tag.
au FileType html,jinja,htmldjango nnoremap <buffer> <localleader>f Vatzf
" Use <localleader>t to fold the current templatetag.
au FileType html,jinja,htmldjango nmap <buffer> <localleader>t viikojozf
" Indent tag
au FileType html,jinja,htmldjango nnoremap <buffer> <localleader>= Vat=
" Django tags
au FileType jinja,htmldjango inoremap <buffer> <c-t> {%<space><space>%}<left><left><left>
" Django variables
au FileType jinja,htmldjango inoremap <buffer> <c-b> {{<space><space>}}<left><left><left>
augroup END
" }}}
" Java {{{
augroup ft_java
au!
au FileType java setlocal foldmethod=marker
au FileType java setlocal foldmarker={,}
augroup END
" }}}
" Javascript {{{
augroup ft_javascript
au!
au FileType javascript setlocal foldmethod=marker
au FileType javascript setlocal foldmarker={,}
au FileType javascript call MakeSpacelessBufferIabbrev('clog', 'console.log();<left><left>')
" Make {<cr> insert a pair of brackets in such a way that the cursor is correctly
" positioned inside of them AND the following code doesn't get unfolded.
au Filetype javascript inoremap <buffer> {<cr> {}<left><cr><space><space><space><space>.<cr><esc>kA<bs>
augroup END
" }}}
" Lisp {{{
augroup ft_lisp
au!
au FileType lisp call TurnOnLispFolding()
" au FileType lisp nnoremap <buffer> <localleader>ee mz99[(va("ry:call Send_to_Tmux(@r)<cr>
" au FileType lisp nnoremap <buffer> <localleader>ee mz99[(:call SlimvEvalExp()<cr>`z
" Fix the eval mappings.
au FileType lisp nnoremap <buffer> <localleader>ef :call SlimvEvalExp()<cr>
au FileType lisp nnoremap <buffer> <localleader>ee :call SlimvEvalDefun()<cr>
au FileType lisp nnoremap <buffer> <localleader>tt mz0l99[(vab"ry:call Send_to_Tmux(@r)<cr>`z
au FileType lisp nnoremap <buffer> <localleader>tb mzggVG"ry:call Send_to_Tmux(@r)<cr>`z
" Indent top-level form.
au FileType lisp nmap <buffer> <localleader>= mz99[(v%='z
augroup END
" }}}
" Markdown {{{
augroup ft_markdown
au!
au Filetype markdown set spell
augroup END
" }}}
" Python {{{
augroup ft_python
au!
au FileType python setlocal define=^\s*\\(def\\\\|class\\)
au FileType man nnoremap <buffer> <cr> :q<cr>
" Jesus tapdancing Christ, built-in Python syntax, you couldn't let me
" override this in a normal way, could you?
au FileType python if exists("python_space_error_highlight") | unlet python_space_error_highlight | endif
au FileType python iabbrev <buffer> afo assert False, "Okay"
augroup END
" }}}
" QuickFix {{{
augroup ft_quickfix
au!
au Filetype qf setlocal colorcolumn=0 nolist nocursorline nowrap tw=0
augroup END
" }}}
" ReStructuredText {{{
augroup ft_rest
au!
au Filetype rst nnoremap <buffer> <localleader>1 yypVr=:redraw<cr>
au Filetype rst nnoremap <buffer> <localleader>2 yypVr-:redraw<cr>
au Filetype rst nnoremap <buffer> <localleader>3 yypVr~:redraw<cr>
au Filetype rst nnoremap <buffer> <localleader>4 yypVr`:redraw<cr>
augroup END
" }}}
" Ruby {{{
augroup ft_ruby
au!
au Filetype ruby setlocal foldmethod=syntax
augroup END
" }}}
" Scala {{{
augroup ft_scala
au!
au Filetype scala setlocal foldmethod=indent
augroup END
" }}}
" Vim {{{
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker
au FileType help setlocal textwidth=78
au BufWinEnter *.txt if &ft == 'help' | wincmd L | endif
augroup END
" }}}
" }}}
" Plugin settings --------------------------------------------------------- {{{
" Ack {{{
nnoremap <leader>a :Ack!<space>
let g:ackprg = 'ag --smart-case --nogroup --nocolor --column'
" }}}
" Autoclose {{{
nmap <Leader>x <Plug>ToggleAutoCloseMappings
" }}}
" Commentary {{{
nmap <leader>c <Plug>CommentaryLine
xmap <leader>c <Plug>Commentary
augroup plugin_commentary
au!
au FileType htmldjango setlocal commentstring={#\ %s\ #}
au FileType clojurescript setlocal commentstring=;\ %s
au FileType lisp setlocal commentstring=;\ %s
au FileType puppet setlocal commentstring=#\ %s
au FileType fish setlocal commentstring=#\ %s
augroup END
" }}}
" Ctrl-P {{{
let g:ctrlp_dont_split = 'NERD_tree_2'
let g:ctrlp_jump_to_buffer = 0
let g:ctrlp_working_path_mode = 0
let g:ctrlp_match_window_reversed = 1
let g:ctrlp_split_window = 0
let g:ctrlp_max_height = 20
let g:ctrlp_extensions = ['tag']
let g:ctrlp_map = '<leader>,'
nnoremap <leader>. :CtrlPTag<cr>
let g:ctrlp_prompt_mappings = {
\ 'PrtSelectMove("j")': ['<c-j>', '<down>', '<s-tab>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>', '<tab>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'ToggleFocus()': ['<c-tab>'],
\ }
let ctrlp_filter_greps = "".
\ "egrep -iv '\\.(" .
\ "jar|class|swp|swo|log|so|o|pyc|jpe?g|png|gif|mo|po" .
\ ")$' | " .
\ "egrep -v '^(\\./)?(" .
\ "deploy/|lib/|classes/|libs/|deploy/vendor/|.git/|.hg/|.svn/|.*migrations/|docs/build/" .
\ ")'"
let my_ctrlp_user_command = "" .
\ "find %s '(' -type f -or -type l ')' -maxdepth 15 -not -path '*/\\.*/*' | " .
\ ctrlp_filter_greps
let my_ctrlp_git_command = "" .
\ "cd %s && git ls-files --exclude-standard -co | " .
\ ctrlp_filter_greps
let my_ctrlp_ffind_command = "ffind --semi-restricted --dir %s --type e -B -f"
let g:ctrlp_user_command = ['.git/', my_ctrlp_ffind_command, my_ctrlp_ffind_command]
" }}}
" Gundo {{{
nnoremap <F5> :GundoToggle<CR>
let g:gundo_debug = 1
let g:gundo_preview_bottom = 1
let g:gundo_tree_statusline = "Gundo"
let g:gundo_preview_statusline = "Gundo Preview"
" }}}
" Haskellmode {{{
let g:haddock_browser = "open"
let g:haddock_browser_callformat = "%s %s"
let g:ghc = "/usr/local/bin/ghc"
" }}}
" HTML5 {{{
let g:event_handler_attributes_complete = 0
let g:rdfa_attributes_complete = 0
let g:microdata_attributes_complete = 0
let g:atia_attributes_complete = 0
" }}}
" Linediff {{{
vnoremap <leader>l :Linediff<cr>
nnoremap <leader>L :LinediffReset<cr>
" }}}
" Lisp (built-in) {{{
"let g:lisp_rainbow = 1
" }}}
" NERD Tree {{{
noremap <F2> :NERDTreeToggle<cr>
inoremap <F2> <esc>:NERDTreeToggle<cr>
augroup ps_nerdtree
au!
au Filetype nerdtree setlocal nolist
" au Filetype nerdtree nnoremap <buffer> K :q<cr>
augroup END
let NERDTreeHighlightCursorline = 1
let NERDTreeIgnore = ['.vim$', '\~$', '.*\.pyc$', 'pip-log\.txt$', 'whoosh_index',
\ 'xapian_index', '.*.pid', 'monitor.py', '.*-fixtures-.*.json',
\ '.*\.o$', 'db.db', 'tags.bak', '.*\.pdf$', '.*\.mid$',
\ '.*\.midi$']
let NERDTreeMinimalUI = 1
let NERDTreeDirArrows = 1
let NERDChristmasTree = 1
let NERDTreeChDirMode = 2
let NERDTreeMapJumpFirstChild = 'gK'
" }}}
" Powerline {{{
let g:Powerline_symbols = 'compatible'
let g:Powerline_cache_enabled = 1
let g:Powerline_colorscheme = 'badwolf'
" }}}
" Python-Mode {{{
let g:pymode_doc = 1
let g:pymode_doc_key = 'M'
let g:pydoc = 'pydoc'
let g:pymode_syntax = 1
let g:pymode_syntax_all = 0
let g:pymode_syntax_builtin_objs = 1
let g:pymode_syntax_print_as_function = 0
let g:pymode_syntax_space_errors = 0
let g:pymode_run = 0
let g:pymode_lint = 0
let g:pymode_breakpoint = 0
let g:pymode_utils_whitespaces = 0
let g:pymode_virtualenv = 0
let g:pymode_folding = 0
let g:pymode_options_indent = 0
let g:pymode_options_fold = 0
let g:pymode_options_other = 0
let g:pymode_options = 0
let g:pymode_rope = 1
let g:pymode_rope_global_prefix = "<localleader>R"
let g:pymode_rope_local_prefix = "<localleader>r"
let g:pymode_rope_auto_project = 1
let g:pymode_rope_enable_autoimport = 0
let g:pymode_rope_autoimport_generate = 1
let g:pymode_rope_autoimport_underlineds = 0
let g:pymode_rope_codeassist_maxfixes = 10
let g:pymode_rope_sorted_completions = 1
let g:pymode_rope_extended_complete = 1
let g:pymode_rope_autoimport_modules = ["os", "shutil", "datetime"]
let g:pymode_rope_confirm_saving = 1
let g:pymode_rope_vim_completion = 1
let g:pymode_rope_guess_project = 1
let g:pymode_rope_goto_def_newwin = 0
let g:pymode_rope_always_show_complete_menu = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment