e8b2a559f37fab3200c82dc91140b88a7d06176c
dblume Remove explicit settings th...

dblume authored 11 months ago

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

dblume authored 11 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 10 months ago

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

dblume authored 11 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 11 months ago

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

dblume authored 11 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 11 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

16) set culopt=number   " Otherwise diff views have an underline. neovim issue 9800
dblume tmux and vim to set termina...

dblume authored 9 months ago

17) set title           " Set the title of the terminal window
dblume Add Neovim configs

dblume authored 11 months ago

18) 
19) " Make j and k move to the next row, not file line
20) nnoremap j gj
21) nnoremap k gk
22) 
23) " From Steve Losh: http://learnvimscriptthehardway.stevelosh.com/chapters/10.html
24) " Map jk to ESC in insert mode (except when navigating popup menu)
25) inoremap <expr> jk pumvisible() ? '' : '<esc>'
26) inoremap <expr> j pumvisible() ? '<Down>' : 'j'
27) inoremap <expr> k pumvisible() ? '<Up>' : 'k'
dblume Map Tab and CR to pull-up-m...

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 9 months ago

42) " tmux 3.2+ doesn't send C-i, so have Alacritty iTerm2 map C-i to <leader>i
43) " iTerm2: Settings > Keys > Key Bindings > + > Shortcut:^i Action:Send Text "\i"
dblume Alacritty+tmux: Map <C-i> t...

dblume authored 9 months ago

44) nnoremap <leader>i <C-i>
dblume Have terminal emulator send...

dblume authored 9 months ago

45) " Use (Shift-)Tab to navigate buffers, retain C-i/C-o for jumps.
dblume When Tab distinguished from...

dblume authored 9 months ago

46) " Test with this:
47) " nvim -Nu NONE +'nno <C-i> :echom "C-i pressed"<cr>' +'nno <tab> :echom "Tab pressed"<cr>'
dblume Have terminal emulator send...

dblume authored 9 months ago

48) "if stridx(expand($TERM), 'xterm') == 0
dblume When Tab distinguished from...

dblume authored 9 months ago

49)   nnoremap <C-i> <C-i>
dblume Alacritty+tmux: Map <C-i> t...

dblume authored 9 months ago

50)   nmap <Tab> :bn<cr>
dblume Have terminal emulator send...

dblume authored 9 months ago

51) "endif
dblume Restore Ctrl-i (Tab) to mea...

dblume authored 9 months ago

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

dblume authored 11 months ago

53) 
54) set t_Co=256
dblume First tweaks for neovim, tw...

dblume authored 11 months ago

55) set colorcolumn=80
dblume Add Neovim configs

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 11 months ago

76) 
dblume Restore cursor line number...

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

86) set tags=tags;/
87) 
dblume First tweaks for neovim, tw...

dblume authored 11 months ago

88) set history=500
dblume Add Neovim configs

dblume authored 11 months ago

89) 
dblume Retrieve git branch only on...

dblume authored 11 months ago

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

dblume authored 11 months ago

91)   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 10 months ago

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

dblume authored 11 months ago

93) endfunction
94) 
dblume Only show encoding and form...

dblume authored 10 months ago

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

dblume authored 10 months ago

102) function! OnRuler()
103)   if &ruler
104)     return '│ '.line('.').':'.col('.').' '
105)   endif
106)   return ''
107) endfunction
108) 
dblume Add Neovim configs

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

137) set statusline+=\ │\ %f
138) set statusline+=%m
139) set statusline+=\ %r
140) set statusline+=\ %=
141) set statusline+=%h
142) set statusline+=\ %{Trim_brackets(&filetype)}
143) set statusline+=\ %#StatusLineNC#
dblume Only show encoding and form...

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

311)   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
dblume When openging files jump to...

dblume authored 9 months ago

312)   \   exe "normal! g`\"" |
dblume Add Neovim configs

dblume authored 11 months ago

313)   \ endif
dblume Always start on first line...

dblume authored 11 months ago

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

dblume authored 11 months ago

316) 
dblume Only show encoding and form...

dblume authored 10 months ago

317)   autocmd BufNewFile,BufReadPost *
318)   \ let b:git_branch = GitBranch() |
319)   \ let b:enc_fmt = EncodingAndFormat()
320)   autocmd BufEnter *
321)   \ let b:git_branch = GitBranch() |
322)   \ let b:enc_fmt = EncodingAndFormat()
dblume Don't set cursorline if we'...

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

339) 
dblume Add commands SynStack and H...

dblume authored 10 months ago

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

dblume authored 11 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

388) 
dblume Add Neovim configs

dblume authored 11 months ago

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

dblume authored 10 months ago

410) " See https://wiki.dlma.com/neovim#cscope
411) lua << EOF
412)   require('cscope_maps').setup()
413) EOF
414)