diff --git a/vim/autoload/rainbow.vim b/vim/autoload/rainbow.vim new file mode 100644 index 00000000..adf84b3e --- /dev/null +++ b/vim/autoload/rainbow.vim @@ -0,0 +1,92 @@ +if exists('s:loaded') | finish | endif | let s:loaded = 1 +fun s:resolve_parenthesis(p) + let ls = split(a:p, '\v%(%(start|step|end)\=(.)%(\1@!.)*\1[^ ]*|\w+%(\=[^ ]*)?) ?\zs', 0) + let [paren, containedin, contains, op] = ['', '', 'TOP', ''] + for s in ls + let [k, v] = [matchstr(s, '^[^=]\+\ze='), matchstr(s, '^[^=]\+=\zs.*')] + if k == 'step' + let op = v + elseif k == 'contains' + let contains = v + elseif k == 'containedin' + let containedin = v + else + let paren .= s + endif + endfor + return [paren, containedin, contains, op] +endfun + +fun rainbow#syn(config) + let conf = a:config + let prefix = conf.syn_name_prefix + let maxlvl = has('gui_running')? len(conf.guifgs) : len(conf.ctermfgs) + for i in range(len(conf.parentheses)) + let p = conf.parentheses[i] + if type(p) == type([]) + let op = len(p)==3? p[1] : has_key(conf, 'operators')? conf.operators : '' + let conf.parentheses[i] = op != ''? printf('start=#%s# step=%s end=#%s#', p[0], op, p[-1]) : printf('start=#%s# end=#%s#', p[0], p[-1]) + endif + endfor + let def_rg = 'syn region %s matchgroup=%s containedin=%s contains=%s %s' + let def_op = 'syn match %s %s containedin=%s contained' + + let b:rainbow_loaded = maxlvl + for parenthesis_args in conf.parentheses + let [paren, containedin, contains, op] = s:resolve_parenthesis(parenthesis_args) + if op == '' |let op = conf.operators |endif + for lvl in range(maxlvl) + if op != '' |exe printf(def_op, prefix.'_o'.lvl, op, prefix.'_r'.lvl) |endif + if lvl == 0 + if containedin == '' + exe printf(def_rg, prefix.'_r0', prefix.'_p0', prefix.'_r'.(maxlvl - 1), contains, paren) + endif + else + exe printf(def_rg, prefix.'_r'.lvl, prefix.'_p'.lvl.(' contained'), prefix.'_r'.((lvl + maxlvl - 1) % maxlvl), contains, paren) + endif + endfor + if containedin != '' + exe printf(def_rg, prefix.'_r0', prefix.'_p0 contained', containedin.','.prefix.'_r'.(maxlvl - 1), contains, paren) + endif + endfor + exe 'syn cluster '.prefix.'Regions contains='.join(map(range(maxlvl), '"'.prefix.'_r".v:val'),',') + exe 'syn cluster '.prefix.'Parentheses contains='.join(map(range(maxlvl), '"'.prefix.'_p".v:val'),',') + exe 'syn cluster '.prefix.'Operators contains='.join(map(range(maxlvl), '"'.prefix.'_o".v:val'),',') + if has_key(conf, 'after') | for cmd in conf.after | exe cmd | endfor | endif +endfun + +fun rainbow#syn_clear(config) + let conf = a:config + let prefix = conf.syn_name_prefix + let maxlvl = has('gui_running')? len(conf.guifgs) : len(conf.ctermfgs) + + for id in range(maxlvl) + exe 'syn clear '.prefix.'_r'.id + exe 'syn clear '.prefix.'_o'.id + endfor +endfun + +fun rainbow#hi(config) + let conf = a:config + let prefix = conf.syn_name_prefix + let maxlvl = has('gui_running')? len(conf.guifgs) : len(conf.ctermfgs) + + for id in range(maxlvl) + let ctermfg = conf.ctermfgs[id % len(conf.ctermfgs)] + let guifg = conf.guifgs[id % len(conf.guifgs)] + exe 'hi '.prefix.'_p'.id.' ctermfg='.ctermfg.' guifg='.guifg + exe 'hi '.prefix.'_o'.id.' ctermfg='.ctermfg.' guifg='.guifg + endfor +endfun + +fun rainbow#hi_clear(config) + let conf = a:config + let prefix = conf.syn_name_prefix + let maxlvl = has('gui_running')? len(conf.guifgs) : len(conf.ctermfgs) + + for id in range(maxlvl) + exe 'hi clear '.prefix.'_p'.id + exe 'hi clear '.prefix.'_o'.id + endfor +endfun + diff --git a/vim/autoload/rainbow_main.vim b/vim/autoload/rainbow_main.vim new file mode 100644 index 00000000..c55a9cb2 --- /dev/null +++ b/vim/autoload/rainbow_main.vim @@ -0,0 +1,97 @@ +let s:rainbow_conf = { +\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'], +\ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], +\ 'operators': '_,_', +\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], +\ 'separately': { +\ '*': {}, +\ 'lisp': { +\ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], +\ }, +\ 'haskell': { +\ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/\v\{\ze[^-]/ end=/}/ fold'], +\ }, +\ 'tex': { +\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'], +\ }, +\ 'vim': { +\ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'], +\ }, +\ 'xml': { +\ 'syn_name_prefix': 'xmlRainbow', +\ 'parentheses': ['start=/\v\<\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'))?)*\>/ end=## fold'], +\ }, +\ 'xhtml': { +\ 'parentheses': ['start=/\v\<\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'))?)*\>/ end=## fold'], +\ }, +\ 'html': { +\ 'parentheses': ['start=/\v\<((script|style|area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold'], +\ }, +\ 'perl': { +\ 'syn_name_prefix': 'perlBlockFoldRainbow', +\ }, +\ 'php': { +\ 'syn_name_prefix': 'phpBlockRainbow', +\ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold', 'start=/(/ end=/)/ containedin=@htmlPreproc contains=@phpClTop', 'start=/\[/ end=/\]/ containedin=@htmlPreproc contains=@phpClTop', 'start=/{/ end=/}/ containedin=@htmlPreproc contains=@phpClTop'], +\ }, +\ 'stylus': { +\ 'parentheses': ['start=/{/ end=/}/ fold contains=@colorableGroup'], +\ }, +\ 'css': 0, +\ 'sh': 0, +\ } +\} + +fun s:eq(x, y) + return type(a:x) == type(a:y) && a:x == a:y +endfun + +fun rainbow_main#gen_config(ft) + let g = exists('g:rainbow_conf')? g:rainbow_conf : {} + "echom 'g:rainbow_conf:' string(g) + let s = get(g, 'separately', {}) + "echom 'g:rainbow_conf.separately:' string(s) + let dft_conf = extend(copy(s:rainbow_conf), g) | unlet dft_conf.separately + "echom 'default config options:' string(dft_conf) + let dx_conf = s:rainbow_conf.separately['*'] + "echom 'default star config:' string(dx_conf) + let ds_conf = get(s:rainbow_conf.separately, a:ft, dx_conf) + "echom 'default separately config:' string(ds_conf) + let ux_conf = get(s, '*', ds_conf) + "echom 'user star config:' string(ux_conf) + let us_conf = get(s, a:ft, ux_conf) + "echom 'user separately config:' string(us_conf) + let conf = (s:eq(us_conf, 'default') ? ds_conf : us_conf) + "echom 'almost finally config:' string(conf) + return s:eq(conf, 0) ? 0 : extend(extend({'syn_name_prefix': substitute(a:ft, '\v\A+(\a)', '\u\1', 'g').'Rainbow'}, dft_conf), conf) +endfun + +fun rainbow_main#gen_configs(ft) + return filter(map(split(a:ft, '\v\.'), 'rainbow_main#gen_config(v:val)'), 'type(v:val) == type({})') +endfun + +fun rainbow_main#load() + let b:rainbow_confs = rainbow_main#gen_configs(&ft) + for conf in b:rainbow_confs + call rainbow#syn(conf) + call rainbow#hi(conf) + endfor +endfun + +fun rainbow_main#clear() + if !exists('b:rainbow_confs') | return | endif + for conf in b:rainbow_confs + call rainbow#hi_clear(conf) + call rainbow#syn_clear(conf) + endfor + unlet b:rainbow_confs +endfun + +fun rainbow_main#toggle() + if exists('b:rainbow_confs') + call rainbow_main#clear() + else + call rainbow_main#load() + endif +endfun + diff --git a/vim/plugin/rainbow_main.vim b/vim/plugin/rainbow_main.vim new file mode 100644 index 00000000..af34568c --- /dev/null +++ b/vim/plugin/rainbow_main.vim @@ -0,0 +1,10 @@ +if exists('s:loaded') || !(exists('g:rainbow_active') || exists('g:rainbow_conf')) | finish | endif | let s:loaded = 1 + +command! RainbowToggle call rainbow_main#toggle() +command! RainbowToggleOn call rainbow_main#load() +command! RainbowToggleOff call rainbow_main#clear() + +if (exists('g:rainbow_active') && g:rainbow_active) + auto syntax * call rainbow_main#load() + auto colorscheme * call rainbow_main#load() +endif diff --git a/vimrc b/vimrc index ddb49fac..f150153d 100644 --- a/vimrc +++ b/vimrc @@ -1,40 +1,22 @@ -" don't bother with vi compatibility +" Setting options set nocompatible - -" enable syntax highlighting -syntax enable - -" configure Vundle -filetype on " without this vim emits a zero exit status, later, because of :ft off -filetype off -set rtp+=~/.vim/bundle/Vundle.vim -call vundle#begin() - -" install Vundle bundles -if filereadable(expand("~/.vimrc.bundles")) - source ~/.vimrc.bundles - source ~/.vimrc.bundles.local -endif - -call vundle#end() - -" ensure ftdetect et al work by including this after the Vundle stuff -filetype plugin indent on - +set undofile +set undodir=~/.maximum-awesome/.undo/ +set history=5000 set autoindent set autoread " reload files when changed on disk, i.e. via `git checkout` set backspace=2 " Fix broken backspace in some setups set backupcopy=yes " see :help crontab set clipboard=unnamed " yank and paste with the system clipboard set directory-=. " don't store swapfiles in the current directory +set noswapfile " do not set swapfiles set encoding=utf-8 set expandtab " expand tabs to spaces set ignorecase " case-insensitive search set incsearch " search as you type set laststatus=2 " always show statusline set list " show trailing whitespace -set listchars=tab:▸\ ,trail:▫ -set number " show line numbers +set listchars=tab:▸\ ,trail:·,eol:¬ set ruler " show where you are set scrolloff=3 " show context above/below cursorline set shiftwidth=2 " normal mode indentation commands use 2 spaces @@ -42,12 +24,65 @@ set showcmd set smartcase " case-sensitive search if any caps set softtabstop=2 " insert mode tab and backspace use 2 spaces set tabstop=8 " actual tabs occupy 8 characters -set wildignore=log/**,node_modules/**,target/**,tmp/**,*.rbc +set wildignore+=*/tmp/*,*.so,*.swp,*.zip " MacOSX/Linux set wildmenu " show a navigable menu for tab completion set wildmode=longest,list,full +"Options to set diffent colors +"let &t_8f = "\[38;5;%1u;%2u;%1um" +"let &t_8b = "\[33;2;%lu;%lu;%lum" +"set termguicolors + +set copyindent + +" Folding + set foldmethod=indent + set foldnestmax=10 + set nofoldenable + set foldlevel=2 + set foldcolumn=3 + +" enable syntax highlighting +syntax on +"syntax enable + +" Tmux & Clipboard +set clipboard^=unnamed + +" limit to 79 +" Autocmds + augroup collumnLimit + autocmd! + autocmd BufEnter,WinEnter,FileType scala,java,asciidoc,yaml,yml,bash + \ highlight CollumnLimit ctermbg=DarkGrey guibg=DarkGrey + let collumnLimit = 79 " feel free to customize + let pattern = + \ '\%<' . (collumnLimit+1) . 'v.\%>' . collumnLimit . 'v' + autocmd BufEnter,WinEnter,FileType scala,java,asciidoc,yaml,yml,bash + \ let w:m1=matchadd('CollumnLimit', pattern, -1) + augroup END + -" Enable basic mouse behavior such as resizing buffers. -set mouse=a +" configure Vundle + filetype on " without this vim emits a zero exit status, later, because of :ft off + filetype off + set rtp+=~/.vim/bundle/Vundle.vim +call vundle#begin() + +" install Vundle bundles +if filereadable(expand("~/.vimrc.bundles")) + source ~/.vimrc.bundles + source ~/.vimrc.bundles.local + source ~/.vimrc.yaml.local +endif +call vundle#end() + +" ensure ftdetect et al work by including this after the Vundle stuff +filetype plugin indent on + + +" Enable basic mouse behavior such as resizing buffers. Off for iTerm2 on Mac +" section on preference to copy on select. +" set mouse=a if exists('$TMUX') " Support resizing in tmux set ttymouse=xterm2 endif @@ -66,6 +101,7 @@ nnoremap f :NERDTreeFind nnoremap t :CtrlP nnoremap T :CtrlPClearCache:CtrlP nnoremap ] :TagbarToggle +nnoremap y :call system('nc -U ~/.clipper.sock', @0) nnoremap :call whitespace#strip_trailing() nnoremap g :GitGutterToggle noremap V :source ~/.vimrc:filetype detect:exe ":echo 'vimrc reloaded'" @@ -73,11 +109,36 @@ noremap V :source ~/.vimrc:filetype detect:exe ":echo ' " in case you forgot to sudo cnoremap w!! %!sudo tee > /dev/null % -" plugin settings -let g:ctrlp_match_window = 'order:ttb,max:20' -let g:NERDSpaceDelims=1 -let g:gitgutter_enabled = 0 - +" plugin settings asciidoct/asciidoctor + let g:ctrlp_match_window = 'order:ttb,max:20' + let g:NERDSpaceDelims=1 + let g:gitgutter_enabled = 0 + let g:vim_asciidoc_initial_foldlevel=1 + " asciidoctor + let g:syntastic_asciidoc_asciidoc_exec = "asciidoctor" + let g:rainbow_active = 1 "0 if you want to enable it later via :RainbowToggle + let g:rainbow_conf = { + \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'], + \ 'ctermfgs': ['lightblue', 'lightyellow', 'lightcyan', 'lightmagenta'], + \ 'operators': '_,_', + \ 'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'], + \ 'separately': { + \ '*': {}, + \ 'tex': { + \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/'], + \ }, + \ 'lisp': { + \ 'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick', 'darkorchid3'], + \ }, + \ 'vim': { + \ 'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'], + \ }, + \ 'html': { + \ 'parentheses': ['start=/\v\<((area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)[ >])@!\z([-_:a-zA-Z0-9]+)(\s+[-_:a-zA-Z0-9]+(\=("[^"]*"|'."'".'[^'."'".']*'."'".'|[^ '."'".'"><=`]*))?)*\>/ end=## fold'], + \ }, + \ 'css': 0, + \ } + \} " Use The Silver Searcher https://github.com/ggreer/the_silver_searcher if executable('ag') " Use Ag over Grep @@ -87,21 +148,32 @@ if executable('ag') let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' endif -" fdoc is yaml -autocmd BufRead,BufNewFile *.fdoc set filetype=yaml -" md is markdown -autocmd BufRead,BufNewFile *.md set filetype=markdown -autocmd BufRead,BufNewFile *.md set spell -" extra rails.vim help -autocmd User Rails silent! Rnavcommand decorator app/decorators -glob=**/* -suffix=_decorator.rb -autocmd User Rails silent! Rnavcommand observer app/observers -glob=**/* -suffix=_observer.rb -autocmd User Rails silent! Rnavcommand feature features -glob=**/* -suffix=.feature -autocmd User Rails silent! Rnavcommand job app/jobs -glob=**/* -suffix=_job.rb -autocmd User Rails silent! Rnavcommand mediator app/mediators -glob=**/* -suffix=_mediator.rb -autocmd User Rails silent! Rnavcommand stepdefinition features/step_definitions -glob=**/* -suffix=_steps.rb -" automatically rebalance windows on vim resize -autocmd VimResized * :wincmd = +" setting bad words to underline instead of highlighed +hi clear SpellBad +hi SpellBad cterm=underline +hi SpellBad ctermfg=red guifg=red + +"Spelling and file types + augroup markdownSpell + autocmd! + autocmd FileType markdown setlocal spell + autocmd BufRead,BufNewFile *.md setlocal spell + augroup END + augroup AsciidocSpell + autocmd! + autocmd FileType asciidoc setlocal spell + autocmd BufRead,BufNewFile *.adoc setlocal spell + augroup END + + + "Jinja 2 + autocmd BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm set ft=jinja spell + " yaml,yml,bash spelling + autocmd Filetype yaml setlocal spell + autocmd BufNewFile,BufRead *.bash,*.sh set ft=bash spell + +" " Fix Cursor in TMUX if exists('$TMUX') let &t_SI = "\Ptmux;\\]50;CursorShape=1\x7\\\" @@ -111,6 +183,7 @@ else let &t_EI = "\]50;CursorShape=0\x7" endif + " Don't copy the contents of an overwritten selection. vnoremap p "_dP @@ -127,3 +200,15 @@ if filereadable(expand("~/.vimrc.local")) " noremap! jj source ~/.vimrc.local endif + +" Line Numbers +function! NumberToggle() + if(&relativenumber == 1) + set nornu + set number + else + set relativenumber + endif + endfunc +" nnoremap :call NumberToggle() +call NumberToggle() diff --git a/vimrc.bundles b/vimrc.bundles index f776fa31..8961b152 100644 --- a/vimrc.bundles +++ b/vimrc.bundles @@ -41,3 +41,13 @@ Plugin 'vim-ruby/vim-ruby' Plugin 'vim-scripts/Align' Plugin 'vim-scripts/greplace.vim' Plugin 'vim-scripts/matchit.zip' +Plugin 'lepture/vim-jinja' +Plugin 'glench/vim-jinja2-syntax' +Plugin 'auto-pairs-gentle' +Plugin 'hashivim/vim-terraform' +Plugin 'maralla/completor.vim' +Plugin 'tpope/vim-sensible' +Plugin 'xuyuanp/nerdtree-git-plugin' +Plugin 'avakhov/vim-yaml' +Plugin 'morhetz/gruvbox' +Plugin 'osyo-manga/vim-over' diff --git a/vimrc.local b/vimrc.local index df938865..e6166de3 100644 --- a/vimrc.local +++ b/vimrc.local @@ -17,7 +17,6 @@ if (&t_Co == 256 || has('gui_running')) endif " Disambiguate ,a & ,t from the Align plugin, making them fast again. -" " This section is here to prevent AlignMaps from adding a bunch of mappings " that interfere with the very-common ,a and ,t mappings. This will get run " at every startup to remove the AlignMaps for the *next* vim startup.