Add Neovim configs
dblume

dblume commited on 2024-03-06 22:50:15
Showing 8 changed files, with 1005 additions and 12 deletions.


This is the first cut, and there will be multiple subsequent changes.
... ...
@@ -0,0 +1,113 @@
1
+" Vim color file
2
+" Maintainer:	Hans Fugal <hans@fugal.net>
3
+" Last Change:	$Date: 2004/06/13 19:30:30 $
4
+" Last Change:	$Date: 2004/06/13 19:30:30 $
5
+" URL:		http://hans.fugal.net/vim/colors/desert.vim
6
+" Version:	$Id: desert.vim,v 1.1 2004/06/13 19:30:30 vimboss Exp $
7
+
8
+" cool help screens
9
+" :he group-name
10
+" :he highlight-groups
11
+" :he cterm-colors
12
+
13
+set background=dark
14
+if version > 580
15
+    " no guarantees for version 5.8 and below, but this makes it stop
16
+    " complaining
17
+    hi clear
18
+    if exists("syntax_on")
19
+	syntax reset
20
+    endif
21
+endif
22
+let g:colors_name="desert"
23
+
24
+hi Normal	guifg=White guibg=grey20
25
+
26
+" highlight groups
27
+hi Cursor	guibg=khaki guifg=slategrey
28
+"hi CursorIM
29
+"hi Directory
30
+"hi DiffAdd
31
+"hi DiffChange
32
+"hi DiffDelete
33
+"hi DiffText
34
+"hi ErrorMsg
35
+hi VertSplit	guibg=#c2bfa5 guifg=grey50 gui=none
36
+hi Folded	guibg=grey30 guifg=gold
37
+hi FoldColumn	guibg=grey30 guifg=tan
38
+hi IncSearch	guifg=slategrey guibg=khaki
39
+"hi LineNr
40
+hi ModeMsg	guifg=goldenrod
41
+hi MoreMsg	guifg=SeaGreen
42
+hi NonText	guifg=LightBlue guibg=grey30
43
+hi Question	guifg=springgreen
44
+hi Search	guibg=peru guifg=wheat
45
+hi SpecialKey	guifg=yellowgreen
46
+hi StatusLine	guibg=#c2bfa5 guifg=black gui=none
47
+hi StatusLineNC	guibg=#c2bfa5 guifg=grey50 gui=none
48
+hi Title	guifg=indianred
49
+hi Visual	gui=none guifg=khaki guibg=olivedrab
50
+"hi VisualNOS
51
+hi WarningMsg	guifg=salmon
52
+"hi WildMenu
53
+"hi Menu
54
+"hi Scrollbar
55
+"hi Tooltip
56
+
57
+" syntax highlighting groups
58
+hi Comment	guifg=SkyBlue
59
+hi Constant	guifg=#ffa0a0
60
+hi Identifier	guifg=palegreen
61
+hi Statement	guifg=khaki
62
+hi PreProc	guifg=indianred
63
+hi Type		guifg=darkkhaki
64
+hi Special	guifg=navajowhite
65
+"hi Underlined
66
+hi Ignore	guifg=grey40
67
+"hi Error
68
+hi Todo		guifg=orangered guibg=yellow2
69
+
70
+" color terminal definitions
71
+hi SpecialKey	ctermfg=darkgreen
72
+hi NonText	cterm=bold ctermfg=darkblue
73
+hi Directory	ctermfg=darkcyan
74
+hi ErrorMsg	cterm=bold ctermfg=7 ctermbg=1
75
+hi IncSearch	cterm=NONE ctermfg=yellow ctermbg=green
76
+hi Search	cterm=NONE ctermfg=grey ctermbg=25
77
+hi MoreMsg	ctermfg=darkgreen
78
+hi ModeMsg	cterm=NONE ctermfg=brown
79
+hi LineNr	ctermfg=3
80
+hi Question	ctermfg=green
81
+hi StatusLine	cterm=bold,reverse
82
+hi StatusLineNC cterm=reverse
83
+hi VertSplit	cterm=reverse
84
+hi Title	ctermfg=74
85
+hi Visual	cterm=reverse
86
+hi VisualNOS	cterm=bold,underline
87
+hi WarningMsg	ctermfg=1
88
+hi WildMenu	ctermfg=0 ctermbg=3
89
+hi Folded	ctermfg=darkgrey ctermbg=NONE
90
+hi FoldColumn	ctermfg=darkgrey ctermbg=NONE
91
+hi DiffAdd      term=reverse ctermbg=28 ctermfg=254
92
+hi DiffChange   term=reverse ctermbg=239 ctermfg=251
93
+hi DiffText     term=reverse ctermbg=30 ctermfg=254
94
+hi DiffDelete   term=reverse ctermbg=52 ctermfg=black
95
+hi Comment	ctermfg=darkcyan
96
+hi Constant	ctermfg=brown
97
+hi Special	ctermfg=74
98
+hi Identifier	ctermfg=6
99
+hi Statement	ctermfg=3
100
+hi PreProc	ctermfg=74
101
+hi Type		ctermfg=2
102
+hi Underlined	cterm=underline ctermfg=74
103
+hi Ignore	cterm=bold ctermfg=7
104
+hi Ignore	ctermfg=darkgrey
105
+hi Error	cterm=bold ctermfg=7 ctermbg=1
106
+hi Pmenu	ctermbg=33 ctermfg=235
107
+hi PmenuSel	ctermbg=14 ctermfg=0
108
+hi TabLineSel	ctermfg=white ctermbg=239
109
+hi TabLine	ctermfg=247 ctermbg=237
110
+hi TabLineFill	ctermfg=235
111
+
112
+
113
+"vim: sw=4
... ...
@@ -0,0 +1,393 @@
1
+" Version 2024-03-06.1 - Original, with many bugs
2
+set bs=2            " allow backspacing over everything in insert mode
3
+set wildmenu        " Allows command-line completion with tab
4
+set autoindent      " Copy indent from current line when starting a new line
5
+set smartindent     " Do smart auto indenting when starting  new line
6
+set smarttab        " Honor 'shiftwidth', 'tabstop' or 'softtabstop'
7
+set hlsearch        " highlight all matches for previous search
8
+set foldlevel=99
9
+set nowrap          " no wrapping text lines on the screen (exceptions below)
10
+set sidescroll=5
11
+set listchars+=tab:>-,precedes:<,extends:>,nbsp:· " for :set list
12
+set iskeyword+=-    " Add - to list of non-word-breaking chars.
13
+set scrolloff=0     " EC2 defaults to 5. Set explicitly to be consistent
14
+set notermguicolors " Only needed for neovim while I port my color schemes
15
+
16
+if v:version >= 703
17
+  " Do save the undo tree to file, but not in the local directory.
18
+  " Don't forget to mkdir ~/.nvim_undo
19
+  set undodir=~/.nvim_undo,.
20
+  set undofile        " undo even after closing and reopening a file
21
+endif
22
+
23
+" The following two lines set the use of perl regex, aka "very magic"
24
+nnoremap / /\v
25
+vnoremap / /\v
26
+
27
+" Make j and k move to the next row, not file line
28
+nnoremap j gj
29
+nnoremap k gk
30
+
31
+" From Steve Losh: http://learnvimscriptthehardway.stevelosh.com/chapters/10.html
32
+" Map jk to ESC in insert mode (except when navigating popup menu)
33
+inoremap <expr> jk pumvisible() ? '' : '<esc>'
34
+inoremap <expr> j pumvisible() ? '<Down>' : 'j'
35
+inoremap <expr> k pumvisible() ? '<Up>' : 'k'
36
+
37
+" https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
38
+nnoremap <leader>v <C-w>v<C-w>l
39
+nnoremap <C-h> <C-w>h
40
+nnoremap <C-j> <C-w>j
41
+nnoremap <C-k> <C-w>k
42
+nnoremap <C-l> <C-w>l
43
+
44
+" clear search highlights
45
+nnoremap <cr> :noh<cr><cr>
46
+
47
+" tab switches to previous/next buffer
48
+nnoremap <Tab> :bp<cr>
49
+nnoremap <S-Tab> :bn<cr>
50
+
51
+syntax on
52
+
53
+set t_Co=256
54
+if v:version >= 703
55
+"  set colorcolumn=80
56
+endif
57
+if has('gui_running') " Didn't work: if &term != 'builtin_gui'
58
+  " Light backgrounds for GUI experiences
59
+  set background=light
60
+  " colorscheme peaksea
61
+  colorscheme tolerable
62
+  if v:version >= 703
63
+    highlight ColorColumn ctermbg=255 guibg=#F6F6F6
64
+  endif
65
+  highlight statusline   ctermfg=17 ctermbg=Gray " override scheme
66
+  highlight statuslineNC ctermfg=20 ctermbg=LightGray" override scheme
67
+  if has('win32')
68
+    set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
69
+  endif
70
+  set lines=50 columns=100
71
+else
72
+  " Dark backgrounds for tty experiences
73
+  set background=dark
74
+  colorscheme nvim_desert
75
+  if v:version >= 703
76
+    highlight ColorColumn ctermbg=233 guibg=Black " dark gray (or 17, dark blue)
77
+  endif
78
+  highlight statusline   ctermfg=24 ctermbg=250  " override scheme
79
+  highlight statuslineNC ctermfg=236 ctermbg=Gray  " override scheme
80
+  highlight MatchParen   term=reverse ctermbg=23  " 23 is more subtle than default
81
+endif
82
+
83
+au InsertEnter * hi statusline guibg=Cyan ctermfg=20 guifg=Black ctermbg=248
84
+au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=24 ctermbg=250 guifg=black guibg=#c2bfa5
85
+
86
+" set mouse=v     " visual mode, not working great for PuTTY
87
+
88
+set tags=tags;/
89
+
90
+set history=50
91
+set laststatus=2
92
+
93
+function! StatuslineGit()
94
+  let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
95
+  return strlen(l:branchname) > 0 ? ' | branch:'.l:branchname : ''
96
+endfunction
97
+
98
+function! Current_mode()
99
+  let l:currentmode={
100
+    \ 'n'  : 'NORMAL',
101
+    \ 'v'  : 'VISUAL',
102
+    \ 'V'  : 'V·LINE',
103
+    \ '' : 'V·BLOCK',
104
+    \ 's'  : 'SELECT',
105
+    \ 'S'  : 'S·LINE',
106
+    \ 'i'  : 'INSERT',
107
+    \ 'r'  : 'I·REPLACE',
108
+    \ 'R'  : 'REPLACE',
109
+    \ 'Rv' : 'V·REPLACE',
110
+    \ 'c'  : 'COMMAND',
111
+    \}
112
+    return get(l:currentmode, mode(), mode())
113
+endfunction
114
+
115
+function! Trim_brackets(fn)
116
+  if v:version > 800
117
+    return trim(a:fn, "[]")
118
+  else
119
+    return a:fn
120
+  endif
121
+endfunction
122
+
123
+set statusline=\ %{Current_mode()}
124
+set statusline+=%{&paste?'\ \ ·\ PASTE':''}
125
+"set statusline+=%{StatuslineGit()}
126
+set statusline+=\ │\ %f
127
+set statusline+=%m
128
+set statusline+=\ %r
129
+set statusline+=\ %=
130
+set statusline+=%h
131
+set statusline+=\ %{Trim_brackets(&filetype)}
132
+set statusline+=\ %#StatusLineNC#
133
+set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
134
+set statusline+=\[%{&fileformat}\]
135
+set statusline+=\ │\ %p%%\ =
136
+set statusline+=\ %l/%L\ :\ %c\ 
137
+
138
+set encoding=utf-8
139
+
140
+" Fast saving
141
+nmap <leader>w :w!<cr>
142
+" I use relative number for cursor movement.
143
+nmap <leader>r :set relativenumber!<cr>
144
+nmap <leader>n :set number!<cr>
145
+
146
+" Useful mappings for managing tabs
147
+" Tab Previous: gT or C-PageUp
148
+" Tab Next: gt or C-PageDown
149
+nmap <leader>tn :tabnew
150
+nmap <leader>to :tabonly<cr>
151
+nmap <leader>tc :tabclose<cr>
152
+nmap <leader>tm :tabmove
153
+nmap <leader>1 1gt
154
+nmap <leader>2 2gt
155
+nmap <leader>3 3gt
156
+nmap <leader>4 4gt
157
+nmap <leader>5 5gt
158
+nmap <leader>6 6gt
159
+nmap <leader>7 7gt
160
+nmap <leader>8 8gt
161
+nmap <leader>9 9gt
162
+
163
+" Open current buffer in new tab. Close with C-w,c
164
+" https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
165
+function! OpenCurrentAsNewTab()
166
+    let l:currentView = winsaveview()
167
+    tabedit %
168
+    call winrestview(l:currentView)
169
+endfunction
170
+nmap <leader>o :call OpenCurrentAsNewTab()<CR>
171
+
172
+" pastetoggle
173
+nmap <leader>p :set invpaste paste?<cr>
174
+
175
+" Control+p to paste onto next line
176
+nmap <C-p> :pu<cr>
177
+
178
+" Make netrw's Explore behave a little like NERDTreeToggle
179
+" http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
180
+function! ToggleNetrw()
181
+  if bufwinnr("NetrwTreeListing") > 0
182
+    for i in range(1, bufnr("$"))
183
+      if (getbufvar(i, "&filetype") == "netrw")
184
+        silent exe "bwipeout " . i
185
+        return
186
+      endif
187
+    endfor
188
+  endif
189
+  silent Vexplore %:p:h
190
+endfunction
191
+nmap <leader>e :call ToggleNetrw()<cr>
192
+
193
+" install taglist
194
+let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
195
+let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
196
+let Tlist_Close_On_Select = 1          " Close taglist window on select
197
+nmap <leader>l :TlistToggle<cr>
198
+
199
+" install vim-bbye
200
+nmap <leader>bd :Bdelete<cr>
201
+
202
+" Visual mode mappings
203
+"""
204
+
205
+" map sort function to a key
206
+vnoremap <leader>s :sort<cr>
207
+
208
+"easier moving of code blocks
209
+vnoremap < <gv
210
+vnoremap > >gv
211
+
212
+" If too many file system events are getting triggered.
213
+set nobackup       " ~ files
214
+set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
215
+set noswapfile     " .swp files
216
+
217
+" Allow tags to open another buffer even if this one is modified
218
+set hidden
219
+
220
+" Switch between source and header files
221
+function! SwitchSourceHeader()
222
+  let s:ext  = expand("%:e")
223
+  let s:base = expand("%:t:r")
224
+  let s:cmd  = "find " . s:base
225
+  if (s:ext == "cpp" || s:ext == "c")
226
+    if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
227
+    if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
228
+  else
229
+    if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
230
+    if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
231
+  endif
232
+endfunc
233
+
234
+" Demonstrates a way to look in a mirror directory
235
+" function! OpenOther()
236
+"    if expand("%:e") == "cpp"
237
+"      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
238
+"    elseif expand("%:e") == "h"
239
+"      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
240
+"    endif
241
+" endfunc
242
+
243
+" Delete trailing white space on save, useful for Python and CoffeeScript ;)
244
+function! DeleteTrailingWS()
245
+  exe "normal mz"
246
+  %s/\s\+$//ge
247
+  exe "normal `z"
248
+endfunc
249
+
250
+function! OpenInOtherWindow()
251
+  if winnr('$') == 1
252
+    exe "wincmd F"
253
+  else
254
+    let curNum = winnr()
255
+    let oldBuf = bufnr( "%" )
256
+    if curNum == 1
257
+      let othNum = 2
258
+    else
259
+      let othNum = 1
260
+    endif
261
+    exe "normal! gF"
262
+    let newBuf = bufnr( "%" )
263
+    let newLine = line(".")
264
+    exe 'hide buf' oldBuf
265
+    exe othNum . "wincmd w"
266
+    exe 'hide buf' newBuf
267
+    exe "normal! " . newLine . "G"
268
+  endif
269
+endfunc
270
+
271
+nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
272
+nmap <silent> <leader>f :call OpenInOtherWindow()<cr>
273
+
274
+if has("autocmd")
275
+  autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
276
+  " Don't let smartindent unindent the # character in Python files
277
+  autocmd FileType python  inoremap # X<c-h>#
278
+  autocmd FileType python,c,cpp,php,brs,sh  set expandtab  " Use spaces instead of tabs
279
+  autocmd Filetype make    setl noexpandtab       " ...not for files that use tabs.
280
+
281
+  " Use the vim command %retab before applying the following
282
+  " two with files that have 8-space tabs.
283
+  autocmd FileType c,cpp,python,php  set tabstop=4
284
+  autocmd FileType c,cpp,php  set shiftwidth=4
285
+
286
+  autocmd FileType python  set foldmethod=indent  " 'za' to fold
287
+
288
+  autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
289
+  autocmd FileType c,cpp set foldmethod=syntax
290
+
291
+  if v:version >= 703
292
+    " I toggle out of relative number when Vim's focus is lost, because
293
+    " if I'm not editing, then I may be referring to errors with line numbers.
294
+    autocmd FocusLost * if &relativenumber | set number | endif
295
+    autocmd FocusGained * if &number | set relativenumber | endif
296
+  endif
297
+
298
+  autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
299
+  autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
300
+  autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
301
+
302
+  " When editing a file, always jump to the last cursor position
303
+  autocmd BufReadPost *
304
+  \ if &ft != "p4changelist" && &ft != "gitcommit" && line("'\"") > 0 && line ("'\"") <= line("$") |
305
+  \   exe "normal! g'\"" |
306
+  \ endif
307
+endif
308
+
309
+" This requires vim to be compiled with +python
310
+" Use auto complete in insert mode with ctrl-x, ctrl-o
311
+" See :help new-omni-completion for more.
312
+filetype plugin on
313
+set omnifunc=syntaxcomplete#Complete
314
+
315
+" Torn on whether I like the omni completion preview window left open or not.
316
+" autocmd CompleteDone * pclose
317
+
318
+" Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
319
+inoremap <Nul> <C-x><C-o>
320
+
321
+" cscope
322
+if has("cscope")
323
+    set cscopetag  " Use both cscope and ctag for 'ctrl-]'
324
+    set csto=1     " 0=cscope first; 1=ctags first
325
+    set cscopequickfix=s-,c-,d-,i-,t-,e-,a- " cscope to quickfix window
326
+
327
+    set nocsverb
328
+    " add any database in current directory
329
+    if filereadable("cscope.out")
330
+        cs add cscope.out
331
+    " else add database pointed to by environment
332
+    elseif $CSCOPE_DB != ""
333
+        cs add $CSCOPE_DB
334
+    endif
335
+    set csverb
336
+endif
337
+
338
+" From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
339
+" :grep term %
340
+" :grep -r term path/
341
+" :cw
342
+" :ccl (or C-w,q)
343
+autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
344
+
345
+function! MaybeSortQuickfix(fn)
346
+"    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
347
+    let t = getqflist({'title': 1}).title
348
+    " Only sort the files if for search-style commands, not "make".
349
+    if stridx(t, "cs ") == 0 || stridx(t, ":gr") == 0 || stridx(t, ":vim") == 0 || stridx(t, ":rg") == 0
350
+        call setqflist(sort(getqflist(), a:fn), 'r')
351
+        call setqflist([], 'r', {'title': t})
352
+    endif
353
+    cwindow
354
+endfunction
355
+
356
+function! QfStrCmp(e1, e2)
357
+    let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
358
+    return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
359
+endfunction
360
+
361
+" Use ripgrep for search instead of grep
362
+if executable('rg')
363
+    " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
364
+    set grepprg=rg
365
+endif
366
+" Navigate quickfix list with ease
367
+nnoremap <silent> [q :cprevious<CR>
368
+nnoremap <silent> ]q :cnext<CR>
369
+
370
+" I use Roboto Mono from https://github.com/powerline/fonts
371
+" On iTerm2, Preferences -> Profiles -> Text -> Font
372
+" Cygwin64 won't let you choose it. Launch Cygwin64 as follows:
373
+" C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -o Font="Roboto Mono for Powerline" -
374
+
375
+" Settings that make netrw more like NERDTree
376
+let g:netrw_banner = 0
377
+let g:netrw_liststyle = 3
378
+let g:netrw_browse_split = 4
379
+let g:netrw_altv = 1
380
+" set g:netrw_winsize to negative for absolute width, positive for relative
381
+let g:netrw_winsize = -36
382
+" let g:netrw_winsize = 35
383
+" sort is affecting only: directories on the top, files below
384
+let g:netrw_sort_sequence = '[\/]$,*'
385
+
386
+" Experimenting with vim-rooter
387
+let g:rooter_patterns = ['.git', 'Makefile', 'builds/']
388
+let g:rooter_cd_cmd = 'lcd'
389
+let g:rooter_manual_only = 1
390
+
391
+" In some environments, Vim starts in replace mode:
392
+" https://superuser.com/questions/1284561/why-is-vim-starting-in-replace-mode
393
+" set t_u7=
... ...
@@ -0,0 +1,19 @@
1
+Copyright (c) 2023, David Blume
2
+
3
+Permission is hereby granted, free of charge, to any person obtaining
4
+a copy of this software and associated documentation files (the "Software"),
5
+to deal in the Software without restriction, including without limitation
6
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+and/or sell copies of the Software, and to permit persons to whom the
8
+Software is furnished to do so, subject to the following conditions:
9
+
10
+The above copyright notice and this permission notice shall be included
11
+in all copies or substantial portions of the Software.
12
+
13
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
14
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
+DEALINGS IN THE SOFTWARE.
... ...
@@ -0,0 +1,128 @@
1
+[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/dblume/gittab/main/LICENSE)
2
+![vim8](https://img.shields.io/badge/vim-8.x-green.svg)
3
+
4
+## Vim Git-Tab
5
+
6
+These are handy context-sensitive Git commands in Vim that load the results in
7
+a new tab. The commands infer what you want from the current filename and
8
+whether there's a commit hash under the cursor.
9
+
10
+These commands are for investigating the history of files. They are:
11
+
12
+* `Blame`
13
+* `Log`
14
+* `Show` and `ShowFile`
15
+* `Diff`
16
+
17
+This simple plugin is enough to do 95% of the Git dives I do. If you still want
18
+to do even more with Git while in Vim, consider Tim Pope's comprehensive
19
+[vim-fugitive](https://github.com/tpope/vim-fugitive).
20
+
21
+## Installation
22
+
23
+Install into Vim's built-in package support:
24
+
25
+    mkdir -p ~/.vim/pack/plugins/start
26
+    cd ~/.vim/pack/plugins/start
27
+    git clone --filter=blob:none -b main --single-branch https://github.com/dblume/gittab
28
+    vim -u NONE -c "helptags gittab/doc" -c q
29
+
30
+
31
+## Common Use Example
32
+
33
+Say you're on "index.html", and you need to know why a section looks the way
34
+it does. Run `:Blame` to see a buffer of "git blame" open at the same line
35
+where you are so you don't lose any context.
36
+
37
+Or run `:Log` to see a list of only the commits that _affect that file_. This
38
+is nice in a repo of thousands of commits, but only dozens are to this file.
39
+
40
+If you see a commit of interest, move the cursor over it, and type  `:Diff` to
41
+see what changes were made by that commit, or `:Show` to see the full commit
42
+description.
43
+
44
+Then you can keep exploring, and each command infers what you want by which
45
+type of buffer you're in or what commit your cursor is on.
46
+
47
+
48
+## The Commands
49
+
50
+When you're browsing a file in a Git repository, these commands provide a very
51
+simple and convenient flow for digging into their history.
52
+
53
+All you have to know is Blame, Log, Show, and Diff.
54
+
55
+The following image is an oversimplification, but shows that with the above
56
+four commands, one can easily and quickly navigate various views of a file and
57
+its commit history.
58
+
59
+![gittab.png](https://dblume.github.io/images/gittab.png)
60
+
61
+### :Blame
62
+
63
+When you're on a regular file or a `:ShowFile` buffer, opens up a `git blame` 
64
+buffer in a new tab and positions the cursor at the same relative spot in the
65
+Blame buffer.
66
+
67
+Example, run Blame on a `:ShowFile` buffer named "git show 1234abcd:README.md",
68
+and you get a `:Blame` buffer named "git blame 1234abcd -- README.md".
69
+
70
+### :Log
71
+
72
+When you're on a regular file or a `:ShowFile` buffer, opens up a `git log`
73
+buffer in a new tab for the commits that _affect only that file_. By default,
74
+runs log as:
75
+
76
+    git log --no-color --graph --date=short --pretty="format:%h %ad %s %an %d"
77
+
78
+And you can pass in additional Git arguments like `--all`.
79
+
80
+    :Log --all
81
+
82
+The reason Log defaults to one-line logs is because `:Show` and `:Diff` are so
83
+easy to use to dive in deeper to the individual commits.
84
+
85
+Handy arguments are `--all`, `--merges`, `--date-order`, `--first-parent`, and
86
+`--ancestry-path`.
87
+
88
+### :Show and :ShowFile
89
+
90
+These require the cursor to be positioned on a hash, so you'd most likely be
91
+in a `:Log` or `:Blame` buffer when you want to use these commands.
92
+
93
+When you're on a `:Log` or `:Blame` buffer  **`:Show`** opens a buffer in a
94
+new tab that shows the full commit message for the hash under the cursor.
95
+
96
+**`:ShowFile`** opens a buffer in a new tab that shows the contents of the file
97
+at the hash under the cursor.
98
+
99
+Ex., If the cursor is on "1234abcd" on `:Blame` buffer `git blame -- README.md`
100
+then:
101
+
102
+| Command   | Resultant Buffer |
103
+| ---       | ---              |
104
+| :Show     | git show 1234abcd -- README.md |
105
+| :ShowFile | git show 1234abcd:README.md |
106
+
107
+### :Diff
108
+
109
+If you're on a regular file that's different from HEAD, `:Diff` will perform a
110
+`git diff` on the file from HEAD. If it's the same as HEAD, then `:Diff` will
111
+perform a `git diff` against that file's previous commit.
112
+
113
+If the cursor is on a commit hash (as available on :Blame, :Log, and :Show 
114
+buffers), then `:Diff` will perform a diff against the previous commit to that
115
+one.
116
+
117
+If the active window is of a `:Diff` buffer, then `:Diff` will perform a
118
+`git diff` of that buffer with that revision's parent.
119
+
120
+## Is it any good?
121
+
122
+[Yes](https://news.ycombinator.com/item?id=3067434).
123
+
124
+The diagram was made with [Excalidraw](https://excalidraw.com/).
125
+
126
+## Licence
127
+
128
+This software uses the [MIT License](https://raw.githubusercontent.com/dblume/gittab/main/LICENSE.txt)
... ...
@@ -0,0 +1,107 @@
1
+*gittab.txt*  Plugin that provides simple Git functions in Vim
2
+
3
+                        _______ __     ______      __
4
+                       / ____(_) /_   /_  __/___ _/ /_
5
+                      / / __/ / __/    / / / __ `/ __ \
6
+                     / /_/ / / /_     / / / /_/ / /_/ /
7
+                     \____/_/\__/    /_/  \__,_/_.___/
8
+
9
+==============================================================================
10
+Gittab                                                                |gittab|
11
+Introduction ........................................... |gittab-introduction|
12
+Commands ................................................... |gittab-commands|
13
+  :Blame ............................................................ |:Blame|
14
+  :Log ................................................................ |:Log|
15
+  :Show .............................................................. |:Show|
16
+  :ShowFile ...................................................... |:ShowFile|
17
+  :Diff .............................................................. :|Diff|
18
+
19
+
20
+==============================================================================
21
+Introduction                                      *gittab* *gittab-introduction*
22
+
23
+These are handy context-sensitive Git commands in Vim that load the results in
24
+a new tab. The commands automatically infer what you want from the current
25
+filename and whether there's a commit hash under the cursor.
26
+
27
+These commands are for investigating the history of files. The supported
28
+commands are:
29
+
30
+  :Blame
31
+  :Log
32
+  :Show and :ShowFile
33
+  :Diff
34
+
35
+When you're browsing a file in a Git repository, these commands provide a very
36
+simple and convenient flow for digging into their history.
37
+
38
+All you have to know is Blame, Log, Show, and Diff.
39
+
40
+==============================================================================
41
+The Commands                                                 *gittab-commands*
42
+
43
+:Blame                                                                *:Blame*
44
+------
45
+
46
+When you're on a regular file or a `:ShowFile` buffer, opens up a "git blame"
47
+buffer in a new tab for the file at that commit, and positions the
48
+cursor at the same relative spot.
49
+
50
+Example, run Blame on a `:ShowFile` buffer named "git show 1234abcd:README.md",
51
+and you get a `:Blame` buffer named "git blame 1234abcd -- README.md".
52
+
53
+:Log {args}                                                             *:Log*
54
+-----------
55
+
56
+When you're on a regular file or a `:ShowFile` buffer, opens up a git log
57
+buffer in a new tab. By default, runs log as:
58
+
59
+    git log --no-color --graph --date=short --pretty="format:%h %ad %s %an %d"
60
+
61
+And you can pass in additional Git arguments like --all.
62
+
63
+    :Log --all
64
+
65
+The reason Log defaults to one-line logs is because `:Show` and `:Diff` are so
66
+easy to use to dive in deeper to the individual commits.
67
+
68
+Handy arguments are --all, --merges, --date-order, --first-parent, and
69
+--ancestry-path.
70
+                              
71
+:Show                                                                 *:Show*
72
+-----
73
+
74
+These require the cursor to be positioned on a hash, so you'd most likely be
75
+in a `:Log` or `:Blame` buffer when you want to use these commands.
76
+
77
+When you're on a `:Blame` buffer, a `:Log` buffer, `:Show` opens a
78
+buffer in a new tab that shows the full commit message for the hash under the
79
+cursor.
80
+
81
+:ShowFile                                                         *:ShowFile*
82
+---------
83
+
84
+`:ShowFile` opens a buffer in a new tab that shows the contents of the file
85
+at the hash under the cursor.
86
+
87
+Ex., If the cursor is on "1234abcd" on `:Blame` buffer "git blame -- README.md"
88
+then:
89
+
90
+| Command   | Resultant Buffer               |
91
+| ---       | ---                            |
92
+| :Show     | git show 1234abcd -- README.md |
93
+| :ShowFile | git show 1234abcd:README.md    |
94
+
95
+:Diff                                                                 *:Diff*
96
+-----
97
+
98
+If you're on a regular file that's different from HEAD, `:Diff` will perform a
99
+`git diff` on the file from HEAD. If it's the same as HEAD, then `:Diff` will
100
+perform a `git diff` against that file's previous commit.
101
+
102
+If the cursor is on a commit hash (as available on :Blame, :Log, and :Show
103
+buffers), then `:Diff` will perform a diff against the previous commit to that
104
+one.
105
+
106
+==============================================================================
107
+vim:tw=78:sw=4:ts=8:ft=help:norl:
... ...
@@ -0,0 +1,207 @@
1
+if exists("g:loaded_gittab") || &cp | finish | endif
2
+let g:loaded_gittab = 1
3
+
4
+"A helper function that tries to show a buffer if it already exists
5
+function! s:ShowBufInNewTab(bufname)
6
+   let l:bnr = bufnr(a:bufname)
7
+   if l:bnr > 0
8
+       tabnew
9
+       exec 'buffer ' . l:bnr
10
+       return 1
11
+   endif
12
+   return 0
13
+endfunction
14
+
15
+"A helper function that tries to show a buffer if it already exists
16
+function! s:ShowBufInNewSplit(bufname)
17
+   let l:bnr = bufnr(a:bufname)
18
+   if l:bnr > 0
19
+"       bo vne
20
+       vne
21
+       exec 'buffer ' . l:bnr
22
+       return 1
23
+   endif
24
+   return 0
25
+endfunction
26
+
27
+function! s:GitBlame(...)
28
+    let l:hash = expand('<cword>')
29
+    let l:currentView = winsaveview()
30
+    let l:args = a:1
31
+    if strlen(l:args)
32
+        " Add a space to the end
33
+        let l:args = l:args . " "
34
+    endif
35
+    " If in a Blame window already, do blame for some prior commit
36
+    if l:hash =~ '^[0-9a-f]\{7,40}$' && stridx(expand('%'), ' -- ') != -1
37
+        let l:fname = split(expand('%'), ' -- ')[-1]
38
+        let l:bufname = 'git blame ' . l:args . l:hash . '^ -- ' . l:fname
39
+        if !s:ShowBufInNewTab(l:bufname)
40
+            exec 'tabnew | r! git blame ' . l:args . l:hash . '^ -- ' . shellescape(l:fname)
41
+            exec 'silent :file ' . fnameescape(l:bufname)
42
+        endif
43
+    else
44
+        let l:fname = expand('%')
45
+        let l:hash = ''
46
+        " Show fnames will have ':' in them.
47
+        if stridx(l:fname, ':') != -1
48
+            let l:fname_parts = split(l:fname, ':')
49
+            let l:fname = l:fname_parts[-1]
50
+            let l:hash = split(l:fname_parts[0], ' ')[-1]
51
+        endif
52
+        if strlen(l:hash)
53
+            let l:bufname = 'git blame ' . l:args . l:hash . ' -- ' . l:fname
54
+            if !s:ShowBufInNewTab(l:bufname)
55
+                exec 'tabnew | r! git blame ' . l:args . l:hash . ' -- ' . shellescape(l:fname)
56
+                exec 'silent :file ' . fnameescape(l:bufname)
57
+            endif
58
+        else
59
+            let l:bufname = 'git blame ' . l:args . '-- ' . l:fname
60
+            if !s:ShowBufInNewTab(l:bufname)
61
+                exec 'tabnew | r! git blame ' . l:args . '-- ' . shellescape(l:fname)
62
+                exec 'silent :file ' . fnameescape(l:bufname)
63
+            endif
64
+        endif
65
+    endif
66
+    0d_
67
+    call winrestview(l:currentView)
68
+    setl buftype=nofile
69
+endfunction
70
+command -nargs=* Blame :call s:GitBlame(<q-args>)
71
+
72
+function! s:GitShow(commit_or_file, ...)
73
+    let l:fname = expand('%')
74
+    let l:hash = expand('<cword>')
75
+    if l:hash =~ '^[0-9a-f]\{7,40}$'
76
+        if stridx(l:fname, ' -- ') != -1
77
+            let l:fname = split(l:fname, ' -- ')[-1]
78
+        endif
79
+        let l:args = a:1
80
+        if strlen(l:args)
81
+            " Add a space to the end
82
+            let l:args = l:args . " "
83
+        endif
84
+        if a:commit_or_file != "file"
85
+            let l:bufname = 'git show ' . l:args . l:hash . ' -- ' . l:fname
86
+            if !s:ShowBufInNewTab(l:bufname)
87
+                " Have Show show all the affected files, so don't actually use  "--"
88
+                " exec 'tabnew | r! git show ' . l:hash . ' -- ' . shellescape(l:fname)
89
+                exec 'tabnew | r! git show ' . l:args . l:hash
90
+                " We lie here (' -- ') to have a filename the other git commands can use.
91
+                exec 'silent :file ' . fnameescape(l:bufname)
92
+            endif
93
+            0d_
94
+        else
95
+            let l:currentView = winsaveview()
96
+            let l:bufname = 'git show ' . l:args . l:hash . ':' . l:fname
97
+            if !s:ShowBufInNewTab(l:bufname)
98
+                exec 'tabnew | r! git show ' . l:args. l:hash . ':' . shellescape(l:fname)
99
+                exec 'silent :file ' . fnameescape(l:bufname)
100
+            endif
101
+            0d_
102
+            call winrestview(l:currentView)
103
+        endif
104
+        setl buftype=nofile
105
+    else
106
+        echo l:hash . ' is not a git hash.'
107
+    endif
108
+endfunction
109
+command -nargs=* Show :call s:GitShow("commit", <q-args>)
110
+command -nargs=* ShowFile :call s:GitShow("file", <q-args>)
111
+
112
+function! s:GitDiff()
113
+    let l:fname = expand('%:.')
114
+    let l:buf = winbufnr(0)
115
+    let l:commit = 'HEAD'
116
+    let l:hash = expand('<cword>')
117
+    let l:currentView = winsaveview()
118
+
119
+    " If the current word is a hash, then diff that vs. previous
120
+    if l:hash =~ '^[0-9a-f]\{7,40}$' && stridx(expand('%'), ' -- ') != -1
121
+        let l:fname = split(expand('%'), ' -- ')[-1]
122
+        let l:bufname = 'git show ' . l:hash . '^:' . l:fname
123
+        if !s:ShowBufInNewTab(l:bufname)
124
+            exec ':tabnew | silent r! git show ' . l:hash . '^:$(git rev-parse --show-prefix)' . shellescape(l:fname)
125
+            setl buftype=nofile
126
+            0d_
127
+            exec 'silent :file ' . fnameescape(l:bufname)
128
+        endif
129
+
130
+        let l:bufname = 'git show ' . l:hash . ':' . l:fname
131
+        if !s:ShowBufInNewSplit(l:bufname)
132
+            exec 'vne | silent r! git show ' . l:hash . ':$(git rev-parse --show-prefix)' . shellescape(l:fname)
133
+            setl buftype=nofile
134
+            exec 'silent :file ' . fnameescape(l:bufname)
135
+            0d_
136
+        endif
137
+    elseif stridx(expand('%'), ':') != -1
138
+        " If we're in a 'git show' buffer, then extract fname and hash from there
139
+        let l:fname_parts = split(l:fname, ':')
140
+        let l:fname = l:fname_parts[-1]
141
+        let l:hash = split(l:fname_parts[0], ' ')[-1]
142
+        " TODO: Below few lines are identical to above, so remove dupes.
143
+        let l:bufname = 'git show ' . l:hash . '^:' . l:fname
144
+        if !s:ShowBufInNewTab(l:bufname)
145
+            exec ':tabnew | silent r! git show ' . l:hash . '^:$(git rev-parse --show-prefix)' . shellescape(l:fname)
146
+            setl buftype=nofile
147
+            0d_
148
+            exec 'silent :file ' . fnameescape(l:bufname)
149
+        endif
150
+
151
+        let l:bufname = 'git show ' . l:hash . ':' . l:fname
152
+        if !s:ShowBufInNewSplit(l:bufname)
153
+            exec 'vne | silent r! git show ' . l:hash . ':$(git rev-parse --show-prefix)' . shellescape(l:fname)
154
+            setl buftype=nofile
155
+            exec 'silent :file ' . fnameescape(l:bufname)
156
+            0d_
157
+        endif
158
+    else
159
+        " If the buffer is not different then repo, then diff HEAD vs file's previous commit
160
+        let l:o = system("git status --porcelain | grep " . l:fname)
161
+        if v:shell_error != 0
162
+            let l:commit = system('git log -2 --pretty=format:"%h" -- ' . l:fname . ' | tail -n 1')
163
+        endif
164
+
165
+        let l:bufname = 'git show ' . l:commit . ':' . l:fname
166
+        " Bug if l:filename includes ".."
167
+        if !s:ShowBufInNewTab(l:bufname)
168
+            exec ':tabnew | r! git show ' . l:commit . ':$(git rev-parse --show-prefix)' . l:fname
169
+            setl buftype=nofile
170
+            0d_
171
+            exec 'silent :file ' . fnameescape(l:bufname)
172
+        endif
173
+        exec 'vert sb '.l:buf
174
+    endif
175
+    call winrestview(l:currentView)
176
+    windo diffthis
177
+    setl buftype=nofile
178
+    wincmd r
179
+    wincmd l
180
+endfunction
181
+command Diff :call s:GitDiff()
182
+
183
+function! s:GitLog(...)
184
+    let l:fname = expand('%')
185
+    if stridx(l:fname, ' -- ') != -1
186
+        let l:fname = split(l:fname, ' -- ')[-1]
187
+    elseif stridx(l:fname, ':') != -1
188
+        let l:fname = split(l:fname, ':')[-1]
189
+    endif
190
+    let l:args = a:1
191
+    if strlen(l:args)
192
+        " Add a space to the end
193
+        let l:args = l:args . " "
194
+    endif
195
+    let l:bufname = 'git log ' . l:args . '-- ' . l:fname
196
+    if !s:ShowBufInNewTab(l:bufname)
197
+        exec 'tabnew | r! git log --no-color --graph --date=short ' . l:args . '--pretty="format:\%h \%ad \%s \%an \%d" -- ' . shellescape(l:fname)
198
+        setl buftype=nofile
199
+        0d_
200
+        exec 'silent :file ' . fnameescape(l:bufname)
201
+    endif
202
+endfunction
203
+
204
+" Handy arguments are --all, --merges, --date-order, --first-parent, --ancestry-path
205
+command -nargs=* Log :call s:GitLog(<q-args>)
206
+
207
+" vim:set ft=vim sw=4 sts=4 et:
... ...
@@ -47,16 +47,21 @@ See [config.dlma.com](http://config.dlma.com) for more.
47 47
         4. [visual-star-search](http://got-ravings.blogspot.com/2008/07/vim-pr0n-visual-search-mappings.html), so * and # work in visual mode too.
48 48
         5. [git-tab](https://github.com/dblume/gittab), use integrated context-sensitive git commands
49 49
         6. Assorted favorite colors like [desert](https://github.com/dblume/desert.vim).
50
-3. .gitconfig and .gitignore
51
-4. .tmux.conf
52
-5. .inputrc, for vi mode and a [partially matched command history traversal](http://askubuntu.com/questions/59846/bash-history-search-partial-up-arrow/59855#59855).
53
-6. .editrc, for vi mode and tab word completion in macOS.
54
-7. .ssh/config, for a [fix for CVE-2016-0777](https://news.ycombinator.com/item?id=10901588). (Or upgrade to OpenSSH 7.1p2 released Jan 14, 2016 from http://www.openssh.com.)
55
-8. .ripgreprc, for ripgrep, or [rg](https://github.com/BurntSushi/ripgrep/).
56
-9. .gdbinit
57
-10. .visidatarc, to hide [visidata's](https://www.visidata.org/) menu at the top, for the old school UI.
58
-11. .config/gitui/key\_bindings.ron, for vim key bindings in [gitui](https://github.com/extrawurst/gitui).
59
-11. [i3](https://i3wm.org/) configs.
50
+3. Neovim resources
51
+    1. .config/nvim/init.vim
52
+    2. An empty .nvim\_undo directory
53
+    3. .config/nvim/colors/nvim\_desert.vim
54
+    4. .local/share/nvim/site/plugin/ plugins
55
+4. .gitconfig and .gitignore
56
+5. .tmux.conf
57
+6. .inputrc, for vi mode and a [partially matched command history traversal](http://askubuntu.com/questions/59846/bash-history-search-partial-up-arrow/59855#59855).
58
+7. .editrc, for vi mode and tab word completion in macOS.
59
+8. .ssh/config, for a [fix for CVE-2016-0777](https://news.ycombinator.com/item?id=10901588). (Or upgrade to OpenSSH 7.1p2 released Jan 14, 2016 from http://www.openssh.com.)
60
+9. .ripgreprc, for ripgrep, or [rg](https://github.com/BurntSushi/ripgrep/).
61
+10. .gdbinit
62
+11. .visidatarc, to hide [visidata's](https://www.visidata.org/) menu at the top, for the old school UI.
63
+12. .config/gitui/key\_bindings.ron, for vim key bindings in [gitui](https://github.com/extrawurst/gitui).
64
+13. [i3](https://i3wm.org/) configs.
60 65
 
61 66
 #### Optional manual steps for fresh setups
62 67
 
... ...
@@ -7,7 +7,8 @@ declare -a dotfiles=(".bashrc" ".bash_profile" ".vimrc" ".editrc" ".gitconfig"
7 7
                      ".gitignore" ".inputrc" ".tmux.conf" ".ssh/config" ".ripgreprc"
8 8
                      ".gdbinit" ".config/gitui/key_bindings.ron" ".visidatarc"
9 9
                      ".config/i3/config" ".config/i3status/config"
10
-                     ".config/dunst/dunstrc")
10
+                     ".config/dunst/dunstrc" ".config/nvim/init.vim"
11
+                     ".config/nvim/colors/nvim_desert.vim")
11 12
 declare -i dry_run=0
12 13
 
13 14
 ## exit the shell (with status 2) after printing the message
... ...
@@ -88,10 +89,30 @@ else
88 89
     echo No change to the .vim/ directories.
89 90
 fi
90 91
 
91
-# Make a directory for vim undo
92
+# TODO: Neovim's plugins go in ~/.local/share/nvim/site/plugin/
93
+# https://neovim.io/doc/user/usr_05.html
94
+if ! diff -qr "$HOME"/.local/share/nvim/site/plugin .local/share/nvim/site/plugin > /dev/null ; then
95
+    if [ $dry_run -eq 0 ]; then
96
+        if [ -d "$HOME"/.local/share/nvim/site/plugin/ ]; then
97
+                mkdir -p "${backup_dir}"/.local/share/nvim/site/plugin
98
+                mv "$HOME"/.local/share/nvim/site/plugin/* "${backup_dir}"/.local/share/nvim/site/plugin/
99
+        else
100
+            mkdir -p "$HOME"/.local/share/nvim/site/plugin
101
+        fi
102
+        cp -r .local/share/nvim/site/plugin/* "$HOME"/.local/share/nvim/site/plugin/
103
+    fi
104
+    echo Check the plugins in .local/share/nvim/site/plugin/
105
+else
106
+    echo No change to the .local/share/nvim/site/plugin/ directories.
107
+fi
108
+
109
+# Make a directory for vim and neovim undo
92 110
 if [ ! -d "$HOME"/.vim_undo ]; then
93 111
     ((dry_run==0)) && mkdir -p "$HOME"/.vim_undo
94 112
 fi
113
+if [ ! -d "$HOME"/.nvim_undo ]; then
114
+    ((dry_run==0)) && mkdir -p "$HOME"/.nvim_undo
115
+fi
95 116
 
96 117
 # I have device local secrets in .localrc and a github secret in .gitconfig.local
97 118
 for i in ".gitconfig.local" ".localrc"
98 119