vim/vimrc

588 lines
15 KiB
VimL

filetype off " required
set ttyfast
" #plugins{{{
set runtimepath+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
"css3-syntax
Plugin 'hail2u/vim-css3-syntax.git'
"scss-syntax
Plugin 'cakebaker/scss-syntax.vim'
"bufexplorer
Plugin 'jlanzarotta/bufexplorer'
"tagbar
Plugin 'majutsushi/tagbar'
"vim-surround
Plugin 'tpope/vim-surround'
"undotree
Plugin 'mbbill/undotree'
" Ctrlp
Plugin 'ctrlpvim/ctrlp.vim'
" Obsession
Plugin 'tpope/vim-obsession'
" vim-css-color
Plugin 'ap/vim-css-color'
" vim-javascript
Plugin 'pangloss/vim-javascript'
" ultisnips
" https://github.com/sirver/UltiSnips
Plugin 'SirVer/ultisnips'
" and some snippets
" https://github.com/honza/vim-snippets
Plugin 'honza/vim-snippets'
" ALE
" https://github.com/w0rp/ale
Plugin 'w0rp/ale'
" MatchTag
" https://github.com/gregsexton/MatchTag
Plugin 'gregsexton/MatchTag'
" phpcomplete.vim
" https://github.com/shawncplus/phpcomplete.vim
Plugin 'shawncplus/phpcomplete.vim'
" https://github.com/dsawardekar/wordpress.vim
" For up to date Wordpress Files see:
" https://github.com/joseluis/wordpress.vim-generator
"Plugin 'dsawardekar/wordpress.vim'
" disabled - doesn't support universal ctags?
" vim-vue
" https://github.com/posva/vim-vue
Plugin 'posva/vim-vue'
" vim-commentary
" https://github.com/tpope/vim-commentary
Plugin 'tpope/vim-commentary'
" vim-repeat
" https://github.com/tpope/vim-repeat
Plugin 'tpope/vim-repeat'
" taboo.vim
" https://github.com/gcmt/taboo.vim
Plugin 'gcmt/taboo.vim'
" https://github.com/mattn/emmet-vim
Plugin 'mattn/emmet-vim'
" vimwiki
" https://github.com/vimwiki/vimwiki
Plugin 'vimwiki/vimwiki'
" youcompleteme
" https://github.com/Valloric/YouCompleteMe
Plugin 'Valloric/YouCompleteMe'
" gitgutter
" https://github.com/airblade/vim-gitgutter/blob/master/README.mkd
Plugin 'airblade/vim-gitgutter'
" vim-peekaboo
" https://github.com/junegunn/vim-peekaboo
Plugin 'junegunn/vim-peekaboo'
" vim-gutentags
" https://github.com/ludovicchabant/vim-gutentags
Plugin 'ludovicchabant/vim-gutentags'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
"}}}
" #settings{{{
" set t_Sf=<Esc>[3%p1%dm " foreground colour
if &term == 'xterm-256color'
set termguicolors
endif
syntax on
colorscheme customred256
set guioptions-=mTrLb
set guioptions+=c
" set t_Sb=<Esc>[4%p1%dm " background coloru
set updatetime=100
set backupdir=~/.vimtmp
set directory=~/.vimtmp
set tags+=./.tags,.tags;/home/ray/
" persisitent undo file
set undodir=/home/ray/.vim/undodir
set undofile
set clipboard=unnamedplus
set ignorecase
set smartcase
set wildmenu
set wildmode=longest:full,full
set hidden
set background=dark
set number relativenumber
set hlsearch
set foldcolumn=1
set iskeyword+=-
set scrolloff=10
set showcmd
set incsearch
set laststatus=2
set foldmethod=manual
set showmode
set autoindent
set breakindent
set showbreak=
set mouse=a
set listchars=eol,tab:->,trail:~,extends:>,precedes:<,space
set textwidth=180
set formatoptions=cq
set wrapmargin=0
"}}}
" key #mappings{{{
let g:mapleader = "\<space>"
nnoremap <leader>rc :so $MYVIMRC<CR>
" Focus on current fold, close the rest
nnoremap <leader>zz zMzvzz
" replace current word with last yanked/deleted text
nnoremap <leader>rr "_diwP
" replace current word with last yanked text
nnoremap <leader>ry diw"0P
inoremap jk <esc>
nnoremap A :call CheckLineEnding()<CR>
nnoremap <leader>co :!clear;
nnoremap <leader>gs :!clear; echo 'git status'; git status<CR>
nnoremap <leader>gd :!clear; echo 'git diff'; git diff<CR>
nnoremap <leader>ga :!clear; git add %; git status<CR>
nnoremap <leader>gA :!clear; git add .; git status<CR>
nnoremap <leader>gc :!clear; git commit -m ''<Left>
nnoremap <leader>gg :!clear; git add %; git commit -m ''<Left>
nnoremap <leader>gp :!clear; echo 'git push'; git push<CR>
nnoremap <leader>gl :!clear; git log<CR>
" netrw
nnoremap <leader>ex :Ex<CR>
nnoremap <leader>ee :e .<CR>
nnoremap <leader>eq :Rex<CR>
" better window navigaton
nnoremap <C-h> <C-w>h
nnoremap <C-l> <C-w>l
nnoremap <C-k> <C-w>k
nnoremap <C-j> <C-w>j
nnoremap <Esc>j :resize -5<CR>
nnoremap <Esc>k :resize +5<CR>
nnoremap <Esc>l :vertical resize +5<CR>
nnoremap <Esc>h :vertical resize -5<CR>
nnoremap <Esc>= <C-w>=
"location list and quickfix mappings
nnoremap <leader>ll :botright lwindow<CR>
nnoremap <leader>lp :lprev<CR>
nnoremap <leader>ln :lnext<CR>
nnoremap <leader>lc :lclose<CR>
nnoremap <leader>llh :lhistory<CR>
nnoremap <leader>llp :lolder<CR>
nnoremap <leader>lln :lnewer<CR>
nnoremap <leader>qf :botright cwindow<CR>
nnoremap <leader>qp :cprev<CR>
nnoremap <leader>qn :cnext<CR>
nnoremap <leader>qc :cclose<CR>
nnoremap <leader>qfh :chistory<CR>
nnoremap <leader>qfp :colder<CR>
nnoremap <leader>qfn :cnewer<CR>
nnoremap <leader>nh :noh<CR>
" quick grep of visual selection
vnoremap <leader>gr y:grep! -R <C-r>" .
" open quickfix window of TODOs
nnoremap <leader>td :grep! -R '// *TODO' .<CR>:botright cwindow<CR>:echo len(getqflist()) 'TODOs'<CR>
" brace/quotes completion
inoremap {{ {}<left>
inoremap {<CR> {<CR>}<esc>O
inoremap {; {<CR>};<esc>O
inoremap }} {{}}<Left><Left>
inoremap (( ()<Left>
inoremap (; ();<Left><Left>
inoremap [[ []<Left>
inoremap [<CR> [<CR>]<esc>O
inoremap "" ""<Left>
inoremap "; "";<Left><Left>
inoremap '' ''<Left>
inoremap '; '';<Left><Left>
inoremap ;; ;<esc>
nnoremap <leader>nn :set invrelativenumber<CR>
nnoremap <leader>hl :nohlsearch<CR>
" devdocs mapping
nnoremap <leader>dd :DD<CR>
"}}}
" #abbreviations{{{
iabbrev adn and
iabbrev waht what
iabbrev tehn then
"}}}
" #statusline format{{{
" isactive = 0 when inactive, 1 otherwise
" get status line
function! GetStatus(isactive)
let l:separator='%#StatusLineSeparator# '
let l:normal='%#StatusLineNormal#'
let l:active='%#StatusLineActive#'
let l:statusline=''
" linter status{{{
let l:statusline.='%#InterfaceH2# %{LinterStatus()} %*'
"}}}
" file info{{{
if a:isactive == 1
let l:statusline.=l:active
let l:statusline.='%q%h%w%r'
let l:statusline.=" %{strlen(&ft)?&ft:'none'},"
let l:statusline.='%{strlen(&fenc)?&fenc:&enc},'
let l:statusline.='%{&fileformat} '
let l:statusline.=l:separator . l:active
let l:statusline.=' %{&spelllang} '
else
let l:statusline.=l:separator
endif
"}}}
" current register{{{
if a:isactive
let l:statusline.=l:separator . l:active
let l:statusline.=' %#StatusLineActiveQuotes#"' . l:active . '%{v:register}%#StatusLineActiveQuotes#" '
endif
"}}}
" session status{{{
if a:isactive
let l:statusline.=l:separator . l:active
let l:statusline.=" %{ObsessionStatus(fnamemodify(v:this_session,':t'),'---')} %*"
let l:statusline.=l:separator . l:active
endif
"}}}
" right/left separator{{{
" let l:statusline.='%#StatusLineDivider'
" " if &modified == 1
" " let l:statusline.='Mod'
" " endif
" echo a:isactive
" if a:isactive
" let l:statusline.='Active'
" endif
"let l:statusline.='# %< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - >' . l:separator . '%*%='
""}}}
" modified flag {{{
let l:statusline.='%#StatusLineMod#%M' . l:separator . '%*'
"}}}
" path/filename.extension{{{
if a:isactive
let l:statusline.='%#StatusLineDirActive# '
let l:statusline.="%{expand('%:p:h:t')}/"
let l:statusline.='%#StatusLineFileActive#'
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.='%#StatusLineDotActive#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExtActive#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
else
let l:statusline.='%#StatusLineDir# '
let l:statusline.="%{expand('%:p:h')}/"
let l:statusline.='%#StatusLineFile#'
let l:statusline.="%{expand('%:t:r')}"
let l:statusline.='%#StatusLineDot#'
let l:statusline.="%{strlen(expand('%:e'))?'.':''}"
let l:statusline.='%#StatusLineExt#'
let l:statusline.="%{strlen(expand('%:e'))?expand('%:e'):expand('%:e')}"
endif
let l:statusline.=' ' . l:separator
"}}}
" file percentage{{{
let l:statusline.='%#InterfaceNormalDark#%P%*'
return l:statusline
endfunction
"}}}
" status line autocommands{{{
augroup status
autocmd!
autocmd WinEnter * set statusline=%!GetStatus(1)
autocmd WinLeave * set statusline=%!GetStatus(0)
" autocmd InsertChange * setlocal statusline=%!GetStatus(1)
augroup END
"}}}}}}
" #autocommands{{{
" persistent folds
augroup AutoSaveFolds
autocmd!
autocmd BufWritePost *.* mkview
autocmd BufWinEnter *.* silent loadview
augroup END
" fix higlight problems such as vertical-align etc
augroup VimCSS3Syntax
autocmd!
autocmd FileType css setlocal iskeyword+=-
augroup END
" Show trailing whitepace and spaces before a tab:
augroup whitespaceerrors
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\t/ containedin=ALL
augroup END
" automatically reload if color scheme file written
augroup coloreload
au!
au BufWritePost customred256.vim so $MYVIMRC
augroup end
augroup linenumbering
autocmd InsertEnter * :set norelativenumber
autocmd InsertLeave * :set number relativenumber
autocmd WinEnter * :set number relativenumber
autocmd WinLeave * set norelativenumber
augroup END
augroup colorcolumns
autocmd WinEnter * set colorcolumn=80
autocmd WinLeave * set colorcolumn=0
augroup END
" Automatically reload .vimrc if chanaged
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
"}}}
" #functions{{{
function! CheckLineEnding()
:normal $
if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
:startinsert
else
:startinsert!
endif
endfunction
" get name of syntax item
function! SyntaxItem()
return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
endfunction
nnoremap <leader>p :echom SyntaxItem()<CR>
" devdocs DD
" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
function! s:Get_env() abort
if has('win64') || has('win32') || has('win16')
return 'WINDOWS'
else
return toupper(substitute(system('uname'), '\n', '', ''))
endif
endfunction
" What command to use on what system
let s:cmds = {'DARWIN': 'open', 'LINUX': 'qutebrowser', 'WINDOWS': 'start'}
" Build the URL stub
let s:stub = s:cmds[<SID>Get_env()] . " 'http://devdocs.io/?q="
command! -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
\ s:stub . &ft . ' ' . expand('<cword>') . "'" : len(split(<q-args>, ' ')) == 1 ?
\ s:stub . &ft . ' ' . <q-args> . "'" : s:stub . <q-args> . "'")
" use ranger as file manager
if !exists('*RangerExplorer')
function RangerExplorer()
exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
if filereadable('/tmp/vim_ranger_current_file')
exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
call system('rm /tmp/vim_ranger_current_file')
endif
redraw!
endfun
map <Leader>ra :call RangerExplorer()<CR>
endif
"}}}
" #plugin settings{{{
" vim-peekaboo
let g:peekaboo_window = 'vert to 30new'
" gitgutter
nmap ]h <Plug>GitGutterNextHunk
nmap [h <Plug>GitGutterPrevHunk
omap ih <Plug>GitGutterTextObjectInnerPending
omap ah <Plug>GitGutterTextObjectOuterPending
xmap ih <Plug>GitGutterTextObjectInnerVisual
xmap ah <Plug>GitGutterTextObjectOuterVisual
" Use the silver searcher ag command instead of grep
if executable('ag')
" Use ag over grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" ag is fast enough that CtrlP doesn't need to cache
let g:ctrlp_use_caching = 0
endif
"vim-wiki
let g:vimwiki_list = [{'path': '~/vimwiki/', 'path_html': '~/vimwiki_html/'}]
" youcompleteme
let g:ycm_collect_identifiers_from_tags_files = 1
" emmet
let g:user_emmet_leader_key='<C-y>'
" taboo.vim
set sessionoptions+=tabpages,globals
let g:taboo_tab_format = ' %f%m '
let g:taboo_renamed_tab_format = ' %l%m '
let g:taboo_modified_tab_flag = '+'
" vue-vim
" disable preprocessor checking for vue files - increases speed
let g:vue_disable_pre_processors=1
" set custom syntax highlighting
augroup fixhighlighting
autocmd BufNewFile,BufRead *.vue syntax sync fromstart
augroup END
" ALE
nnoremap <leader>ne :lnext<cr>
nnoremap <leader>pe :lprev<cr>
let g:ale_sign_error = '>>'
let g:ale_sign_warning = '--'
let g:ale_sign_column_always = 1
let g:ale_linters = {'scss': ['stylelint'], 'javascript': ['eslint'], 'php':['php'], 'html':['htmlhint']}
let g:ale_html_htmlhint_options = '-c ~/.htmlhintrc --format=unix'
let g:ale_fixers = {'javascript': ['eslint']}
function! LinterStatus() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? 'OK' : printf('%dW %dE', l:all_non_errors, l:all_errors)
endfunction
"nmap <silent> <C-k> <Plug>(ale_previous_wrap)
"nmap <silent> <C-j> <Plug>(ale_next_wrap)
" ultisnips
let g:UltiSnipsSnippetsDir="~/.vim/UltiSnips"
" Trigger configuration. Do not use <tab> if you use https://github.com/Valloric/YouCompleteMe.
let g:UltiSnipsExpandTrigger='<c-j>'
let g:UltiSnipsJumpForwardTrigger='<c-b>'
let g:UltiSnipsJumpBackwardTrigger='<c-z>'
let g:UltiSnipsEditSplit='horizontal'
" Netrw
let g:netrw_liststyle=3
let g:netrw_list_hide='^\..*'
" bufexploer
nnoremap <leader>o :BufExplorer<CR>
" undotree
nnoremap <leader>ut :UndotreeToggle<cr>
" TagBar
nnoremap <leader>tb :TagbarOpen fj<CR>
nnoremap <leader>] :tag /[.#@]<c-r>=expand('<cword>')<cr><cr>
let g:tagbar_autoclose = 1
" let g:tagbar_autopreview = 1
" let g:tagbar_previewwin_pos = ''
let g:tagbar_type_css = {
\ 'ctagstype' : 'css',
\ 'kinds' : [
\ 'c:classes',
\ 'i:ids',
\ 't:tags',
\ 'm:medias'
\ ]
\}
let g:tagbar_type_scss = {
\ 'ctagstype' : 'scss',
\ 'kinds' : [
\ 'v:variables',
\ 'c:classes',
\ 'i:ids',
\ 't:tags',
\ 'd:medias',
\ 'm:mixins',
\ 'f:functions'
\ ]
\}
let g:tagbar_type_vue = {
\ 'ctagstype' : 'vue',
\ 'kinds' : [
\ 'o:objects',
\ 'f:functions',
\ 'a:array',
\ 's:string',
\ 'b:boolean',
\ 'n:number',
\ 'v:variable'
\ ]
\ }
" gutentags
let g:gutentags_ctags_tagfile = '.tags'
let g:gutentags_ctags_exclude = ['package.json', 'Session.vim' ,'package-lock.json', 'TODO.txt']
"}}}
" vim: foldmethod=marker