Skip to content

Instantly share code, notes, and snippets.

@aminnj
Created January 21, 2018 23:26
Show Gist options
  • Save aminnj/5e76adf47a27ca40f92d2f5eda253fa5 to your computer and use it in GitHub Desktop.
Save aminnj/5e76adf47a27ca40f92d2f5eda253fa5 to your computer and use it in GitHub Desktop.
.vimrc
let g:pathogen_disabled = [] " disable certain pathogen plugins ... useful to debug
" load plugins before screwing with settings
" https://github.com/tpope/vim-commentary
" https://github.com/tpope/vim-surround
" https://github.com/tpope/vim-fugitive
" https://github.com/scrooloose/nerdtree
" https://github.com/haya14busa/incsearch.vim
" https://github.com/haya14busa/incsearch-fuzzy.vim # z/ to fuzzy search
" https://github.com/tpope/vim-jdaddy # gqaj to pretty-print json under cursor
" https://github.com/godlygeek/tabular
" https://github.com/itchyny/lightline.vim
" https://github.com/ervandew/supertab
" https://github.com/w0rp/ale
" https://github.com/majutsushi/tagbar
" https://github.com/machakann/vim-swap # gs, g< or g> on args to switch them
" https://github.com/aminnj/vim-lazytools
execute pathogen#infect()
syntax on
" zR to open all folds
" zM to close them again
" ====== One and only theme {{{
color wombat256mod
set background=light
" Tweak to have more vivid error/warning/todo colors
" especially for Ale
hi SpellBad ctermfg=253 ctermbg=160 cterm=none
hi Error ctermfg=253 ctermbg=160 cterm=none
hi SpellCap ctermfg=253 ctermbg=220 cterm=none
hi Todo ctermfg=235 ctermbg=220 cterm=none
" }}}
" ====== Settings {{{
" fix backspace in tmux->ssh->vim
if &term == "screen"
set t_kb=
endif
if exists('$TMUX')
set term=screen-256color
endif
if exists('$UCSD')
set term=screen-256color
endif
" fixes error syntax for $( ) in .sh files
let g:is_posix = 1
set t_Co=256
set backupdir=~/.backup,. " Backupdir (doesn't exist)
set directory=~/.backup,.
set nu " Line numbers ON
set sidescroll=1 " Columns to scroll horizontally when wrapping on
set backspace=indent,eol,start " Allow backspacing to move over various chars
set hidden " Hides (not closes) buffers when :q
set nowrap
set wildmenu " Turn on wild menu for tab command completion
set wildmode=list:longest,full
set wildignorecase
set wildignore=*.pyc,*.so,*.o,*.pkl,*.png,*.pdf
set ruler " Turn ruler on to show position
set splitbelow " Open new split panes to the bottom
set splitright " ...and right, which is more natural
set scrolloff=3 " Keep at least 3 lines visible on either side of cursor
set noerrorbells visualbell t_vb= " No alerts/bells
set ttyfast " Smoother drawing
set lazyredraw " Lazy redrawing for slow connections
set cursorline " Highlight current line
set laststatus=2 " Show the status line always
set noshowmode " Because of lightline don't show mode at bottom
set formatoptions+=cr " Continue comment if in insert mode
set formatoptions-=o " ...but not when hitting o/O
set formatoptions-=t " Disable automatic wrapping of comments
set autochdir " Cd into directory where file is
set tabstop=4 " Spaces only, and 4 spaces forever
set shiftwidth=4
set softtabstop=4
set smarttab " Correct the wicked by converting tabs to spaces
set expandtab
set title " Set window title to current file
set showmatch " When bracket inserted, briefly flash matching one
set matchtime=3 " Timing for above
set incsearch " Search as characters are entered
set hlsearch " Highlight search
set ignorecase " Case-sensitive only if search contains an uppercase character
set smartcase
set noswapfile
set diffopt+=vertical " Vertical split for diff
set viminfo=%,<800,'10,/50,:100,h,f0,n~/.vim/.viminfo
" set foldmethod=marker
" cursor changing escape sequences in iTerm
let &t_SI = "\<Esc>]1337;CursorShape=1\x7"
let &t_SR = "\<Esc>]1337;CursorShape=2\x7"
let &t_EI = "\<Esc>]1337;CursorShape=0\x7"
" }}}
" ====== Mapping {{{
let mapleader = ","
map <leader>vi :e ~/.vimrc<CR>
map <leader>ww :set nowrap!<cr>
map <leader>nn :set nu!<cr>
" table delimited by space for whole document
map <leader>ts ggVG:Tab / <cr>:set nohl<cr>
" table delimited by comma for whole document
map <leader>tc ggVG:Tab /,<cr>
" replace multiple spaces with single space
map <leader>ss :%s/ \+/ /g<cr>
" sets off header with #
nnoremap <leader>h# :center 40<cr>hhv0r#A<space><esc>20A#<esc>d40<bar>YppVr#kk.
" paste from system clipboard, but only locally
nnoremap <leader>pp "+p
" mash to escape
inoremap kj <Esc>
inoremap kJ <Esc>
inoremap KJ <Esc>
inoremap Kj <Esc>
" mash to move
noremap K 5<up>
noremap J 5<down>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-l> <C-w>l
nnoremap <C-k> <C-w>k
" tnoremap <C-h> <C-w>h
" tnoremap <C-j> <C-w>j
" tnoremap <C-l> <C-w>l
" tnoremap <C-k> <C-w>k
nnoremap <space> %
" maintain line joining even though J remapped
nnoremap <leader>j J
vnoremap <leader>j J
" calculate quantity in Word
nnoremap <leader>cc ciW<C-r>=<C-r>"<CR><Esc>
nnoremap <leader><space> :noh<cr>
nnoremap <leader>rr :w <bar> exec '!. all.sh'<CR>
nnoremap <leader>pt :set paste!<CR>
nnoremap <leader>fv <C-w>F<C-w>L
" copies a line and comments the old line
nmap zz yygccp
vmap zz V<Esc>gvygvgc`>p
nnoremap <leader>an :ALENextWrap<CR>
nnoremap <leader>ap :ALEPreviousWrap<CR>
" dot maps over visual line selection
xnoremap . :norm .<CR>
vnoremap . :norm .<CR>
" remove all trailing whitespace
nnoremap <leader>ws :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
" https://github.com/haya14busa/incsearch.vim
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
map z/ <Plug>(incsearch-fuzzy-/)
map z? <Plug>(incsearch-fuzzy-?)
map zg/ <Plug>(incsearch-fuzzy-stay)
" NERDTree
map <leader>nt :NERDTreeToggle<CR>
" tagbar
map <leader>tt :TagbarToggle<cr>
" remap arrow keys for long lines
noremap <Down> gj
noremap <Up> gk
" select last pasted text
nnoremap gp `[v`]
" remap VIM 0 to first non-blank character
map 0 ^
" }}}
" ====== Abbreviations {{{
iab xdate <c-r>=strftime("%I:%M%p\ \%a\ %b\ %d,\ %Y")<cr>
abbr ifnm if __name__ == "__main__":
abbr allimps import os<CR>import sys<CR>import math<CR>
abbr coutline std::cout << __LINE__ << std::endl;
" }}}
" ====== Misc plugin settings {{{
" ====== Lightline {{{
" Note that fugitive is slow on sshfs
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'cmsswver', 'filename', 'modified' ] ]
\ },
\ 'component': {
\ 'filename': '%<%F',
\ },
\ 'component_function': {
\ 'cmsswver': 'LightlineCMSSWver',
\ },
\ }
" }}}
" ====== Ale {{{
let g:ale_sign_error = '❯❯'
let g:ale_sign_warning = '•'
" 501 - line >80 chars
" 303 - too many blank lines
" 226 - missing whitespace around arithmetic operator
" 231 - missing whitespace after ,
" 225 - missing whitespace after operator
" 302 - 2 blank lines before class
" 305 - 2 blank lines after class
" 701 - multiple statements on one line
" 126 - continuation line over-indented for hanging indent
" 123 - closing bracket does not match indentation of opening bracket
" 251 - unespected spaces around keyword/parameter equals
" 201 - whitespace after (
" 202 - whitespace before )
" 124 - closing bracket does not match outer indent level
let g:ale_python_flake8_args=" --ignore=E501,E303,E226,E231,E225,E302,E305,E701,E126,E123,E251,E201,E202,E124 "
" Disable Ale completely on sshfs mount
let g:ale_pattern_options = {
\ '.*sandbox/uaf/.*$': {'ale_enabled': 0},
\}
" }}}
" }}}
" ====== Autocommands {{{
" this is why I made a group for autocommands:
" http://stackoverflow.com/questions/15353988/progressively-slower-reloading-time-of-vimrc
if has("autocmd")
augroup Group1
autocmd!
filetype plugin indent on
" restore cursor position when opening a file
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
" close vim if only nerdtree is left
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
autocmd InsertLeave * set nopaste
autocmd FileType crontab set nobackup nowritebackup
autocmd FileType crontab set nobackup nowritebackup
" hack? when hitting ,, ALE will try to 'run' again and this screws up colors, so disable and then re-enable
autocmd FileType python nnoremap <buffer> <leader><leader> :ALEDisable <bar> w <bar> exec '!python '.shellescape('%') <bar>ALEEnable<CR>
" why <buffer> ? with a .py file open, opening another file type will cause ,, to use the python ,, mapping to be overriden
autocmd FileType cpp nnoremap <buffer> <leader><leader> :w <bar> exec '!root -b -q -l -n '.shellescape('%')<CR>
autocmd FileType sh nnoremap <leader><leader> :w <bar> exec '!./'.shellescape('%')<CR>
autocmd FileType vim nnoremap <leader><leader> :w <bar> source %<CR>
autocmd FileType c,cpp nnoremap <leader>cp :call lazytools#CoutTokens()<CR>
" vim-commentary
autocmd FileType c set commentstring=\/\/\ %s
autocmd FileType cpp set commentstring=\/\/\ %s
autocmd FileType text set commentstring=\#\ %s
autocmd FileType crontab set commentstring=\#\ %s
augroup END
endif
" }}}
" ====== Misc functions {{{
" }}}
" ====== CMSSW {{{
if exists('$CMSSW_BASE')
" search CMS3 first, then local CMSSW, then central CMSSW
set path+=$CMSSW_BASE/src/CMS3/NtupleMaker/src
set path+=$CMSSW_BASE/src
set path+=$CMSSW_RELEASE_BASE/src
set path+=$ROOTSYS/include
" remove includes from autocomplete search list, otherwise slow
set complete-=i
function! LightlineCMSSWver()
return split($CMSSW_BASE,"CMSSW_")[1]
endfunction
endif
" }}}
" ====== MacVim {{{
if has('gui_running')
let g:lightline.colorscheme = 'one'
colorscheme one
set background=dark
call one#highlight('VertSplit', '2c323c', '2c323c', 'none')
let g:lightline.separator = { 'left': "\ue0b0", 'right': "\ue0b2" }
let g:lightline.subseparator = { 'left': "\ue0b1", 'right': "\ue0b3" }
" set guifont=Monaco:h15
set guifont=Source\ Code\ Pro:h15
set guioptions-=r " remove right-hand scroll bar
set guioptions-=l " remove left-hand scroll bar
set guioptions-=L " remove left-hand scroll bar
endif
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment