Skip to content

Instantly share code, notes, and snippets.

@offlinehacker
Created February 22, 2015 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offlinehacker/d0bc0805bc86f4cbdfd4 to your computer and use it in GitHub Desktop.
Save offlinehacker/d0bc0805bc86f4cbdfd4 to your computer and use it in GitHub Desktop.
My vimrc file
" VAM {{{
" Set leader keys
let mapleader=","
let maplocalleader = ","
" put this line first in ~/.vimrc
set nocompatible | filetype indent plugin on | syn on
fun! SetupVAM()
let c = get(g:, 'vim_addon_manager', {})
let g:vim_addon_manager = c
let c.plugin_root_dir = expand('$HOME', 1) . '/.vim/vim-addons'
" most used options you may want to use:
" let c.log_to_buf = 1
" let c.auto_install = 0
let &rtp.=(empty(&rtp)?'':',').c.plugin_root_dir.'/vim-addon-manager'
if !isdirectory(c.plugin_root_dir.'/vim-addon-manager/autoload')
execute '!git clone --depth=1 git://github.com/MarcWeber/vim-addon-manager '
\ shellescape(c.plugin_root_dir.'/vim-addon-manager', 1)
endif
call vam#ActivateAddons([], {'auto_install' : 0})
endfun
call SetupVAM()
VAMActivate matchit.zip vim-addon-commenting
" use <c-x><c-p> to complete plugin names
" }}}
" Addons config {{{
" Airlineis
let g:airline_theme = 'molokai'
let g:airline_powerline_fonts = 1
" solarized
let g:solarized_termcolors = 256
let g:solarized_hitrail = 0
let g:solarized_diffmode = "high"
" minibufexplorer
let g:miniBufExplorerMoreThanOne = 1 " only one mini buf explorer
let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
let g:miniBufExplUseSingleClick = 1
let g:miniBufExplBRSplit = 0
" Syntastic
let g:syntastic_check_on_open=1
let g:syntastic_auto_jump=0
let g:syntastic_stl_format = '[%E{%e Errors}%B{, }%W{%w Warnings}]'
let g:syntastic_html_checkers = ['polylint', 'jshint']
" fugitive
map <LEADER>gg :Git
map <LEADER>gr :Gremove
map <LEADER>gm :Gmove
map <LEADER>gs :Gstatus<CR>
map <LEADER>gd :Gdiff<CR>
" tagbar
nmap <LEADER>tb :TagbarToggle<CR>
" detect indent
autocmd BufReadPost * :DetectIndent
let g:detectindent_preferred_expandtab = 1
let g:detectindent_preferred_indent = 2
" python mode
let g:pymod_run = 1
let g:pymode_rope = 0 " Rope can be slow, turn it off by default
let g:pymode_doc = 0
let g:pymode_lint_on_write = 1
let g:pymode_lint_checkers = ["pyflakes", "pep8"]
let g:pymode_lint_write = 0 " Auto check on save
let g:pymode_breakpoint = 1 " Enable breakpoints plugin
let g:pymode_breakpoint_key = '<leader>b'
let g:pymode_syntax = 1 " syntax highlighting
let g:pymode_syntax_all = 1
let g:pymode_syntax_indent_errors = g:pymode_syntax_all
let g:pymode_syntax_space_errors = g:pymode_syntax_all
let g:pymode_folding = 0 " Don't autofold code
let g:pymode_indent = 0
let g:pymode_run = 1
let g:pymode_run_bind = '<leader>r'
let g:pymode_lint = 1
" youcompleteme
let g:ycm_autoclose_preview_window_after_insertion = 1
" vexplore
let g:netrw_browse_split = 4
let g:netrw_altv = 1
" ultisnips
function! g:UltiSnips_Complete()
call UltiSnips#ExpandSnippet()
if g:ulti_expand_res == 0
if pumvisible()
return "\<C-n>"
else
call UltiSnips#JumpForwards()
if g:ulti_jump_forwards_res == 0
return "\<TAB>"
endif
endif
endif
return ""
endfunction
au BufEnter * exec "inoremap <silent> " . g:UltiSnipsExpandTrigger . " <C-R>=g:UltiSnips_Complete()<cr>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsListSnippets="<c-e>"
" this mapping Enter key to <C-y> to chose the current highlight item
" and close the selection list, same as other IDEs.
" CONFLICT with some plugins like tpope/Endwise
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" tern
let g:tern#command = '~/.nix-profile/bin/tern'
" debug
function! ToggleVerbose()
if !&verbose
set verbosefile=~/.logs/vim/verbose.log
set verbose=15
else
set verbose=0
set verbosefile=
endif
endfunction
" nerdcommenter
let g:NERDCustomDelimiters = {'nix': { 'left': '#' }}
" sparkup
let g:sparkupExecuteMapping = '<c-x>'
" }}}
" Addons {{{
let scripts = []
" visual
call add(scripts, {'name': 'vim-airline', 'tag': 'visual'}) " statusline
call add(scripts, {'name': 'Solarized', 'tag': 'visual'})
call add(scripts, {'name': 'github:fholgado/minibufexpl.vim', 'tag': 'visual'})
" development
call add(scripts, {'name': 'Syntastic', 'tag': 'development'}) " syntax higlighter
call add(scripts, {'name': 'fugitive', 'tag': 'development'}) " git wrapper
call add(scripts, {'name': 'Tagbar', 'tag': 'development'}) " show ctags
call add(scripts, {'name': 'vim-signify', 'tag': 'development'}) "show diff
call add(scripts, {'name': 'DetectIndent', 'tag': 'development'})
call add(scripts, {'name': 'github:scrooloose/nerdcommenter', 'tag': 'development'})
call add(scripts, {'name': 'gitv', 'tag': 'development'})
call add(scripts, {'name': 'Tabular', 'tag': 'development'})
call add(scripts, {'name': 'delimitMate', 'tag': 'development'})
call add(scripts, {'name': 'YouCompleteMe', 'tag': 'development'})
call add(scripts, {'name': 'UltiSnips', 'tag': 'development'})
call add(scripts, {'name': 'vim-snippets', 'tag': 'development'})
call add(scripts, {'name': 'Command-T', 'tag': 'development'})
call add(scripts, {'name': 'vixclip -sel clip <xclip -sel clip <xclip -sel clip <m-multiple-cursors', 'tag': 'development'})
" html
call add(scripts, {'name': 'github:tristen/vim-sparkup', 'ft_regex': 'html'})
call add(scripts, {'name': 'html5', 'ft_regex': 'html'})
call add(scripts, {'name': 'github:bendavis78/vim-polymer', 'ft_regex': 'html'})
" javascript
call add(scripts, {'name': 'vim-javascript', 'filename_regex': '\.js$'}) " indent + syntax
"call add(scripts, {'name': 'github:marijnh/tern_for_vim', 'ft_regex': 'javascript$'})
call add(scripts, {'name': 'github:jamescarr/snipmate-nodejs', 'ft_regex': 'javascript'})
" jsx
call add(scripts, {'name': 'github:mxw/vim-jsx', 'filename_regex': '\.jsx$'})
call add(scripts, {'name': 'vim-javascript', 'filename_regex': '\.jsx$'})
" cofeescript
call add(scripts, {'name': 'github:kchmck/vim-coffee-script', 'filename_regex': '\.coffee$'})
call add(scripts, {'name': 'github:noc7c9/vim-iced-coffee-script', 'ft_regex': 'coffeescript'})
" css
call add(scripts, {'name': 'vim-less', 'filename_regex': '\.less$'})
call add(scripts, {'name': 'css_color@skammer', 'ft_regex': 'css'})
call add(scripts, {'name': 'vim-css3-syntax', 'ft_regex': 'css'})
" python
call add(scripts, {'name': 'Python-mode-klen', 'filename_regex': '\.py$'})
" nix
call add(scripts, {'name': 'vim-addon-nix', 'filename_regex': '\.nix$'})
" golang
call add(scripts, {'name': 'github:fatih/vim-go','filename_regex': '\.go$'})
" activate visual and development addons
call vam#Scripts(scripts, {'tag_regex': 'visual'})
call vam#Scripts([], {'tag_regex': 'development'})
call togglebg#map("<LEADER>C")
" }}}
" General options {{{
set nocompatible
set encoding=utf-8
set modelines=0
set autoindent
set showmode
set showcmd
set hidden
set cursorline
set ttyfast
set ruler
set backspace=indent,eol,start
set number
set norelativenumber
set laststatus=2
set history=1000
set undofile
set undoreload=10000
set cpoptions+=J
set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮
set lazyredraw
set matchtime=3
set showbreak=↪
set splitbelow
set splitright
set fillchars=diff:⣿
set ttimeout
set notimeout
set nottimeout
set autowrite
set shiftround
set autoread
set title
set linebreak
set completeopt=longest,menuone,preview " Better Completion
set pastetoggle=<F2> " Toggle paste
set sessionoptions=buffers " Only save buffers to session
" Make Vim able to edit crontab files again.
set backupskip=/tmp/*,/private/tmp/*"
" Resize splits when the window is resized
au VimResized * exe "normal! \<c-w>="
" set all window splits equal
set equalalways
" enable mouse
set mouse=a
set ttymouse=xterm2
behave xterm
" }}}
" Wildmenu 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
" }}}
" Line Return {{{
" Make sure Vim returns to the same line when you reopen a file.
" Thanks, Amit
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" }}}
" Tabs, spaces, wrapping {{{
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set wrap
set textwidth=79
set formatoptions=qrn1
set colorcolumn=+1
" }}}
" Backups {{{
call system("mkdir -p ~/.vim/tmp/{backup,undo,swap}")
set backupdir=~/.vim/tmp/backup// " backups
set backupskip=/tmp/*,/private/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*¬
set undodir=~/.vim/tmp/undo// " undo files
set directory=~/.vim/tmp/swap// " swap files
set backup " enable backups
set noswapfile " It's 2012, Vim.
" }}}
" Color scheme {{{
syntax on
filetype on
filetype plugin on
filetype plugin indent on
colorscheme solarized
set background=dark
" Highlight VCS conflict markers
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
" Highlight lines that are longer then 80
match ErrorMsg '\%>80v.+'
" }}}
" Navigation {{{
" It's 2011.
noremap j gj
noremap k gk
" Easy buffer navigation
noremap <C-j> <C-w>h
noremap <C-k> <C-w>j
noremap <C-i> <C-w>k
noremap <C-l> <C-w>l
noremap <leader>v <C-w>v
noremap <C-o> :bnext<CR>
" }}}
" Folding {{{
set foldlevelstart=0
" Space to toggle folds.
nnoremap <Space> za
vnoremap <Space> za
" Double click to toggle folds
:map <2-LeftMouse> za
" Save and load folds
au BufWinLeave * silent! mkview
au BufWinEnter * silent! loadview
" Make zz recursively open whatever top level fold we're in, no matter where the
" cursor happens to be.
nnoremap zz zCzO
" Use ,z to "focus" the current fold.
nnoremap <leader>f zMzvzz
function! MyFoldText()
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' '
endfunction
set foldtext=MyFoldText()
" }}}
" Visual Mode */# from Scrooloose {{{
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
endfunction
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
" }}}
" Various filetype-specific stuff ----------------------------------------- {{{
" C {{{
augroup ft_c
au!
au FileType c setlocal foldmethod=syntax
augroup END
" }}}
" CSS and LessCSS {{{
augroup ft_css
au!
au Filetype less,css setlocal foldmethod=marker
au Filetype less,css setlocal ts=2 sts=2 sw=2
au Filetype less,css setlocal foldmarker={,}
au Filetype less,css setlocal omnifunc=csscomplete#CompleteCSS
au Filetype less,css setlocal iskeyword+=-
" Use <leader>S to sort properties. Turns this:
"
" p {
" width: 200px;
" height: 100px;
" background: red;
"
" ...
" }
"
" into this:
"
" p {
" background: red;
" height: 100px;
" width: 200px;
"
" ...
" }
au BufNewFile,BufRead *.less,*.css nnoremap <buffer> <localleader>S ?{<CR>jV/\v^\s*\}?$<CR>k:sort<CR>:noh<CR>
" 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 BufNewFile,BufRead *.less,*.css inoremap <buffer> {<cr> {}<left><cr><space><space><space><space>.<cr><esc>kA<bs>
augroup END
" }}}
" HTML {{{
augroup ft_html
au!
au BufNewFile,BufRead *.html *.pt *.zcml setlocal filetype=html
au FileType html setlocal foldmethod=manual
au Filetype html setlocal ts=2 sts=2 sw=2
au FileType html nnoremap <buffer> <localleader>f Vatzf " Use <localleader>f to fold the current tag.
" Use Shift-Return to turn this:
" <tag>|</tag>
"
" into this:
" <tag>
" |
" </tag>
au FileType html nnoremap <buffer> <s-cr> vit<esc>a<cr><esc>vito<esc>i<cr><esc>
augroup END
" }}}
" Javascript {{{
augroup ft_javascript
au!
au FileType javascript setlocal foldmethod=marker
au FileType javascript setlocal foldmarker={,}
au Filetype javascript setlocal ts=2 sts=2 sw=2
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
augroup END
" }}}
" CoffeeScript {{{
augroup ft_coffeescript
au!
au FileType coffeescript setlocal foldmethod=indent
augroup END
" }}}
" Lisp {{{
augroup ft_lisp
au!
au FileType lisp call TurnOnLispFolding()
augroup END
" }}}
" Markdown {{{
augroup ft_markdown
au!
au BufNewFile,BufRead *.m*down setlocal filetype=markdown
" Use <localleader>1/2/3 to add headings.
au Filetype markdown nnoremap <buffer> <localleader>1 yypVr=
au Filetype markdown nnoremap <buffer> <localleader>2 yypVr-
au Filetype markdown nnoremap <buffer> <localleader>3 I### <ESC>
augroup END
" }}}
" OrgMode {{{
augroup ft_org
au!
au Filetype org nmap <buffer> Q vahjgq
augroup END
" }}}
" Python {{{
augroup ft_python
au!
au FileType python setlocal define=^\s*\\(def\\\\|class\\)
augroup END
" }}}
" ReStructuredText {{{
augroup ft_rest
au!
au FileType rst nnoremap <buffer> <localleader>1 yypVr=
au FileType rst nnoremap <buffer> <localleader>2 yypVr-
au FileType rst nnoremap <buffer> <localleader>3 yypVr~
au FileType rst nnoremap <buffer> <localleader>4 yypVr`
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
" }}}
" nix {{{
" }}}
" }}}
" Convenience mappings ----------------------------------------------------- {{{
nmap <LEADER>L :set list!<CR>
map <SILENT> <LEADER>S :set spell!<CR>
map <SILENT> <LEADER>H :set hlsearch!<CR>¬
map <SILENT> <LEADER>N :set number!<CR>
" Clean whitespace
map <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Change case
nnoremap <C-u> gUiw
inoremap <C-u> <esc>gUiwea
" Emacs bindings in command line mode
cnoremap <c-a> <home>
cnoremap <c-e> <end>
" Formatting, TextMate-style
nnoremap <leader>w gqip
" Align text
nnoremap <leader>Al :left<cr>
nnoremap <leader>Ac :center<cr>
nnoremap <leader>Ar :right<cr>
" Less chording
nnoremap ; :
" Faster Esc
inoremap jj <esc>
" Marks and Quotes
noremap ' `
noremap æ '
noremap ` <C-^>
" Calculator
inoremap <C-B> <C-O>yiW<End>=<C-R>=<C-R>0<CR>
" Show syntax highlighting groups for word under cursor
nmap <C-S-P> :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" Remove trailing spaces
autocmd FileType * autocmd BufWritePre <buffer> :%s/\s\+$//e
" Leave in visual mode after indent
vnoremap > >gv
vnoremap < <gv
" }}}
" Usefull snippers {{{
" Select all
nmap <C-a> ggVG
" Strip the newline from the end of a string
function! Chomp(str)
return substitute(a:str, '\n$', '', '')
endfunction
" Find a file and pass it to cmd
function! DmenuOpen(cmd)
let fname = Chomp(system("git ls-files | dmenu -i -l 20 -p " . a:cmd))
if empty(fname)
return
endif
execute a:cmd . " " . fname
endfunction
map <c-e> :call DmenuOpen("e")<cr>
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment