dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

commit 4dedeec2d92c79ac5f89390013c64668d67924a0
parent 7b292b2df3c976801a5df609fc37a25f8e6c5c48
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Wed, 22 Jan 2020 16:26:14 +0100

vim: moved coherent groups of config out of vimrc

Former-commit-id: c7ee8dafac675ac6c6eec7aaabd06c34cf57e7dd
Diffstat:
Avim/autoload/delete_hidden_buffers.vim | 9+++++++++
Dvim/autoload/deletehiddenbuffers.vim | 7-------
Avim/autoload/toggle_number.vim | 8++++++++
Dvim/autoload/togglenumber.vim | 8--------
Avim/plugin/delete_hidden_buffers.vim | 7+++++++
Avim/plugin/redir.vim | 10++++++++++
Avim/plugin/statusline.vim | 30++++++++++++++++++++++++++++++
Avim/plugin/toggle_number.vim | 7+++++++
Mvim/vimrc | 44++++++--------------------------------------
9 files changed, 77 insertions(+), 53 deletions(-)

diff --git a/vim/autoload/delete_hidden_buffers.vim b/vim/autoload/delete_hidden_buffers.vim @@ -0,0 +1,9 @@ +function! delete_hidden_buffers#DeleteHiddenBuffers() " Vim with the 'hidden' option + if &hidden + let tpbl=[] + call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))') + for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1') + silent execute 'bwipeout' buf + endfor + endif +endfunction diff --git a/vim/autoload/deletehiddenbuffers.vim b/vim/autoload/deletehiddenbuffers.vim @@ -1,7 +0,0 @@ -function! deletehiddenbuffers#DeleteHiddenBuffers() " Vim with the 'hidden' option - let tpbl=[] - call map(range(1, tabpagenr('$')), 'extend(tpbl, tabpagebuflist(v:val))') - for buf in filter(range(1, bufnr('$')), 'bufexists(v:val) && index(tpbl, v:val)==-1') - silent execute 'bwipeout' buf - endfor -endfunction diff --git a/vim/autoload/toggle_number.vim b/vim/autoload/toggle_number.vim @@ -0,0 +1,8 @@ +function! toggle_number#ToggleNumber() abort + if(&relativenumber == 1) + set norelativenumber + set number + else + set relativenumber + endif +endfunction diff --git a/vim/autoload/togglenumber.vim b/vim/autoload/togglenumber.vim @@ -1,8 +0,0 @@ -function! togglenumber#ToggleNumber() abort - if(&relativenumber == 1) - set norelativenumber - set number - else - set relativenumber - endif -endfunction diff --git a/vim/plugin/delete_hidden_buffers.vim b/vim/plugin/delete_hidden_buffers.vim @@ -0,0 +1,7 @@ +if exists("g:loaded_delete_hidden_buffers") || &cp + finish +endif +let g:loaded_delete_hidden_buffers = 1 + +command! DeleteHiddenBuffers call delete_hidden_buffers#DeleteHiddenBuffers() +nnoremap <Plug>DeleteHiddenBuffers :DeleteHiddenBuffers<CR> diff --git a/vim/plugin/redir.vim b/vim/plugin/redir.vim @@ -0,0 +1,10 @@ +" Usage: +" :Redir hi ............. show the full output of command ':hi' in a scratch window +" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window + +if exists("g:loaded_redir") || &cp + finish +endif +let g:loaded_redir = 1 + +command! -nargs=1 -complete=command Redir silent call redir#Redir(<f-args>) diff --git a/vim/plugin/statusline.vim b/vim/plugin/statusline.vim @@ -0,0 +1,30 @@ +if exists("g:loaded_statusline") || &cp + finish +endif + +let g:loaded_statusline = 1 + +set laststatus=2 " Always show status bar +set statusline=%f " Relative path and filename +set statusline+=\ %m%r%w " Flags (modified, readonly, help, preview) +set statusline+=%#error# " Start error highlighting +set statusline+=%{statusline#StatuslineTabWarning()} " Inconsistent indentation warning +set statusline+=%{statusline#StatuslineTrailingSpaceWarning()} " Trailing whitespace warning +set statusline+=%* " Clear highlighting +set statusline+=%< " Start truncating here +set statusline+=\ \ %{statusline#StatuslineBuildCwd()} " Current working directory, replacing home with ~ +set statusline+=%= " Move everything after this to the right +set statusline+=%y " File type +set statusline+=\ [%{&expandtab?'spaces':'tabs'}, " Using spaces or tabs +set statusline+=%{strlen(&shiftwidth)?&shiftwidth:'none'}] " Spaces in a tab +set statusline+=\ [%{statusline#StatuslineFoldmethod()}] " The current foldlevel +set statusline+=\ {%{statusline#StatuslineWrapCol()}} " Textwidth/wrapmargin info +set statusline+=\ %l/%L\ " Cursor line/total lines +set statusline+=\ %{strftime(\"%H:%M\")}\ " Time + +augroup statusline + " recalculate the tab/trailing whitespace warning flags when idle and after writing + autocmd! + autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning + autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning +augroup END diff --git a/vim/plugin/toggle_number.vim b/vim/plugin/toggle_number.vim @@ -0,0 +1,7 @@ +if exists("g:loaded_toggle_number") || &cp + finish +endif +let g:loaded_toggle_number = 1 + +" Switch between relative and absolute line num +nnoremap <Plug>ToggleNumber :call toggle_number#ToggleNumber()<CR> diff --git a/vim/vimrc b/vim/vimrc @@ -124,6 +124,9 @@ Plug 'tpope/vim-dispatch' " &path for filetypes Plug 'tpope/vim-apathy' + +" easier markdown-style tables +Plug 'dhruvasagar/vim-table-mode' call plug#end() " }}} " Config {{{ @@ -410,35 +413,6 @@ set wildmenu " Allow the mouse, good for e.g. resizing splits set mouse=a -" Status line {{{ -set laststatus=2 " Always show status bar -set statusline=%f " Relative path and filename -set statusline+=\ %m%r%w " Flags (modified, readonly, help, preview) -set statusline+=%#error# " Start error highlighting -set statusline+=%{statusline#StatuslineTabWarning()} " Inconsistent indentation warning -set statusline+=%{statusline#StatuslineTrailingSpaceWarning()} " Trailing whitespace warning -set statusline+=%* " Clear highlighting -set statusline+=%< " Start truncating here -set statusline+=\ \ %{statusline#StatuslineBuildCwd()} " Current working directory, replacing home with ~ -set statusline+=%= " Move everything after this to the right -set statusline+=%y " File type -set statusline+=\ [%{&expandtab?'spaces':'tabs'}, " Using spaces or tabs -set statusline+=%{strlen(&shiftwidth)?&shiftwidth:'none'}] " Spaces in a tab -set statusline+=\ [%{statusline#StatuslineFoldmethod()}] " The current foldlevel -set statusline+=\ {%{statusline#StatuslineWrapCol()}} " Textwidth/wrapmargin info -set statusline+=\ %l/%L\ " Cursor line/total lines -set statusline+=\ %{strftime(\"%H:%M\")}\ " Time - -" Conditional foldlevel display -augroup statusline - " recalculate the tab/trailing whitespace warning flags when idle and after writing - autocmd! - autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning - autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning -augroup END -" }}} - - highlight ColorColumn ctermbg=233 " How to split new windows @@ -545,6 +519,8 @@ set complete=.,w,b,u,t,i,kspell " a match, don't select anything automatically. set completeopt=menu,menuone,preview +nmap <leader># <Plug>ToggleNumber + set omnifunc=syntaxcomplete#Complete " Keep cursor off top and bottom of screen @@ -572,13 +548,7 @@ command! Unhex %!xxd -r command! JsonSimplifyObject %s/^\(\s\{10}\){\n\s\{12\}\(.*\)\n\s\{10\}}\(,\?\)/\1{ \2 }\3 command! BeautifyJson %!python -m json.tool command! Dos2unix .!dos2unix "%" -command! DeleteHiddenBuffers call deletehiddenbuffers#DeleteHiddenBuffers() -command! -nargs=1 -complete=command Redir silent call redir#Redir(<f-args>) command! -nargs=1 Cheat terminal curl cheat.sh/<args> -" Usage: -" :Redir hi ............. show the full output of command ':hi' in a scratch window -" :Redir !ls -al ........ show the full output of command ':!ls -al' in a scratch window - " Fat finger fixes/convenience abbreviations cnoreabbrev W! w! @@ -740,7 +710,7 @@ nnoremap <C-h> <C-W>> nnoremap <C-l> <C-W>< " Delete hidden buffers -nnoremap <leader>dh :DeleteHiddenBuffers<CR> +nmap <leader>dh <Plug>DeleteHiddenBuffers " Switch to alernative buffer nnoremap <leader>s<leader> :b#<CR> @@ -752,8 +722,6 @@ nnoremap <leader>hs :set list!<CR> nnoremap <leader>mm :<C-u>marks<CR>:normal! ` nnoremap <leader>ml :<C-u>marks a-z<CR>:normal! ` -" Switch between relative and absolute line num -nnoremap <leader># :call togglenumber#ToggleNumber()<CR> " Map '0' to act as '^' on first press and '0' on second nnoremap <expr> <silent> 0 col('.') == match(getline('.'),'\S')+1 ? '0' : '^'