270d7ad57b8d69fae6bd224a3c80992318944041
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
dblume Use build-in style for nvim...

dblume authored 7 months ago

7) set listchars+=tab:>-,precedes:<,extends:>,nbsp:·,eol:\\u21b5 " for :set list
dblume Add Neovim configs

dblume authored 8 months ago

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'
dblume Map Tab and CR to pull-up-m...

dblume authored 7 months ago

27) inoremap <expr> <Tab> pumvisible() ? '<Down>' : '<Tab>'
28) inoremap <expr> <S-Tab> pumvisible() ? '<Up>' : '<S-Tab>'
29) inoremap <expr> <cr> pumvisible() ? '<C-y>' : '<cr>'
dblume Add Neovim configs

dblume authored 8 months ago

30) 
31) " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
32) nnoremap <leader>v <C-w>v<C-w>l
33) nnoremap <C-h> <C-w>h
34) nnoremap <C-j> <C-w>j
35) nnoremap <C-k> <C-w>k
36) nnoremap <C-l> <C-w>l
37) 
38) " clear search highlights
39) nnoremap <cr> :noh<cr><cr>
40) 
dblume When Tab distinguished from...

dblume authored 6 months ago

41) " Use (Shift-)Tab to switch buffers if Tab different than C-i (usually not in tmux).
42) " Test with this:
43) " nvim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
44) if stridx(expand($TERM), 'xterm') == 0
45)   nnoremap <C-i> <C-i>
46)   nnoremap <Tab> :bn<cr>
47) endif
dblume Restore Ctrl-i (Tab) to mea...

dblume authored 6 months ago

48) nnoremap <S-Tab> :bp<cr>
dblume Add Neovim configs

dblume authored 8 months ago

49) 
50) set t_Co=256
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

51) set colorcolumn=80
dblume Add Neovim configs

dblume authored 8 months ago

52) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
53)   " Light backgrounds for GUI experiences
54)   set background=light
55)   " colorscheme peaksea
56)   colorscheme tolerable
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

60)   if has('win32')
61)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
62)   endif
63)   set lines=50 columns=100
64) else
65)   " Dark backgrounds for tty experiences
66)   set background=dark
67)   colorscheme nvim_desert
68) endif
69) 
dblume Vim insert mode's blue shou...

dblume authored 7 months ago

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

dblume authored 7 months ago

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

72) 
dblume Restore cursor line number...

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

76) " Make c-] show a list of tags, or jump straight if only single tag
77) nnoremap <c-]> g<c-]>
78) vnoremap <c-]> g<c-]>
79) nnoremap g<c-]> <c-]>
80) vnoremap g<c-]> <c-]>
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

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

dblume authored 8 months ago

82) set tags=tags;/
83) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

84) set history=500
dblume Add Neovim configs

dblume authored 8 months ago

85) 
dblume Retrieve git branch only on...

dblume authored 7 months ago

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

dblume authored 8 months ago

87)   let l:branchname = system("git -C " . expand('%:p:h') . " rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
dblume Add the powerline git char...

dblume authored 7 months ago

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

dblume authored 8 months ago

89) endfunction
90) 
dblume Only show encoding and form...

dblume authored 7 months ago

91) function! EncodingAndFormat()
92)   if (len(&fileencoding) && &fileencoding != 'utf-8') || &fileformat != 'unix'
93)     return &fileencoding?&fileencoding:&encoding .'['. &fileformat . '] │ '
94)   endif
95)   return ''
96) endfunction
97) 
dblume Make "set ruler!" change st...

dblume authored 7 months ago

98) function! OnRuler()
99)   if &ruler
100)     return '│ '.line('.').':'.col('.').' '
101)   endif
102)   return ''
103) endfunction
104) 
dblume Add Neovim configs

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

133) set statusline+=\ │\ %f
134) set statusline+=%m
135) set statusline+=\ %r
136) set statusline+=\ %=
137) set statusline+=%h
138) set statusline+=\ %{Trim_brackets(&filetype)}
139) set statusline+=\ %#StatusLineNC#
dblume Only show encoding and form...

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

144) 
145) " Fast saving
146) nmap <leader>w :w!<cr>
147) " I use relative number for cursor movement.
148) nmap <leader>r :set relativenumber!<cr>
149) nmap <leader>n :set number!<cr>
150) 
151) " Useful mappings for managing tabs
152) " Tab Previous: gT or C-PageUp
153) " Tab Next: gt or C-PageDown
154) nmap <leader>tn :tabnew
155) nmap <leader>to :tabonly<cr>
156) nmap <leader>tc :tabclose<cr>
157) nmap <leader>tm :tabmove
158) nmap <leader>1 1gt
159) nmap <leader>2 2gt
160) nmap <leader>3 3gt
161) nmap <leader>4 4gt
162) nmap <leader>5 5gt
163) nmap <leader>6 6gt
164) nmap <leader>7 7gt
165) nmap <leader>8 8gt
166) nmap <leader>9 9gt
167) 
168) " Open current buffer in new tab. Close with C-w,c
169) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
170) function! OpenCurrentAsNewTab()
171)     let l:currentView = winsaveview()
172)     tabedit %
173)     call winrestview(l:currentView)
174) endfunction
175) nmap <leader>o :call OpenCurrentAsNewTab()<CR>
176) 
177) " pastetoggle
178) nmap <leader>p :set invpaste paste?<cr>
179) 
180) " Control+p to paste onto next line
181) nmap <C-p> :pu<cr>
182) 
183) " Make netrw's Explore behave a little like NERDTreeToggle
184) " http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
185) function! ToggleNetrw()
186)   if bufwinnr("NetrwTreeListing") > 0
187)     for i in range(1, bufnr("$"))
188)       if (getbufvar(i, "&filetype") == "netrw")
189)         silent exe "bwipeout " . i
190)         return
191)       endif
192)     endfor
193)   endif
194)   silent Vexplore %:p:h
195) endfunction
196) nmap <leader>e :call ToggleNetrw()<cr>
197) 
198) " install taglist
199) let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
200) let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
201) let Tlist_Close_On_Select = 1          " Close taglist window on select
dblume Disable taglist's auto resi...

dblume authored 7 months ago

202) let Tlist_Inc_Winwidth = 0             " Only needed for neovim in tmux
dblume Add Neovim configs

dblume authored 8 months ago

203) nmap <leader>l :TlistToggle<cr>
204) 
205) " install vim-bbye
206) nmap <leader>bd :Bdelete<cr>
207) 
208) " Visual mode mappings
209) """
210) 
211) " map sort function to a key
212) vnoremap <leader>s :sort<cr>
213) 
214) "easier moving of code blocks
215) vnoremap < <gv
216) vnoremap > >gv
217) 
218) " If too many file system events are getting triggered.
219) set nobackup       " ~ files
220) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
221) set noswapfile     " .swp files
222) 
223) " Switch between source and header files
224) function! SwitchSourceHeader()
225)   let s:ext  = expand("%:e")
226)   let s:base = expand("%:t:r")
227)   let s:cmd  = "find " . s:base
228)   if (s:ext == "cpp" || s:ext == "c")
229)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
230)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
231)   else
232)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
233)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
234)   endif
235) endfunc
236) 
237) " Demonstrates a way to look in a mirror directory
238) " function! OpenOther()
239) "    if expand("%:e") == "cpp"
240) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
241) "    elseif expand("%:e") == "h"
242) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
243) "    endif
244) " endfunc
245) 
246) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
247) function! DeleteTrailingWS()
248)   exe "normal mz"
249)   %s/\s\+$//ge
250)   exe "normal `z"
251) endfunc
252) 
253) function! OpenInOtherWindow()
254)   if winnr('$') == 1
255)     exe "wincmd F"
256)   else
257)     let curNum = winnr()
258)     let oldBuf = bufnr( "%" )
259)     if curNum == 1
260)       let othNum = 2
261)     else
262)       let othNum = 1
263)     endif
264)     exe "normal! gF"
265)     let newBuf = bufnr( "%" )
266)     let newLine = line(".")
267)     exe 'hide buf' oldBuf
268)     exe othNum . "wincmd w"
269)     exe 'hide buf' newBuf
270)     exe "normal! " . newLine . "G"
271)   endif
272) endfunc
273) 
274) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
275) nmap <silent> <leader>f :call OpenInOtherWindow()<cr>
276) 
277) if has("autocmd")
278)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
279)   " Don't let smartindent unindent the # character in Python files
280)   autocmd FileType python  inoremap # X<c-h>#
281)   autocmd FileType python,c,cpp,php,brs,sh  set expandtab  " Use spaces instead of tabs
282)   autocmd Filetype make    setl noexpandtab       " ...not for files that use tabs.
283) 
284)   " Use the vim command %retab before applying the following
285)   " two with files that have 8-space tabs.
286)   autocmd FileType c,cpp,python,php  set tabstop=4
287)   autocmd FileType c,cpp,php  set shiftwidth=4
288) 
289)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
290) 
291)   autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
292)   autocmd FileType c,cpp set foldmethod=syntax
293) 
dblume Improve focus-based switchi...

dblume authored 7 months ago

294) " https://jeffkreeftmeijer.com/vim-number/
295) augroup numbertoggle
296)   autocmd!
297)   autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu   | endif
298)   autocmd BufLeave,FocusLost,InsertEnter,WinLeave   * if &nu                  | set nornu | endif
299) augroup END
dblume Add Neovim configs

dblume authored 8 months ago

300) 
301)   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
302)   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
303)   autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
304) 
dblume Always start on first line...

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

312) 
dblume Only show encoding and form...

dblume authored 7 months ago

313)   autocmd BufNewFile,BufReadPost *
314)   \ let b:git_branch = GitBranch() |
315)   \ let b:enc_fmt = EncodingAndFormat()
316)   autocmd BufEnter *
317)   \ let b:git_branch = GitBranch() |
318)   \ let b:enc_fmt = EncodingAndFormat()
dblume Don't set cursorline if we'...

dblume authored 7 months ago

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

dblume authored 8 months ago

322) endif
323) 
324) " This requires vim to be compiled with +python
325) " Use auto complete in insert mode with ctrl-x, ctrl-o
326) " See :help new-omni-completion for more.
327) filetype plugin on
328) set omnifunc=syntaxcomplete#Complete
329) 
330) " Torn on whether I like the omni completion preview window left open or not.
331) " autocmd CompleteDone * pclose
332) 
333) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
dblume Sensibly, in neovim <C-Spac...

dblume authored 7 months ago

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

dblume authored 8 months ago

335) 
dblume Add commands SynStack and H...

dblume authored 6 months ago

336) " These two commands display syntax/highlight info for what's under the cursor.
337) if exists(":SynStack") != 2
338)     command SynStack :echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
339) endif
340) 
341) function! SynGroup()
342)     let l:s = synID(line('.'), col('.'), 1)
343)     echo synIDattr(l:s, 'name') . ' -> ' . synIDattr(synIDtrans(l:s), 'name')
344) endfun
345) command Hi :call SynGroup()
dblume Add Neovim configs

dblume authored 8 months ago

346) 
347) " From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
348) " :grep term %
349) " :grep -r term path/
350) " :cw
351) " :ccl (or C-w,q)
352) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
353) 
354) function! MaybeSortQuickfix(fn)
355) "    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
356)     let t = getqflist({'title': 1}).title
357)     " Only sort the files if for search-style commands, not "make".
358)     if stridx(t, "cs ") == 0 || stridx(t, ":gr") == 0 || stridx(t, ":vim") == 0 || stridx(t, ":rg") == 0
359)         call setqflist(sort(getqflist(), a:fn), 'r')
360)         call setqflist([], 'r', {'title': t})
361)     endif
362)     cwindow
363) endfunction
364) 
365) function! QfStrCmp(e1, e2)
366)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
367)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
368) endfunction
369) 
370) " Use ripgrep for search instead of grep
371) if executable('rg')
372)     " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
373)     set grepprg=rg
374) endif
375) " Navigate quickfix list with ease
376) nnoremap <silent> [q :cprevious<CR>
377) nnoremap <silent> ]q :cnext<CR>
378) 
dblume Add DiffOrig from the vim h...

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

384) 
dblume Add Neovim configs

dblume authored 8 months ago

385) " I use Roboto Mono from https://github.com/powerline/fonts
386) " On iTerm2, Preferences -> Profiles -> Text -> Font
387) " Cygwin64 won't let you choose it. Launch Cygwin64 as follows:
388) " C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -o Font="Roboto Mono for Powerline" -
389) 
390) " Settings that make netrw more like NERDTree
391) let g:netrw_banner = 0
392) let g:netrw_liststyle = 3
393) let g:netrw_browse_split = 4
394) let g:netrw_altv = 1
395) " set g:netrw_winsize to negative for absolute width, positive for relative
396) let g:netrw_winsize = -36
397) " let g:netrw_winsize = 35
398) " sort is affecting only: directories on the top, files below
399) let g:netrw_sort_sequence = '[\/]$,*'
400) 
401) " Experimenting with vim-rooter
402) let g:rooter_patterns = ['.git', 'Makefile', 'builds/']
403) let g:rooter_cd_cmd = 'lcd'
404) let g:rooter_manual_only = 1
405) 
dblume Add commands SynStack and H...

dblume authored 6 months ago

406) " See https://wiki.dlma.com/neovim#cscope
407) lua << EOF
408)   require('cscope_maps').setup()
409) EOF
410)