dotfiles

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

commit ddc9bb4c7132492259cddd0831f2780555aa5518
parent a41e7a8cb7f454e8af22f85260a011f4c1b10bfe
Author: Alex Balgavy <a.balgavy@gmail.com>
Date:   Thu, 25 Jul 2019 12:41:34 +0200

vim: improving vimrc with autoloads

Former-commit-id: 007081b8ed1572e3d06680107591f81199107440
Diffstat:
M.gitignore | 1+
Avim/autoload/deletehiddenbuffers.vim | 7+++++++
Avim/autoload/redir.vim | 18++++++++++++++++++
Avim/autoload/sessions.vim | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Avim/autoload/statusline.vim | 45+++++++++++++++++++++++++++++++++++++++++++++
Avim/autoload/synstack.vim | 7+++++++
Avim/autoload/togglenumber.vim | 8++++++++
Mvim/vimrc | 256++++++++++++++++---------------------------------------------------------------
8 files changed, 207 insertions(+), 204 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -8,3 +8,4 @@ newsboat/* !newsboat/urls !newsboat/cache.db *.pyc +vim/autoload/plug.vim* diff --git a/vim/autoload/deletehiddenbuffers.vim b/vim/autoload/deletehiddenbuffers.vim @@ -0,0 +1,7 @@ +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/redir.vim b/vim/autoload/redir.vim @@ -0,0 +1,18 @@ +function! redir#Redir(cmd) abort + for win in range(1, winnr('$')) + if getwinvar(win, 'scratch') + execute win . 'windo close' + endif + endfor + if a:cmd =~ '^!' + execute "let output = system('" . substitute(a:cmd, '^!', '', '') . "')" + else + redir => output + execute a:cmd + redir END + endif + vnew + let w:scratch = 1 + setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile + call setline(1, split(output, "\n")) +endfunction diff --git a/vim/autoload/sessions.vim b/vim/autoload/sessions.vim @@ -0,0 +1,69 @@ +" Custom session management (should be plugin) {{{ +function! sessions#SaveSession() abort + let seshdir = $HOME.'/.vim/sessions/' + silent call mkdir (seshdir, 'p') + let name = input("Save as: ") + if name == "" + echo "\nNo name provided." + else + let seshfile = seshdir.name.".vim" + execute "mksession! " . seshfile + echo "\nSession saved: ".seshfile + endif +endfunction +function! sessions#ListSessions() abort + let seshdir = $HOME.'/.vim/sessions/' + silent call mkdir (seshdir, 'p') + let files = globpath(seshdir, '*', 0, 1) + call filter(files, '!isdirectory(v:val)') + return files +endfunction +function! sessions#ChooseSession() abort + let files = ListSessions() + if len(files) > 0 + let inputfiles = map(copy(files), 'index(files, v:val)+1.": ".v:val') + let response = inputlist(inputfiles) + if response > 0 + return files[response-1] + else + return "" + endif + else + echo "No sessions available." + return "" + endif +endfunction +function! sessions#LoadSession() abort + let session = ChooseSession() + if session != "" + execute 'source '.session + else + echo "\nNo session selected." + endif +endfunction +function! sessions#DeleteSession() abort + let sesh = ChooseSession() + if sesh == "" + echo "\nNo session selected" + return 1 + endif + let conf = confirm("Delete ".sesh."?", "&Yes\n&No\n", 2) + if conf == 1 + if delete(sesh) == 0 + echom "Deleted ".sesh + else + echom "Couldn't delete ".sesh + endif + else + echom "No action taken." + endif +endfunction +function! sessions#CloseSession() + bufdo! bwipeout + cd + if g:loaded_tagbar == 1 + execute "TagbarClose" + endif + echom "Session closed." +endfunction +" }}} diff --git a/vim/autoload/statusline.vim b/vim/autoload/statusline.vim @@ -0,0 +1,45 @@ +" return '[&et]' if &et is set wrong +" return '[mixed-indenting]' if spaces and tabs are used to indent +" return an empty string if everything is fine +function! statusline#StatuslineTabWarning() + if &readonly || &bt == "nofile" + return "" + endif + + if !exists("b:statusline_tab_warning") + let tabs = search('^\t', 'nw') != 0 + let spaces = search('^ ', 'nw') != 0 + + if tabs && spaces + let b:statusline_tab_warning = '[mixed-indenting]' + elseif (spaces && !&et) || (tabs && &et) + let b:statusline_tab_warning = '[&et]' + else + let b:statusline_tab_warning = '' + endif + endif + return b:statusline_tab_warning +endfunction + +" return '[\s]' if trailing white space is detected +" return '' otherwise +function! statusline#StatuslineTrailingSpaceWarning() + if &readonly || &bt == "nofile" + return "" + endif + + if !exists("b:statusline_trailing_space_warning") + if search('\s\+$', 'nw') != 0 + let b:statusline_trailing_space_warning = '[\s]' + else + let b:statusline_trailing_space_warning = '' + endif + endif + return b:statusline_trailing_space_warning +endfunction + +" build the current working directory string +function! statusline#StatuslineBuildCwd() + let cwd = substitute(getcwd(),$HOME,'~','g') + return "CWD: " . cwd +endfunction diff --git a/vim/autoload/synstack.vim b/vim/autoload/synstack.vim @@ -0,0 +1,7 @@ +" Show syntax highlighting groups for word under cursor +function! synstack#SynStack() + if !exists("*synstack") + return + endif + echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') +endfunc diff --git a/vim/autoload/togglenumber.vim b/vim/autoload/togglenumber.vim @@ -0,0 +1,8 @@ +function! togglenumber#ToggleNumber() abort + if(&relativenumber == 1) + set norelativenumber + set number + else + set relativenumber + endif +endfunction diff --git a/vim/vimrc b/vim/vimrc @@ -1,8 +1,13 @@ " vim: foldmethod=marker foldlevel=0 let mapleader=" " " Set the mapleader to be space - " Plugins {{{ " Installation {{{ +" Install vim-plug if needed +if empty(glob('~/.vim/autoload/plug.vim')) + silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" + autocmd VimEnter * PlugInstall | source $MYVIMRC +endif + call plug#begin('~/.vim/plugged') " A color table with xterm color codes @@ -11,7 +16,7 @@ Plug 'guns/xterm-color-table.vim' " Simple commenting Plug 'tpope/vim-commentary' -" Emmet - must-have for HTML, awesome snippet expansion +" Emmet - must-have for HTML, awesome tag expansion Plug 'mattn/emmet-vim' " Sleuth - set tab options based on current file @@ -29,10 +34,13 @@ Plug 'tpope/vim-eunuch' " Markdown in vim (better than built-in) Plug 'plasticboy/vim-markdown' +" Aligning and filtering text Plug 'godlygeek/tabular' +" A tag overview on the right side Plug 'majutsushi/tagbar' +" Personal hypertext files Plug 'vimwiki/vimwiki' " Git wrapper from tpope @@ -41,12 +49,14 @@ Plug 'tpope/vim-fugitive' " Undo tree visualiser Plug 'simnalamburt/vim-mundo' +" Quickfix window mappings Plug 'romainl/vim-qf' " Repeat everything with '.' Plug 'tpope/vim-repeat' " Distraction-free editing +" problem starts here Plug 'junegunn/goyo.vim' " Better CSV editing @@ -58,31 +68,42 @@ Plug 'vim-scripts/AnsiEsc.vim' " Disable hlsearch after finished searching Plug 'romainl/vim-cool' +" Vim + latex Plug 'lervag/vimtex' +" Snippets Plug 'SirVer/ultisnips' +" Improve K Plug 'gastonsimone/vim-dokumentary' +" Open devdocs for a keyword Plug 'romainl/vim-devdocs' +" Fuzzy finder in vim Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } Plug 'junegunn/fzf.vim' +" Better abbrevation and substitution Plug 'tpope/vim-abolish' +" An improved grep Plug 'rking/ag.vim' +" Highlight hex colors Plug 'chrisbra/colorizer' +" Pywal scheme in vim Plug 'dylanaraps/wal.vim' +" Documentation skeleton generator Plug 'kkoomen/vim-doge' -Plug 'mhinz/vim-signify' + +" Show git changes in the sign column +Plug 'airblade/vim-gitgutter' call plug#end() " }}} " Config {{{ - " Tagbar {{{ " Maps nnoremap <leader>tt :TagbarToggle<CR> @@ -136,49 +157,47 @@ let g:tagbar_type_markdown = { \ 'sort': 0 \ } " }}} - +" Doge {{{ let g:doge_mapping = '<leader>gd' - +" }}} +" Goyo {{{ let g:goyo_width = 120 - +" }}} " Vimtex {{{ let g:tex_flavor='latex' let g:vimtex_view_method='general' let g:vimtex_quickfix_mode=0 let g:tex_conceal='abdmg' " }}} - " Ultisnips {{{ let g:UltiSnipsExpandTrigger = '<tab>' let g:UltiSnipsJumpForwardTrigger = '<tab>' let g:UltiSnipsJumpBackwardTrigger = '<s-tab>' let g:UltiSnipsSnippetDirectories = [$DOTFILES.'/vim/ultisnips'] let g:UltiSnipsEditSplit = "vertical" -let g:vimwiki_table_mappings = 0 " avoid vimwiki conflict cabbrev USE UltiSnipsEdit " }}} - " Dokumentary {{{ " Improve what K does let g:dokumentary_docprgs = {'ruby': 'ri {0} | col -b'} " }}} - " Abolish {{{ " Work with variants of words easily let g:abolish_save_file = $DOTFILES.'/vim/abolish_save_file.vim' " }}} - - +" Fzf {{{ set rtp+=~/.fzf let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-i': 'split', \ 'ctrl-v': 'vsplit' } +" }}} " Vimwiki {{{ nmap <leader><CR> <Plug>VimwikiSplitLink nmap <leader>v<CR> <Plug>VimwikiVSplitLink let tlist_vimwiki_settings = 'wiki;h:Headers' +let g:vimwiki_table_mappings = 0 " avoid vimwiki conflict with Ultisnips let wiki = {} let wiki.path = '/Users/alex/Dropbox/vimwiki/' @@ -192,10 +211,7 @@ let g:vimwiki_ext2syntax = {'.wiki': 'default'} " }}} " }}} " General {{{ -" Update file when changed from the outside -" set autoread - -" tags files +" where to find tags files set tags=./tags,tags,.git/tags " matchit.vim is default, why not enable it @@ -233,7 +249,7 @@ set hidden " Dont redraw while executing macros set lazyredraw -" Encoding +" Encoding & formats set encoding=utf-8 nobomb set fileencoding=utf-8 set fileencodings=utf-8 @@ -262,19 +278,15 @@ endif colorscheme wal set notermguicolors - " Show partial command on last line set showcmd " Command completion set wildmenu -" Enable dark background +" Use colors that work on a dark background set background=dark -" Enable 256 colormode -" set t_Co=256 - " Mouse tweak set mousemodel=popup @@ -283,14 +295,14 @@ set laststatus=2 " Always sho 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+=%{StatuslineTabWarning()} " Inconsistent indentation warning -set statusline+=%{StatuslineTrailingSpaceWarning()} " Trailing whitespace warning +set statusline+=%{statusline#StatuslineTabWarning()} " Inconsistent indentation warning +set statusline+=%{statusline#StatuslineTrailingSpaceWarning()} " Trailing whitespace warning set statusline+=%* " Clear highlighting set statusline+=%< " Start truncating here if exists('g:loaded_fugitive') " If fugitive is in use set statusline+=\ %{FugitiveStatusline()} " add fugitive status to the statusline endif " end -set statusline+=\ \ %{StatuslineBuildCwd()} " Current working directory, replacing home with ~ +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 @@ -305,54 +317,9 @@ augroup statusline autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning augroup END - -" return '[&et]' if &et is set wrong -" return '[mixed-indenting]' if spaces and tabs are used to indent -" return an empty string if everything is fine -function! StatuslineTabWarning() - if &readonly || &bt == "nofile" - return "" - endif - - if !exists("b:statusline_tab_warning") - let tabs = search('^\t', 'nw') != 0 - let spaces = search('^ ', 'nw') != 0 - - if tabs && spaces - let b:statusline_tab_warning = '[mixed-indenting]' - elseif (spaces && !&et) || (tabs && &et) - let b:statusline_tab_warning = '[&et]' - else - let b:statusline_tab_warning = '' - endif - endif - return b:statusline_tab_warning -endfunction - -" return '[\s]' if trailing white space is detected -" return '' otherwise -function! StatuslineTrailingSpaceWarning() - if &readonly || &bt == "nofile" - return "" - endif - - if !exists("b:statusline_trailing_space_warning") - if search('\s\+$', 'nw') != 0 - let b:statusline_trailing_space_warning = '[\s]' - else - let b:statusline_trailing_space_warning = '' - endif - endif - return b:statusline_trailing_space_warning -endfunction - -" build the current working directory string -function! StatuslineBuildCwd() - let cwd = substitute(getcwd(),$HOME,'~','g') - return "CWD: " . cwd -endfunction " }}} + highlight ColorColumn ctermbg=233 " How to split new windows @@ -386,7 +353,7 @@ endif " Highlight current line set cursorline -" Text wrap sucks +" Text wrap sucks most of the time set nowrap " Linebreak when obsessive @@ -404,7 +371,6 @@ set number set numberwidth=3 set relativenumber - " with a smart tab set smarttab @@ -414,10 +380,12 @@ set expandtab " use spaces instead of tabs set shiftwidth=2 " 2 spaces when >> set softtabstop=2 " and when pressing TAB set shiftround " always shift by multiple of shiftwidth -set copyindent " smart indent based on file " Auto indent when starting new line set autoindent +set copyindent " copy structure of other indents whn autoindenting + +" Enable indenting based on filetype filetype plugin indent on " Syntax highlighting @@ -449,121 +417,6 @@ set completeopt=longest,menuone,preview " Keep cursor off top and bottom of screen set scrolloff=5 " }}} -" Functions {{{ -function! ToggleNumber() abort - if(&relativenumber == 1) - set norelativenumber - set number - else - set relativenumber - endif -endfunc - -function! Redir(cmd) abort - for win in range(1, winnr('$')) - if getwinvar(win, 'scratch') - execute win . 'windo close' - endif - endfor - if a:cmd =~ '^!' - execute "let output = system('" . substitute(a:cmd, '^!', '', '') . "')" - else - redir => output - execute a:cmd - redir END - endif - vnew - let w:scratch = 1 - setlocal nobuflisted buftype=nofile bufhidden=wipe noswapfile - call setline(1, split(output, "\n")) -endfunction - -function! 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 - -" Show syntax highlighting groups for word under cursor -function! SynStack() - if !exists("*synstack") - return - endif - echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")') -endfunc - -" Custom session management (should be plugin) {{{ -function! SaveSession() abort - let seshdir = $HOME.'/.vim/sessions/' - silent call mkdir (seshdir, 'p') - let name = input("Save as: ") - if name == "" - echo "\nNo name provided." - else - let seshfile = seshdir.name.".vim" - execute "mksession! " . seshfile - echo "\nSession saved: ".seshfile - endif -endfunction -function! ListSessions() abort - let seshdir = $HOME.'/.vim/sessions/' - silent call mkdir (seshdir, 'p') - let files = globpath(seshdir, '*', 0, 1) - call filter(files, '!isdirectory(v:val)') - return files -endfunction -function! ChooseSession() abort - let files = ListSessions() - if len(files) > 0 - let inputfiles = map(copy(files), 'index(files, v:val)+1.": ".v:val') - let response = inputlist(inputfiles) - if response > 0 - return files[response-1] - else - return "" - endif - else - echo "No sessions available." - return "" - endif -endfunction -function! LoadSession() abort - let session = ChooseSession() - if session != "" - execute 'source '.session - else - echo "\nNo session selected." - endif -endfunction -function! DeleteSession() abort - let sesh = ChooseSession() - if sesh == "" - echo "\nNo session selected" - return 1 - endif - let conf = confirm("Delete ".sesh."?", "&Yes\n&No\n", 2) - if conf == 1 - if delete(sesh) == 0 - echom "Deleted ".sesh - else - echom "Couldn't delete ".sesh - endif - else - echom "No action taken." - endif -endfunction -function! CloseSession() - bufdo! bwipeout - cd - if g:loaded_tagbar == 1 - execute "TagbarClose" - endif - echom "Session closed." -endfunction -" }}} -" }}} " Commands {{{ command! Light set background=light termguicolors | colorscheme kuroi command! Dark set background=dark termguicolors | colorscheme junipero @@ -585,8 +438,8 @@ 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() -command! -nargs=1 -complete=command Redir silent call Redir(<f-args>) +command! DeleteHiddenBuffers call deletehiddenbuffers#DeleteHiddenBuffers() +command! -nargs=1 -complete=command Redir silent call redir#Redir(<f-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 @@ -716,7 +569,7 @@ 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()<CR> +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' : '^' @@ -753,10 +606,10 @@ nnoremap <leader>yy yg_ nnoremap <leader>td 0f-l"aywf:l"byw0"cywf:l"dywA (=((a*60+b)-(c*60+d))/60.0 )F.r:wyw"aywcw=0.a*60 F.2xih0:s/:0h/h " Custom session maps -nnoremap <leader>ss :call SaveSession()<CR> -nnoremap <leader>sl :call LoadSession()<CR> -nnoremap <leader>sd :call DeleteSession()<CR> -nnoremap <leader>sq :call CloseSession()<CR> +nnoremap <leader>ss :call sessions#SaveSession()<CR> +nnoremap <leader>sl :call sessions#LoadSession()<CR> +nnoremap <leader>sd :call sessions#DeleteSession()<CR> +nnoremap <leader>sq :call sessions#CloseSession()<CR> " native file browsing nnoremap <leader>f :Lexplore<CR> @@ -767,7 +620,7 @@ nmap <leader>$ <Plug>StripTrailingWhitespace nnoremap H :bprevious<CR> nnoremap L :bnext<CR> -nmap <C-S-P> :call SynStack()<CR> +nmap <C-S-P> :call synstack#SynStack()<CR> inoremap <C-p> <esc>m`[s1z=``a @@ -781,16 +634,11 @@ if has('autocmd') autocmd InsertEnter * setlocal nocursorline autocmd InsertLeave * setlocal cursorline augroup END - +" this is a comment augroup mappings autocmd! autocmd BufEnter *.tex nnoremap <leader>tt :VimtexTocToggle<CR> autocmd BufLeave *.tex nnoremap <leader>tt :TagbarToggle<CR> augroup END endif -" Install vim-plug if needed -if empty(glob('~/.vim/autoload/plug.vim')) - silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim" - autocmd VimEnter * PlugInstall | source $MYVIMRC -endif " }}}