3dd469eb3512805002113ee9fa6869ad7ed000b5
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 Add Neovim configs

dblume authored 8 months ago

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

dblume authored 8 months ago

41) set colorcolumn=80
dblume Add Neovim configs

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

61) 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

62) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

63) " May want to "set mouse=" See https://neovim.io/doc/user/vim_diff.html#_default-mouse
64) " set mouse=v  " visual mode, not great in PuTTY, neovim defaults to nvi
dblume Add Neovim configs

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

72) set tags=tags;/
73) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

74) set history=500
dblume Add Neovim configs

dblume authored 8 months ago

75) 
dblume Retrieve git branch only on...

dblume authored 7 months ago

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

dblume authored 8 months ago

77)   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 8 months ago

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

dblume authored 8 months ago

79) endfunction
80) 
dblume Only show encoding and form...

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

301) 
dblume Only show encoding and form...

dblume authored 7 months ago

302)   autocmd BufNewFile,BufReadPost *
303)   \ let b:git_branch = GitBranch() |
304)   \ let b:enc_fmt = EncodingAndFormat()
305)   autocmd BufEnter *
306)   \ let b:git_branch = GitBranch() |
307)   \ let b:enc_fmt = EncodingAndFormat()
dblume Add Neovim configs

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

376)