First tweaks for neovim, two essential plugins
dblume

dblume commited on 2024-03-07 10:29:21
Showing 5 changed files, with 70 additions and 25 deletions.


Didn't need an nvim undodir, neovim auto-creates its own.
... ...
@@ -48,20 +48,14 @@ nnoremap <cr> :noh<cr><cr>
48 48
 nnoremap <Tab> :bp<cr>
49 49
 nnoremap <S-Tab> :bn<cr>
50 50
 
51
-syntax on
52
-
53 51
 set t_Co=256
54
-if v:version >= 703
55 52
 set colorcolumn=80
56
-endif
57 53
 if has('gui_running') " Didn't work: if &term != 'builtin_gui'
58 54
   " Light backgrounds for GUI experiences
59 55
   set background=light
60 56
   " colorscheme peaksea
61 57
   colorscheme tolerable
62
-  if v:version >= 703
63 58
   highlight ColorColumn ctermbg=255 guibg=#F6F6F6
64
-  endif
65 59
   highlight statusline   ctermfg=17 ctermbg=Gray " override scheme
66 60
   highlight statuslineNC ctermfg=20 ctermbg=LightGray" override scheme
67 61
   if has('win32')
... ...
@@ -72,9 +66,7 @@ else
72 66
   " Dark backgrounds for tty experiences
73 67
   set background=dark
74 68
   colorscheme nvim_desert
75
-  if v:version >= 703
76 69
   highlight ColorColumn ctermbg=233 guibg=Black " dark gray (or 17, dark blue)
77
-  endif
78 70
   highlight statusline   ctermfg=24 ctermbg=250  " override scheme
79 71
   highlight statuslineNC ctermfg=236 ctermbg=Gray  " override scheme
80 72
   highlight MatchParen   term=reverse ctermbg=23  " 23 is more subtle than default
... ...
@@ -83,12 +75,13 @@ endif
83 75
 au InsertEnter * hi statusline guibg=Cyan ctermfg=20 guifg=Black ctermbg=248
84 76
 au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=24 ctermbg=250 guifg=black guibg=#c2bfa5
85 77
 
86
-" set mouse=v     " visual mode, not working great for PuTTY
78
+" May want to "set mouse=" See https://neovim.io/doc/user/vim_diff.html#_default-mouse
79
+" set mouse=v  " visual mode, not great in PuTTY, neovim defaults to nvi
87 80
 
81
+" Consider neovim default "./tags;,tags"
88 82
 set tags=tags;/
89 83
 
90
-set history=50
91
-set laststatus=2
84
+set history=500
92 85
 
93 86
 function! StatuslineGit()
94 87
   let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
... ...
@@ -135,8 +128,6 @@ set statusline+=\[%{&fileformat}\]
135 128
 set statusline+=\ │\ %p%%\ =
136 129
 set statusline+=\ %l/%L\ :\ %c\ 
137 130
 
138
-set encoding=utf-8
139
-
140 131
 " Fast saving
141 132
 nmap <leader>w :w!<cr>
142 133
 " I use relative number for cursor movement.
... ...
@@ -214,9 +205,6 @@ set nobackup       " ~ files
214 205
 set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
215 206
 set noswapfile     " .swp files
216 207
 
217
-" Allow tags to open another buffer even if this one is modified
218
-set hidden
219
-
220 208
 " Switch between source and header files
221 209
 function! SwitchSourceHeader()
222 210
   let s:ext  = expand("%:e")
... ...
@@ -288,12 +276,10 @@ if has("autocmd")
288 276
   autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
289 277
   autocmd FileType c,cpp set foldmethod=syntax
290 278
 
291
-  if v:version >= 703
292 279
   " I toggle out of relative number when Vim's focus is lost, because
293 280
   " if I'm not editing, then I may be referring to errors with line numbers.
294 281
   autocmd FocusLost * if &relativenumber | set number | endif
295 282
   autocmd FocusGained * if &number | set relativenumber | endif
296
-  endif
297 283
 
298 284
   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
299 285
   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
... ...
@@ -0,0 +1,46 @@
1
+" Avoid installing twice or when in unsupported Vim version.
2
+if exists('g:loaded_file_line') || (v:version < 700)
3
+	finish
4
+endif
5
+let g:loaded_file_line = 1
6
+
7
+function! s:gotoline()
8
+	let file = bufname("%")
9
+
10
+	" :e command calls BufRead even though the file is a new one.
11
+	" As a workarround Jonas Pfenniger<jonas@pfenniger.name> added an
12
+	" AutoCmd BufRead, this will test if this file actually exists before
13
+	" searching for a file and line to goto.
14
+	if (filereadable(file))
15
+		return
16
+	endif
17
+
18
+	" Accept file:line:column: or file:line:column and file:line also
19
+	let names =  matchlist( file, '\(.\{-1,}\):\%(\(\d\+\)\%(:\(\d*\):\?\)\?\)\?$')
20
+
21
+	if empty(names)
22
+		return
23
+	endif
24
+
25
+	let file_name = names[1]
26
+	let line_num  = names[2] == ''? '0' : names[2]
27
+	let  col_num  = names[3] == ''? '0' : names[3]
28
+
29
+	if filereadable(file_name)
30
+		let l:bufn = bufnr("%")
31
+
32
+		exec "keepalt edit " . fnameescape(file_name)
33
+		exec ":" . line_num
34
+		exec "normal! " . col_num . '|'
35
+		if foldlevel(line_num) > 0
36
+			exec "normal! zv"
37
+		endif
38
+
39
+		exec "normal! zz"
40
+		exec ":bwipeout " l:bufn
41
+	endif
42
+
43
+endfunction
44
+
45
+autocmd! BufNewFile *:* nested call s:gotoline()
46
+autocmd! BufRead *:* nested call s:gotoline()
... ...
@@ -0,0 +1,17 @@
1
+" From http://got-ravings.blogspot.com/2008/07/vim-pr0n-visual-search-mappings.html
2
+
3
+" makes * and # work on visual mode too.
4
+function! s:VSetSearch(cmdtype)
5
+  let temp = @s
6
+  norm! gv"sy
7
+  let @/ = '\V' . substitute(escape(@s, a:cmdtype.'\'), '\n', '\\n', 'g')
8
+  let @s = temp
9
+endfunction
10
+
11
+xnoremap * :<C-u>call <SID>VSetSearch('/')<CR>/<C-R>=@/<CR><CR>
12
+xnoremap # :<C-u>call <SID>VSetSearch('?')<CR>?<C-R>=@/<CR><CR>
13
+
14
+" recursively vimgrep for word under cursor or selection if you hit leader-star
15
+nmap <leader>* :execute 'noautocmd vimgrep /\V' . substitute(escape(expand("<cword>"), '\'), '\n', '\\n', 'g') . '/ **'<CR>
16
+vmap <leader>* :<C-u>call <SID>VSetSearch()<CR>:execute 'noautocmd vimgrep /' . @/ . '/ **'<CR>
17
+
... ...
@@ -49,9 +49,8 @@ See [config.dlma.com](http://config.dlma.com) for more.
49 49
         6. Assorted favorite colors like [desert](https://github.com/dblume/desert.vim).
50 50
 3. Neovim resources
51 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
52
+    2. .config/nvim/colors/nvim\_desert.vim
53
+    3. .local/share/nvim/site/plugin/ plugins
55 54
 4. .gitconfig and .gitignore
56 55
 5. .tmux.conf
57 56
 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).
... ...
@@ -106,13 +106,10 @@ else
106 106
     echo No change to the .local/share/nvim/site/plugin/ directories.
107 107
 fi
108 108
 
109
-# Make a directory for vim and neovim undo
109
+# Make a directory for vim undo
110 110
 if [ ! -d "$HOME"/.vim_undo ]; then
111 111
     ((dry_run==0)) && mkdir -p "$HOME"/.vim_undo
112 112
 fi
113
-if [ ! -d "$HOME"/.nvim_undo ]; then
114
-    ((dry_run==0)) && mkdir -p "$HOME"/.nvim_undo
115
-fi
116 113
 
117 114
 # I have device local secrets in .localrc and a github secret in .gitconfig.local
118 115
 for i in ".gitconfig.local" ".localrc"
119 116