51fae5e6f4f0a77283800c3487c0ae7cd05ec3bc
dblume Remove explicit settings th...

dblume authored 8 months ago

1) " Version 2024-03-07.1 - First misc fixes
dblume Add Neovim configs

dblume authored 8 months ago

2) set bs=2            " allow backspacing over everything in insert mode
3) set smartindent     " Do smart auto indenting when starting  new line
4) set foldlevel=99
5) set nowrap          " no wrapping text lines on the screen (exceptions below)
6) set sidescroll=5
7) set listchars+=tab:>-,precedes:<,extends:>,nbsp:· " for :set list
8) set iskeyword+=-    " Add - to list of non-word-breaking chars.
9) set scrolloff=0     " EC2 defaults to 5. Set explicitly to be consistent
10) set notermguicolors " Only needed for neovim while I port my color schemes
dblume Remove explicit settings th...

dblume authored 8 months ago

11) set undofile        " undo even after closing and reopening a file
dblume Small responsiveness improv...

dblume authored 8 months ago

12) set noshowcmd       " Show size of selected area in visual mode on last line
13) set noruler         " Show coordinates on status line
dblume nvim set hidden

dblume authored 8 months ago

14) set hidden          " Don't abandon Scratch buffer when hidden.
dblume Don't set cursorline if we'...

dblume authored 7 months ago

15) "set cursorline     " For CursorLineNR formatting similar to pre 8.0.
dblume Set cursorlineopt to number...

dblume authored 7 months ago

16) set culopt=number   " Otherwise diff views have an underline. neovim issue 9800
dblume Add Neovim configs

dblume authored 8 months ago

17) 
18) " Make j and k move to the next row, not file line
19) nnoremap j gj
20) nnoremap k gk
21) 
22) " From Steve Losh: http://learnvimscriptthehardway.stevelosh.com/chapters/10.html
23) " Map jk to ESC in insert mode (except when navigating popup menu)
24) inoremap <expr> jk pumvisible() ? '' : '<esc>'
25) inoremap <expr> j pumvisible() ? '<Down>' : 'j'
26) inoremap <expr> k pumvisible() ? '<Up>' : 'k'
27) 
28) " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
29) nnoremap <leader>v <C-w>v<C-w>l
30) nnoremap <C-h> <C-w>h
31) nnoremap <C-j> <C-w>j
32) nnoremap <C-k> <C-w>k
33) nnoremap <C-l> <C-w>l
34) 
35) " clear search highlights
36) nnoremap <cr> :noh<cr><cr>
37) 
38) " tab switches to previous/next buffer
39) nnoremap <Tab> :bp<cr>
40) nnoremap <S-Tab> :bn<cr>
41) 
42) set t_Co=256
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

43) set colorcolumn=80
dblume Add Neovim configs

dblume authored 8 months ago

44) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
45)   " Light backgrounds for GUI experiences
46)   set background=light
47)   " colorscheme peaksea
48)   colorscheme tolerable
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

49)   highlight ColorColumn ctermbg=255 guibg=#F6F6F6
dblume nvim ColorColumn was inverted

dblume authored 8 months ago

50)   highlight statusline   ctermfg=17 ctermbg=Gray  " override scheme
51)   highlight statuslineNC ctermfg=20 ctermbg=LightGray  " override scheme
dblume Add Neovim configs

dblume authored 8 months ago

52)   if has('win32')
53)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
54)   endif
55)   set lines=50 columns=100
56) else
57)   " Dark backgrounds for tty experiences
58)   set background=dark
59)   colorscheme nvim_desert
60) endif
61) 
dblume Vim insert mode's blue shou...

dblume authored 7 months ago

62) au InsertEnter * hi statusline guibg=Cyan ctermfg=25 guifg=Black ctermbg=248
dblume Make the normal statusbar m...

dblume authored 7 months ago

63) au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=23 ctermbg=250 guifg=black guibg=#c2bfa5
dblume Add Neovim configs

dblume authored 8 months ago

64) 
dblume Restore cursor line number...

dblume authored 7 months ago

65) " See https://neovim.io/doc/user/vim_diff.html#_default-mouse
66) set mouse=  " neovim defaults to nvi
dblume Add Neovim configs

dblume authored 8 months ago

67) 
dblume Make c-] show taglist like...

dblume authored 7 months ago

68) " Make c-] show a list of tags, or jump straight if only single tag
69) nnoremap <c-]> g<c-]>
70) vnoremap <c-]> g<c-]>
71) nnoremap g<c-]> <c-]>
72) vnoremap g<c-]> <c-]>
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

73) " Consider neovim default "./tags;,tags"
dblume Add Neovim configs

dblume authored 8 months ago

74) set tags=tags;/
75) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

76) set history=500
dblume Add Neovim configs

dblume authored 8 months ago

77) 
dblume Retrieve git branch only on...

dblume authored 7 months ago

78) function! GitBranch()
dblume Make vim StatuslineGit() re...

dblume authored 8 months ago

79)   let l:branchname = system("git -C " . expand('%:p:h') . " rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
dblume Make git branch fit on stat...

dblume authored 7 months ago

80)   return strlen(l:branchname) > 0 ? '  │ '.l:branchname : ''
dblume Add Neovim configs

dblume authored 8 months ago

81) endfunction
82) 
dblume Only show encoding and form...

dblume authored 7 months ago

83) function! EncodingAndFormat()
84)   if (len(&fileencoding) && &fileencoding != 'utf-8') || &fileformat != 'unix'
85)     return &fileencoding?&fileencoding:&encoding .'['. &fileformat . '] │ '
86)   endif
87)   return ''
88) endfunction
89) 
dblume Make "set ruler!" change st...

dblume authored 7 months ago

90) function! OnRuler()
91)   if &ruler
92)     return '│ '.line('.').':'.col('.').' '
93)   endif
94)   return ''
95) endfunction
96) 
dblume Add Neovim configs

dblume authored 8 months ago

97) function! Current_mode()
98)   let l:currentmode={
99)     \ 'n'  : 'NORMAL',
100)     \ 'v'  : 'VISUAL',
101)     \ 'V'  : 'V·LINE',
102)     \ '' : 'V·BLOCK',
103)     \ 's'  : 'SELECT',
104)     \ 'S'  : 'S·LINE',
105)     \ 'i'  : 'INSERT',
106)     \ 'r'  : 'I·REPLACE',
107)     \ 'R'  : 'REPLACE',
108)     \ 'Rv' : 'V·REPLACE',
109)     \ 'c'  : 'COMMAND',
110)     \}
111)     return get(l:currentmode, mode(), mode())
112) endfunction
113) 
114) function! Trim_brackets(fn)
115)   if v:version > 800
116)     return trim(a:fn, "[]")
117)   else
118)     return a:fn
119)   endif
120) endfunction
121) 
122) set statusline=\ %{Current_mode()}
123) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
dblume Retrieve git branch only on...

dblume authored 7 months ago

124) set statusline+=%{b:git_branch}
dblume Add Neovim configs

dblume authored 8 months ago

125) set statusline+=\ │\ %f
126) set statusline+=%m
127) set statusline+=\ %r
128) set statusline+=\ %=
129) set statusline+=%h
130) set statusline+=\ %{Trim_brackets(&filetype)}
131) set statusline+=\ %#StatusLineNC#
dblume Only show encoding and form...

dblume authored 7 months ago

132) set statusline+=\ %{b:enc_fmt}
133) set statusline+=%p%%\ of
dblume Drop column and line number...

dblume authored 7 months ago

134) set statusline+=\ %L\ 
dblume Make "set ruler!" change st...

dblume authored 7 months ago

135) set statusline+=%{OnRuler()}
dblume Add Neovim configs

dblume authored 8 months ago

136) 
137) " Fast saving
138) nmap <leader>w :w!<cr>
139) " I use relative number for cursor movement.
140) nmap <leader>r :set relativenumber!<cr>
141) nmap <leader>n :set number!<cr>
142) 
143) " Useful mappings for managing tabs
144) " Tab Previous: gT or C-PageUp
145) " Tab Next: gt or C-PageDown
146) nmap <leader>tn :tabnew
147) nmap <leader>to :tabonly<cr>
148) nmap <leader>tc :tabclose<cr>
149) nmap <leader>tm :tabmove
150) nmap <leader>1 1gt
151) nmap <leader>2 2gt
152) nmap <leader>3 3gt
153) nmap <leader>4 4gt
154) nmap <leader>5 5gt
155) nmap <leader>6 6gt
156) nmap <leader>7 7gt
157) nmap <leader>8 8gt
158) nmap <leader>9 9gt
159) 
160) " Open current buffer in new tab. Close with C-w,c
161) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
162) function! OpenCurrentAsNewTab()
163)     let l:currentView = winsaveview()
164)     tabedit %
165)     call winrestview(l:currentView)
166) endfunction
167) nmap <leader>o :call OpenCurrentAsNewTab()<CR>
168) 
169) " pastetoggle
170) nmap <leader>p :set invpaste paste?<cr>
171) 
172) " Control+p to paste onto next line
173) nmap <C-p> :pu<cr>
174) 
175) " Make netrw's Explore behave a little like NERDTreeToggle
176) " http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
177) function! ToggleNetrw()
178)   if bufwinnr("NetrwTreeListing") > 0
179)     for i in range(1, bufnr("$"))
180)       if (getbufvar(i, "&filetype") == "netrw")
181)         silent exe "bwipeout " . i
182)         return
183)       endif
184)     endfor
185)   endif
186)   silent Vexplore %:p:h
187) endfunction
188) nmap <leader>e :call ToggleNetrw()<cr>
189) 
190) " install taglist
191) let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
192) let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
193) let Tlist_Close_On_Select = 1          " Close taglist window on select
194) nmap <leader>l :TlistToggle<cr>
195) 
196) " install vim-bbye
197) nmap <leader>bd :Bdelete<cr>
198) 
199) " Visual mode mappings
200) """
201) 
202) " map sort function to a key
203) vnoremap <leader>s :sort<cr>
204) 
205) "easier moving of code blocks
206) vnoremap < <gv
207) vnoremap > >gv
208) 
209) " If too many file system events are getting triggered.
210) set nobackup       " ~ files
211) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
212) set noswapfile     " .swp files
213) 
214) " Switch between source and header files
215) function! SwitchSourceHeader()
216)   let s:ext  = expand("%:e")
217)   let s:base = expand("%:t:r")
218)   let s:cmd  = "find " . s:base
219)   if (s:ext == "cpp" || s:ext == "c")
220)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
221)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
222)   else
223)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
224)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
225)   endif
226) endfunc
227) 
228) " Demonstrates a way to look in a mirror directory
229) " function! OpenOther()
230) "    if expand("%:e") == "cpp"
231) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
232) "    elseif expand("%:e") == "h"
233) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
234) "    endif
235) " endfunc
236) 
237) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
238) function! DeleteTrailingWS()
239)   exe "normal mz"
240)   %s/\s\+$//ge
241)   exe "normal `z"
242) endfunc
243) 
244) function! OpenInOtherWindow()
245)   if winnr('$') == 1
246)     exe "wincmd F"
247)   else
248)     let curNum = winnr()
249)     let oldBuf = bufnr( "%" )
250)     if curNum == 1
251)       let othNum = 2
252)     else
253)       let othNum = 1
254)     endif
255)     exe "normal! gF"
256)     let newBuf = bufnr( "%" )
257)     let newLine = line(".")
258)     exe 'hide buf' oldBuf
259)     exe othNum . "wincmd w"
260)     exe 'hide buf' newBuf
261)     exe "normal! " . newLine . "G"
262)   endif
263) endfunc
264) 
265) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
266) nmap <silent> <leader>f :call OpenInOtherWindow()<cr>
267) 
268) if has("autocmd")
269)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
270)   " Don't let smartindent unindent the # character in Python files
271)   autocmd FileType python  inoremap # X<c-h>#
272)   autocmd FileType python,c,cpp,php,brs,sh  set expandtab  " Use spaces instead of tabs
273)   autocmd Filetype make    setl noexpandtab       " ...not for files that use tabs.
274) 
275)   " Use the vim command %retab before applying the following
276)   " two with files that have 8-space tabs.
277)   autocmd FileType c,cpp,python,php  set tabstop=4
278)   autocmd FileType c,cpp,php  set shiftwidth=4
279) 
280)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
281) 
282)   autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
283)   autocmd FileType c,cpp set foldmethod=syntax
284) 
dblume Improve focus-based switchi...

dblume authored 7 months ago

285) " https://jeffkreeftmeijer.com/vim-number/
286) augroup numbertoggle
287)   autocmd!
288)   autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu   | endif
289)   autocmd BufLeave,FocusLost,InsertEnter,WinLeave   * if &nu                  | set nornu | endif
290) augroup END
dblume Add Neovim configs

dblume authored 8 months ago

291) 
292)   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
293)   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
294)   autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
295) 
dblume Always start on first line...

dblume authored 7 months ago

296)   " When editing a file, always jump to the last cursor position...
dblume Add Neovim configs

dblume authored 8 months ago

297)   autocmd BufReadPost *
dblume Always start on first line...

dblume authored 7 months ago

298)   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
dblume Add Neovim configs

dblume authored 8 months ago

299)   \   exe "normal! g'\"" |
300)   \ endif
dblume Always start on first line...

dblume authored 7 months ago

301)   " ...except for gitcommit where we always want to start at the top
302)   autocmd FileType gitcommit exe "normal! gg"
dblume Retrieve git branch only on...

dblume authored 7 months ago

303) 
dblume Only show encoding and form...

dblume authored 7 months ago

304)   autocmd BufNewFile,BufReadPost *
305)   \ let b:git_branch = GitBranch() |
306)   \ let b:enc_fmt = EncodingAndFormat()
307)   autocmd BufEnter *
308)   \ let b:git_branch = GitBranch() |
309)   \ let b:enc_fmt = EncodingAndFormat()
dblume Don't set cursorline if we'...

dblume authored 7 months ago

310) 
311)   " I only use a cursorline style for the number column
312)   autocmd OptionSet number,relativenumber if v:option_new | set cursorline | endif
dblume Add Neovim configs

dblume authored 8 months ago

313) endif
314) 
315) " This requires vim to be compiled with +python
316) " Use auto complete in insert mode with ctrl-x, ctrl-o
317) " See :help new-omni-completion for more.
318) filetype plugin on
319) set omnifunc=syntaxcomplete#Complete
320) 
321) " Torn on whether I like the omni completion preview window left open or not.
322) " autocmd CompleteDone * pclose
323) 
324) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
dblume Sensibly, in neovim <C-Spac...

dblume authored 7 months ago

325) inoremap <C-Space> <C-x><C-o>
dblume Add Neovim configs

dblume authored 8 months ago

326) 
327) " cscope
328) if has("cscope")
329)     set cscopetag  " Use both cscope and ctag for 'ctrl-]'
330)     set csto=1     " 0=cscope first; 1=ctags first
331)     set cscopequickfix=s-,c-,d-,i-,t-,e-,a- " cscope to quickfix window
332) 
333)     set nocsverb
334)     " add any database in current directory
335)     if filereadable("cscope.out")
336)         cs add cscope.out
337)     " else add database pointed to by environment
338)     elseif $CSCOPE_DB != ""
339)         cs add $CSCOPE_DB
340)     endif
341)     set csverb
342) endif
343) 
344) " From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
345) " :grep term %
346) " :grep -r term path/
347) " :cw
348) " :ccl (or C-w,q)
349) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
350) 
351) function! MaybeSortQuickfix(fn)
352) "    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
353)     let t = getqflist({'title': 1}).title
354)     " Only sort the files if for search-style commands, not "make".
355)     if stridx(t, "cs ") == 0 || stridx(t, ":gr") == 0 || stridx(t, ":vim") == 0 || stridx(t, ":rg") == 0
356)         call setqflist(sort(getqflist(), a:fn), 'r')
357)         call setqflist([], 'r', {'title': t})
358)     endif
359)     cwindow
360) endfunction
361) 
362) function! QfStrCmp(e1, e2)
363)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
364)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
365) endfunction
366) 
367) " Use ripgrep for search instead of grep
368) if executable('rg')
369)     " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
370)     set grepprg=rg
371) endif
372) " Navigate quickfix list with ease
373) nnoremap <silent> [q :cprevious<CR>
374) nnoremap <silent> ]q :cnext<CR>
375) 
dblume Add DiffOrig from the vim h...

dblume authored 7 months ago

376) " From `:help :DiffOrig`.
dblume Make "set ruler!" change st...

dblume authored 7 months ago

377) if exists(":DiffOrig") != 2
378)   command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_
dblume Add DiffOrig from the vim h...

dblume authored 7 months ago

379)     \ | diffthis | wincmd p | diffthis
dblume Make "set ruler!" change st...

dblume authored 7 months ago

380) endif
dblume Add DiffOrig from the vim h...

dblume authored 7 months ago

381)