f1f91d6872c09fb398e26ee41bfac3632b4e5d5a
dblume Remove explicit settings th...

dblume authored 10 months ago

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

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

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

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

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

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

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

dblume authored 9 months ago

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

dblume authored 9 months ago

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

dblume authored 8 months ago

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

dblume authored 10 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 9 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 10 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 Alacritty+tmux: Map <C-i> t...

dblume authored 8 months ago

42) " tmux in Alacritty doesn't send C-i, so I have Alacritty map C-i to <leader>i
43) nnoremap <leader>i <C-i>
dblume When Tab distinguished from...

dblume authored 8 months ago

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

dblume authored 8 months ago

49)   nmap <Tab> :bn<cr>
dblume When Tab distinguished from...

dblume authored 8 months ago

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

dblume authored 9 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

54) set colorcolumn=80
dblume Add Neovim configs

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

75) 
dblume Restore cursor line number...

dblume authored 9 months ago

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

dblume authored 10 months ago

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

dblume authored 9 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

87) set history=500
dblume Add Neovim configs

dblume authored 10 months ago

88) 
dblume Retrieve git branch only on...

dblume authored 10 months ago

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

dblume authored 10 months ago

90)   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 9 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 9 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 8 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

315) 
dblume Only show encoding and form...

dblume authored 10 months ago

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

dblume authored 9 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

338) 
dblume Add commands SynStack and H...

dblume authored 9 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

387) 
dblume Add Neovim configs

dblume authored 10 months ago

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

dblume authored 9 months ago

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