Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jast

jast/.vimrc Secret

Last active March 8, 2017 14:55
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 jast/e3930169cdee4bb972dd141efd13b3ff to your computer and use it in GitHub Desktop.
Save jast/e3930169cdee4bb972dd141efd13b3ff to your computer and use it in GitHub Desktop.
set mouse=a
set enc=utf-8 fenc=utf-8
set background=dark
" break hardlinks
set backupcopy=breakhardlink,auto
set colorcolumn=+1
" graphical confirmations for things like unsaved buffers
set confirm
set diffopt+=vertical
" put swapfiles there
set directory=~/.vim/swap,.
set undodir=~/.vim/undo,.
set undofile
set ff=unix
" don't ever accidentally work in DOS mode
set ffs=unix
" auto formatting
set formatoptions=tcroqn
set guifont=Bitstream\ Vera\ Sans\ Mono\ 9
" needed for using buffers instead of tabs
set hidden
set hlsearch
set modeline
set modelines=5
" context menu
set mousemodel=popup_setpos
set nowrapscan
set pastetoggle=<F2>
set scrolloff=3
" display linebreak
set showbreak=↪
" highlight matching braces
set showmatch
set noshowmode
set textwidth=78
" <file> [+][RO] [Preview] [<filetype>] - GVIM
set titlestring=%f%(\ %m%r%)%(\ %w%)%(\ %y%)\ -\ GVIM
set wildignore+=*/node_modules/*,*/.git/*,*.min.js,*.min.css
set wildmenu
set wildmode=longest:full,full
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffers_label = 'b'
let g:airline#extensions#tabline#buffer_idx_mode = 1
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:ycm_add_preview_to_completeopt=1
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_rust_src_path=$HOME . "/download/rustc-1.8.0/src"
let g:UltiSnipsExpandTrigger="<c-j>"
let g:UltiSnipsEditSplit="context"
let jshint2_read=1
let jshint2_save=1
if executable('ag')
let g:ackprg = 'ag'
let g:CtrlSpaceGlobCommand = 'ag -l --nocolor -g ""'
endif
let g:CtrlSpaceUseTabline = 0
let g:CtrlSpaceSaveWorkspaceOnExit = 1
let g:CtrlSpaceSaveWorkspaceOnSwitch = 1
let g:easy_align_delimiters = {
\ '>': { 'pattern': '>>\|=>\|>' },
\ '/': { 'pattern': '//\+\|/\*\|\*/',
\ 'delimiter_align': 'l',
\ 'ignore_groups': ['!Comment'] }
\ }
let NERDTreeHighlightCursorline=1
let NERDTreeIgnore=['\~$', '^\.git$[[dir]]', '^node_modules$[[dir]]']
let NERDTreeHijackNetrw=0
let NERDTreeMinimalUI=1
let NERDTreeMouseMode=2
let NERDTreeQuitOnOpen=1
if filereadable($HOME . "/.local/vimrc-early")
source $HOME . "/.local/vimrc-early"
endif
let g:fzf_command_prefix = 'Fzf'
call plug#begin('~/.vim/bundle')
Plug 'mattn/webapi-vim'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-repeat'
Plug 'vim-ctrlspace/vim-ctrlspace'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-dispatch'
Plug 'mhinz/vim-signify'
Plug 'junegunn/indentLine'
Plug 'vim-airline/vim-airline'
Plug 'benmills/vimux'
Plug 'jtdowney/vimux-cargo'
Plug 'junegunn/fzf', { 'dir': '~/.config/fzf', 'do': './install --bin' } |
\ Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-eunuch'
Plug 'majutsushi/tagbar'
Plug 'geoffharcourt/vim-matchit'
Plug 'easymotion/vim-easymotion'
Plug 'tpope/vim-sleuth'
Plug 'valloric/youcompleteme'
Plug 'sirver/ultisnips' | Plug 'honza/vim-snippets'
Plug 'junegunn/vim-easy-align'
Plug 'tpope/vim-surround'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'mattn/emmet-vim'
Plug 'mattn/gist-vim'
Plug 'elzr/vim-json'
Plug 'othree/html5.vim'
Plug 'hail2u/vim-css3-syntax'
Plug 'ap/vim-css-color'
Plug 'pangloss/vim-javascript'
Plug 'shutnik/jshint2.vim'
Plug 'vim-perl/vim-perl'
Plug 'rust-lang/rust.vim'
Plug 'mileszs/ack.vim'
Plug 'jeetsukumaran/vim-indentwise'
Plug 'kchmck/vim-coffee-script'
Plug 'nvie/vim-flake8'
call plug#end()
syn on
" bindings for plugins
nmap <F8> :TagbarOpen fjc<CR>
nmap <F11> :NERDTreeToggle<CR>
nmap <silent> - :let NERDTreeQuitOnOpen=1<CR>:NERDTreeFind<CR>
nmap <silent> \- :let NERDTreeQuitOnOpen=0<CR>:NERDTreeFind<CR>
nmap <F5> :Dispatch<CR>
nmap <silent> <C-P> :FZF<CR>
nmap <silent> _g :FzfGFiles<CR>
nmap <silent> _G :FzfGFiles?<CR>
nmap <silent> _B :FzfBuffers<CR>
nmap <silent> _c :FzfBCommits<CR>
nmap <silent> _C :FzfCommits<CR>
nmap <silent> _r :FzfHistory<CR>
nmap <silent> _l :FzfBLines<CR>
nmap <silent> _L :FzfLines<CR>
nmap <silent> _t :FzfBTags<CR>
nmap <silent> _T :FzfTags<CR>
nmap <silent> _s :FzfSnippets<CR>
nmap <silent> _? :FzfHelptags<CR>
nmap <silent> _/ :FzfHistory/<CR>
nmap <silent> _: :FzfHistory:
vmap <Enter> <Plug>(EasyAlign)
vmap \a <Plug>(EasyAlign)
nmap \a <Plug>(EasyAlign)
nmap ,gg :YcmCompleter GoTo<CR>
nmap ,gr :YcmCompleter GoToReferences<CR>
nmap ,gi :YcmCompleter GoToImplementationElseDeclaration<CR>
nmap ,gt :YcmCompleter GetType<CR>
nmap ,gp :YcmCompleter GetParent<CR>
nmap ,gd :YcmCompleter GetDoc<CR>
nmap ,gR :YcmCompleter RefactorRename<CR>
" buffer switching {{{
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
nmap _a :Ack!<Space>
imap <C-\>1 <C-O><Plug>AirlineSelectTab1
imap <C-\>2 <C-O><Plug>AirlineSelectTab2
imap <C-\>3 <C-O><Plug>AirlineSelectTab3
imap <C-\>4 <C-O><Plug>AirlineSelectTab4
imap <C-\>5 <C-O><Plug>AirlineSelectTab5
imap <C-\>6 <C-O><Plug>AirlineSelectTab6
imap <C-\>7 <C-O><Plug>AirlineSelectTab7
imap <C-\>8 <C-O><Plug>AirlineSelectTab8
imap <C-\>9 <C-O><Plug>AirlineSelectTab9
function! s:SetupBufferSwitch()
if exists(':CtrlSpace') == 2
nmap <silent> <leader>k :CtrlSpace dq<CR>
nmap <silent> <leader>, :CtrlSpaceGoUp<CR>
nmap <silent> <leader>. :CtrlSpaceGoDown<CR>
nmap <silent> <leader>< :CtrlSpace lk<Tab><CR>
nmap <silent> <leader>> :CtrlSpace lj<Tab><CR>
imap <silent> <C-\>, <C-O>:<C-U>CtrlSpaceGoUp<CR>
imap <silent> <C-\>. <C-O>:<C-U>CtrlSpaceGoDown<CR>
imap <silent> <C-\>< <C-O>:<C-U>CtrlSpace lk<Tab><CR>
imap <silent> <C-\>> <C-O>:<C-U>CtrlSpace lj<Tab><CR>
nmap <silent> ,, :CtrlSpace<CR>
else
nmap <leader>k :bd<CR>
nmap <leader>, <Plug>AirlineSelectPrevTab
nmap <leader>. <Plug>AirlineSelectNextTab
imap <C-\>, <C-O><Plug>AirlineSelectPrevTab
imap <C-\>. <C-O><Plug>AirlineSelectNextTab
endif
endfunction
au VimEnter * call s:SetupBufferSwitch()
" }}}
" bookmark editor/quick create
if !exists('g:bookmarkfile')
let g:bookmarkfile=$HOME .'/.NERDTreeBookmarks'
endif
" {{{
function! Bookmark_Go(r)
let l:r = substitute(a:r, '\v^\s+|\s+$', '', 'g')
let l:r = matchlist(l:r, '\v^(\S+)\s+(\S+)$')
if len(l:r) > 2
let l:dir = l:r[2]
elseif len(l:r)
let l:dir = l:r[1]
else
return
endif
execute 'cd '. fnameescape(l:dir)
echomsg 'cd: '. l:dir
endfunction
function! s:AddBookmark()
let l:curdir = expand('%:p:h')
execute 'edit '. fnameescape(g:bookmarkfile)
execute 'normal GO '. l:curdir ."\<Esc>0"
inoremap <buffer> <C-Y> <Esc>:up<CR>:bd<CR>
noremap <buffer> <C-Y> :<C-U>up<CR>:bd<CR>
inoremap <buffer> <C-N> <Esc>:bd!<CR>
noremap <buffer> <C-N> :bd!<CR>
setl cursorline
startinsert
endfunction
nmap <silent> _b :call fzf#run({
\ 'source': filter(readfile(g:bookmarkfile), 'v:val =~ "\\S"'),
\ 'sink': function('Bookmark_Go'), 'options': '-m', 'down': '40%'})<CR>
nmap ,b :call <sid>AddBookmark()<CR>
" }}}
nmap ,/ :nohlsearch<CR>
" supercharged C-L (from mhinz)
nnoremap <leader>l :noh<CR>:diffu<CR>:syntax sync fromstart<CR><C-L>
" quick-edit macro/register
nnoremap ,m :<c-r><c-r>='let @'. v:register .' = '. string(getreg(v:register))<cr><c-f><left>
map ,vo :e ~/.vimrc<CR>
" eval current line as vim command
map ,ve ^y$:<C-R>"<CR>
map _2d :difft<CR><C-W>w:difft<CR><C-W>W
" screen line movements
noremap <Up> gk
noremap <Down> gj
" nobody likes exidents
noremap Q <nop>
cmap w!! w !sudo tee % >/dev/null
" move lines
nnoremap \<Up> :<C-U>execute 'move -1-'. v:count1<CR>
nnoremap \<Down> :<C-U>execute 'move +'. v:count1<CR>
vnoremap \<Up> :<C-U>execute 'move -1-'. v:count1<CR>gv
vnoremap \<Down> :<C-U>execute 'move +'. v:count1<CR>gv
" listchars \o/
set list
set listchars=tab:»¬,trail:·
highlight SpecialKey ctermfg=3 guifg=#c0c0c0
" folding options
set foldmethod=marker
set foldminlines=3
set foldopen=block,hor,insert,jump,mark,percent,quickfix,search,tag,undo
" textwidth toggling (turn line wrapping on/off)
function! ToggleTextwidth()
if &l:tw == 78
let &l:tw = 0
else
let &l:tw = 78
endif
endfunction
map <F9> :call ToggleTextwidth()<CR>
imap <F9> <C-O>:call ToggleTextwidth()<CR>
" insert completion
set complete=.,w,b,u,t
" we want more include files for completion
set path=.,..,/usr/include,/usr/include/**,/usr/local/include,/usr/local/include/**,
set tags+=./tags;,/usr/local/include/tags
au BufRead,BufNewFile /etc/** set tw=0
au filetype make setl ts=8 sts=8 sw=8 noet
au filetype yaml setl ts=2 sts=2 sw=2 et
" vim-css-color workaround for SCSS
au! filetype scss syntax cluster sassCssAttributes add=@cssColors
au filetype coffee nmap <buffer> <silent> <F7> :CoffeeLint <bar> cwindow<CR>
au filetype python setl ts=4 sts=4 sw=4 et
au bufnewfile,bufread *.rss setf xml
au bufnewfile,bufread *.md setl ft=markdown
" Foswiki
au bufnewfile,bufread *.tmpl setl ft=html
" regen tags {{{
function! s:tags_regen(...)
if exists('b:git_dir')
let l:tree = b:git_dir[0:-6]
else
let l:tree = expand('%:p:h')
endif
execute 'setl tag+='. fnameescape(l:tree) .'/tags'
let l:cmd = ['ctags', '-f', l:tree .'/tags']
if a:0
let l:arg = substitute(expand('%:p'), "'", "'\\''", 'g')
call add(l:cmd, '-a')
else
let l:arg = l:tree
endif
call extend(l:cmd, map(split(&l:wildignore, ','), '"--exclude=".v:val'))
call extend(l:cmd, ['-R', '--tag-relative', l:arg])
silent botright 10sp tags_regen\ results
setl buftype=nofile noswapfile bufhidden=wipe nobuflisted
wincmd p
if exists('*job_start')
let s:tags_regen_job = job_start(l:cmd, {'err_io': 'buffer', 'err_name': 'tags_regen results', 'exit_cb': function('s:tags_regen_exit')})
else
call system(l:cmd)
endif
endfunction
function! s:tags_regen_activate()
execute 'setl tag+='. fnameescape(b:git_dir[0:-6]) .'/tags'
endfunction
function! s:tags_regen_abort()
if exists('s:tags_regen_job')
call job_stop(s:tags_regen_job)
unlet s:tags_regen_job
else
echomsg "No ctags job running"
endif
endfunction
function! s:tags_regen_exit(j, code)
if a:code ==# 0
" close temporary window, if it's still there
let l:curwin = win_getid()
for tabnr in range(1, tabpagenr('$'))
for winnr in range(1, tabpagewinnr(tabnr, '$'))
let l:winid = win_getid(winnr, tabnr)
if bufname(winbufnr(l:winid)) == 'tags_regen results'
call win_gotoid(l:winid)
bd!
call win_gotoid(l:curwin)
endif
endfor
endfor
else
echohl errormsg
echomsg "Ctags run terminated with error status"
echohl normal
buf 'tags_regen results'
endif
unlet s:tags_regen_job
endfunction
"au BufWritePost * call <sid>tags_regen(1)
"au User Fugitive call <sid>tags_regen_activate()
command! Ctags :call <sid>tags_regen()
command! CtagsAbort :call <sid>tags_regen_abort()
" }}}
if filereadable($HOME . "/.local/vimrc")
source $HOME . "/.local/vimrc"
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment