My vim configuration
git clone https://github.com/m-col/vim-misc
Files | Refs | Readme

Commit 49f2cfeb869d280b6f633cf435c30089ae2c4ad9
Parent: d5d8393d621b5f38b6fe8701b3b0ca6579bde9a7
Author: mcol <mcol@posteo.net>
Date: 2019-12-31 11:17:56 +0000
Committer: mcol <mcol@posteo.net>
Committed: 2019-12-31 11:17:56 +0000

Purge vimrc; add noscrollbar and gitgutter

vimrc Modified

@@ -22,8 +22,10 @@
 
 if stridx(hostname(), "book")
     Plugin 'vimwiki/vimwiki'		    " vimwiki
-    "Plugin 'm-col/vimlab'		    " vimlab
+    "Plugin 'gu-fan/riv.vim'
+    Plugin 'm-col/vimlab'		    " vimlab
     "Plugin 'lervag/vimtex'		    " vimtex
+    Plugin 'airblade/vim-gitgutter'	    " gitgutter
 endif
 
 Plugin 'm-col/vim-misc'			    " my vimrc and misc functions 
@@ -99,45 +101,33 @@
 	    \ |   exe "normal! g`\""
 	    \ | endif
 
-" netrw
-nmap <C-n> :Explore<CR>
-let g:netrw_sort_sequence='[\/]$'
-
 " machine specific settings
-if hostname() == "zenbook"
+if stridx(hostname(), "book")
 
-    "packadd! matchit		" needed for matlab indentation functionality
+    packadd! matchit		" needed for matlab indentation functionality
     "let g:mlint_path_to_mlint = expand("$HOME") . "/applications/MATLAB/R2018b/bin/glnxa64/mlint"
+    let g:vimlab_session = "~/.vim/sessions/matlab-session.vim"
 
-    let g:vimwiki_list = [{'path': '~/work/research/research.wiki/', 'path_html': '~/work/research/research.wiki.html/'}]
+    " potentially unneeded
+    "let g:vimwiki_list = [{'path': '~/work/research/research.wiki/', 'path_html': '~/work/research/research.wiki.html/'}]
 
     "let g:vimtex_view_general_viewer = 'qpdfview'
     "let g:vimtex_view_general_options = '--unique @pdf\#src:@tex:@line:@col'
     "let g:vimtex_view_general_options_latexmk = '--unique'
+    "let g:vimtex_view_qpdfview_hook_callback = 'ViewerCallback'
+    "function! ViewerCallback() dict
+    "    VimtexView
+    "endfunction
+
+    let g:gitgutter_enabled = 0
 endif
 
-" session saving
-"let g:vimlab_session = "~/.vim/sessions/matlab-session.vim"
-
-"" Intelligently navigate tmux panes and Vim splits using the same keys.
-"" See https://sunaku.github.io/tmux-select-pane.html for documentation.
-"let progname = substitute($VIM, '.*[/\\]', '', '')
-"if empty(v:servername)
-"    set title titlestring=%{progname}\ [%n]\ %F
-"else
-"    set title titlestring=%{progname}\ [%{v:servername}]\ [%n]\ %F
-"endif
-"if &term =~ '^screen' && !has('nvim') | exe "set t_ts=\e]2; t_fs=\7" | endif
-"
-"let g:vimtex_view_qpdfview_hook_callback = 'ViewerCallback'
-"function! ViewerCallback() dict
-"    VimtexView
-"endfunction
-
-" disable middle click paste (restoring xterm middle click open url)
-"map <MiddleMouse> <Nop>
-"imap <MiddleMouse> <Nop>
-
-" flake8 settings
-"let g:flake8_show_in_gutter=1
-"let g:flake8_show_in_file=1
+" Intelligently navigate tmux panes and Vim splits using the same keys.
+" See https://sunaku.github.io/tmux-select-pane.html for documentation.
+let progname = substitute($VIM, '.*[/\\]', '', '')
+if empty(v:servername)
+    set title titlestring=%{progname}\ [%n]\ %F
+else
+    set title titlestring=%{progname}\ [%{v:servername}]\ [%n]\ %F
+endif
+if &term =~ '^screen' && !has('nvim') | exe "set t_ts=\e]2; t_fs=\7" | endif

tmux.conf Modified

@@ -92,4 +92,3 @@
 bind-key -n C-j run-shell -b "$navigate_down"
 bind-key -n C-k run-shell -b "$navigate_up"
 bind-key -n C-l run-shell -b "$navigate_right"
-bind-key -n C-\ run-shell -b "$navigate_back"

plugin/theme.vim Modified

@@ -12,12 +12,15 @@
 if ! empty($TMUX)
     set statusline +=%6*%*
 endif
+
 set statusline +=%1*\ \ %<%F\ \ %*	    " full path
 set statusline +=%2*\ \ %y%*                " file type
 set statusline +=%2*\ %m\ %*                " modified flag
-set statusline +=%3*%=%*		    " centre padding
-set statusline +=%4*\ \ %l\ /\ %L\ \ %*	    " current / total lines
-set statusline +=%5*\ %n\ %*		    " buffer number 
+set statusline +=%3*%{noscrollbar#statusline(12,'\ ','-')}
+set statusline +=%4*%=%*		    " centre padding
+set statusline +=%5*\ \ %l\ /\ %L\ \ %*	    " current / total lines
+set statusline +=%1*\ %n\ %*		    " buffer number 
+
 hi User1 ctermfg=0 ctermbg=5 cterm=none 
 hi User2 ctermfg=0 ctermbg=4 cterm=none 
 hi User3 ctermfg=0 ctermbg=14 cterm=none 
@@ -71,5 +74,5 @@
 "augroup END
 
 " character for split barrier
-"set fillchars=vert:\ 
-"hi VertSplit cterm=bold term=bold ctermbg=12
+set fillchars=vert:\ 
+hi VertSplit cterm=bold term=bold ctermbg=12

plugin/noscrollbar.vim Added

@@ -0,0 +1,115 @@
+"------------------------------------------------------------------"
+" noscrollbar plugin from github.com/gcavallanti/vim-noscrollbar
+"------------------------------------------------------------------"
+if &cp || exists('g:noscrollbar_loaded')
+  finish
+endif
+
+let g:noscrollbar_loaded = 1
+
+function! noscrollbar#statusline(...)
+    let top_line = line("w0")
+    let bottom_line = line("w$")
+    let current_line = line('.')
+    let lines_count = line('$')
+
+    " Default values
+    let length = 20
+    let tracksymbol = '-'
+    let grippersymbol = '#'
+    let gripperleftsymbols = []
+    let gripperrightsymbols = []
+    let part = 'a'
+
+    if a:0 >= 3
+      let length = a:1
+      let tracksymbol = a:2
+      let grippersymbol = a:3
+    endif
+
+    if a:0 >= 5 && type(a:4) == 3 && type(a:5) == 3
+                \ && len(a:4) == len(a:5) 
+        let gripperleftsymbols = a:4
+        let gripperrightsymbols = a:5
+    endif
+
+    if a:0 >= 6
+      let part = a:6
+    endif
+
+    let scaling = len(gripperleftsymbols) + 1 
+
+    " Compute gripper position and size as if we have scaling times a:1
+    " characters available. Will shrink everything back just before returning 
+    let scrollbar_length = str2nr(length) * scaling
+
+    " Gripper positions are 0 based (0..scrollbar_length-1)
+    let gripper_position = float2nr((top_line - 1.0) / lines_count 
+\       * scrollbar_length)
+    let gripper_length = float2nr(ceil((bottom_line - top_line + 1.0)  
+\       / lines_count * scrollbar_length)) 
+
+    " Users expect to see the scrollbar in the leftmost position only if we
+    " are at the very top of the buffer
+    if (top_line > 1) && (gripper_position == 0)
+        " Since the top line is not visible shift the gripper by one position
+        let gripper_position = 1
+        if (gripper_position + gripper_length > scrollbar_length)
+            " Shrink the gripper if we end up after the end of the scrollbar 
+            let gripper_length = gripper_length - 1
+        endif
+    endif
+
+    if (bottom_line < lines_count) 
+\       && (gripper_position + gripper_length == scrollbar_length)
+        " As before, if the last line is not on the screen but the scrollbar
+        " seems to indicate so then either move the scrollbar position leftwise
+        " by one position or decrease its length
+        if gripper_position > 0
+            let gripper_position = gripper_position - 1
+        else
+            let gripper_length = gripper_length - 1
+        endif
+    endif
+
+    " Shrink everything back to the range [0, a:1)
+    let gripper_position = 1.0 * gripper_position / scaling
+    let gripper_length = 1.0 * gripper_length / scaling
+    let scrollbar_length = 1.0 * scrollbar_length / scaling
+
+    " The left of the gripper is broken in 3 parts.  The left and right are
+    " fractionals in the range [0, len(a:4)). 
+    let gripper_length_left = ceil(gripper_position) - gripper_position
+    " Hackish rounding errors workaround. If `gripper_length
+    " - gripper_lenght_left` is 0.9999.. we force it to 1 before rounding it
+    let gripper_length_middle = floor(round((gripper_length 
+                \ - gripper_length_left)*100.0)/100.0)
+    let gripper_length_right = gripper_length - gripper_length_left 
+                \ - gripper_length_middle
+
+    " Time to assemble the actual scrollbar
+    let scrollbar = ''
+    if part != 'm' && part != 'r'
+        let scrollbar .= repeat(tracksymbol, float2nr(floor(gripper_position)))
+
+        let grippersymbol_index = float2nr(round(gripper_length_left * scaling))
+        if grippersymbol_index != 0
+            let scrollbar .= gripperleftsymbols[grippersymbol_index - 1]
+        endif
+    endif
+    
+    if part != 'l' && part != 'r'
+        let scrollbar .= repeat(grippersymbol, float2nr(gripper_length_middle)) 
+    endif
+
+    if part != 'l' && part != 'm'
+        let grippersymbol_index = float2nr(round(gripper_length_right * scaling))
+        if grippersymbol_index != 0
+            let scrollbar .= gripperrightsymbols[grippersymbol_index - 1]
+        endif
+        let scrollbar .= repeat(tracksymbol, float2nr(scrollbar_length 
+                    \ - ceil(gripper_position + gripper_length)))
+    endif
+
+    return scrollbar
+endfunction

plugin/keybindings.vim Modified

@@ -8,6 +8,9 @@
 " toggle fold
 nnoremap <space> za
 
+" yank to end of line
+nnoremap Y y$
+
 " buffer navigation
 nnoremap <leader>b :ls<CR>:b<space>
 nnoremap <Leader>v :ls<CR>:vert sb<space>
@@ -31,20 +34,13 @@
 nnoremap :Q :q
 nnoremap :W :w
 
-" yank to end of line
-nnoremap Y y$
-
 " disable K man
 nnoremap K k
 
 " copy and paste system clipboard
-nnoremap <C-p> "+p
 nnoremap <C-y> "+y
 nnoremap <C-y><C-y> ms0v$"+y`s
-vnoremap <C-p> "+p
 vnoremap <C-y> "+y
-"next one needs fixing:
-"inoremap <C-p> <Esc>"+p
 inoremap <C-y> <Esc>"+y
 
 " save read-only file with sudo trick
@@ -107,3 +103,23 @@
 " quickfix navigation
 nnoremap <localleader>cn :cn<CR>
 nnoremap <localleader>cp :cp<CR>
+
+" netrw
+nmap <C-n> :Explore<CR>
+let g:netrw_sort_sequence='[\/]$'
+
+" disable middle click paste (restoring xterm middle click open url)
+map <MiddleMouse> <Nop>
+imap <MiddleMouse> <Nop>
+
+" gitgutter
+nmap <localleader>g :GitGutterToggle<CR>
+nmap gp <Plug>(GitGutterPreviewHunk)
+nmap gs <Plug>(GitGutterStageHunk)
+nmap gu <Plug>(GitGutterUndoHunk)
+nmap [g <Plug>(GitGutterPrevHunk)
+nmap ]g <Plug>(GitGutterNextHunk)
+omap ig <Plug>(GitGutterTextObjectInnerPending)
+omap ag <Plug>(GitGutterTextObjectOuterPending)
+xmap ig <Plug>(GitGutterTextObjectInnerVisual)
+xmap ag <Plug>(GitGutterTextObjectOuterVisual)

plugin/folds.vim Modified

@@ -4,31 +4,31 @@
 
 
 " format folded section header text
-function! GenericFoldText()
-    let line = getline(v:foldstart)
-
-    let nucolwidth = &fdc + &number * &numberwidth
-    let windowwidth = winwidth(0) - nucolwidth - 3
-    let foldedlinecount = v:foldend - v:foldstart
-
-    let onetab = strpart('          ', 0, &tabstop)
-    let line = substitute(line, '\t', onetab, 'g')
-
-    let line = strpart(line, 0, windowwidth - len(foldedlinecount))
-    let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
-    return line . repeat(" ",fillcharcount) . ' ' . foldedlinecount
-endfunction
-set foldtext=GenericFoldText()
-
-
-function! GenericFolds()
-    if match(getline(v:lnum), '^\s*' . &commentstring[0] . &commentstring[0]) >=0
-	return ">1"
-    else
-	return "="
-    endif
-endfunction
-
-
-set foldmethod=expr
-set foldexpr=GenericFolds()
+"function! GenericFoldText()
+"    let line = getline(v:foldstart)
+"
+"    let nucolwidth = &fdc + &number * &numberwidth
+"    let windowwidth = winwidth(0) - nucolwidth - 3
+"    let foldedlinecount = v:foldend - v:foldstart
+"
+"    let onetab = strpart('          ', 0, &tabstop)
+"    let line = substitute(line, '\t', onetab, 'g')
+"
+"    let line = strpart(line, 0, windowwidth - len(foldedlinecount))
+"    let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
+"    return line . repeat(" ",fillcharcount) . ' ' . foldedlinecount
+"endfunction
+"set foldtext=GenericFoldText()
+"
+"
+"function! GenericFolds()
+"    if match(getline(v:lnum), '^\s*' . &commentstring[0] . &commentstring[0]) >=0
+"	return ">1"
+"    else
+"	return "="
+"    endif
+"endfunction
+"
+"
+"set foldmethod=expr
+"set foldexpr=GenericFolds()

ftplugin/rst.vim Modified

@@ -1,3 +1,7 @@
 setlocal textwidth=79
-setlocal spell spelllang=en_gb
+"setlocal spell spelllang=en_gb
 nnoremap <localleader>c :mkview<CR>gqip:silent loadview<CR>
+
+nnoremap <localleader>t= mt0yypv$r=
+nnoremap <localleader>t- mt0yypv$r-
+nnoremap <localleader>t' mt0yypv$r'

ftplugin/python.vim Modified

@@ -1,5 +1,5 @@
 setlocal tabstop=4
 setlocal softtabstop=4
 setlocal shiftwidth=4
-setlocal textwidth=79
+setlocal textwidth=88
 setlocal expandtab