8c3cf8457d807a7cde2ebf9de097e708ca478d52
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 Clarify comment 'Shift-Tab'

dblume authored 6 months ago

41) " Shift-Tab switches to prev buffer
dblume Restore Ctrl-i (Tab) to mea...

dblume authored 6 months ago

42) " (Not remapping Tab because Ctrl-i in use as 'go to next jump pos')
43) nnoremap <S-Tab> :bp<cr>
dblume Add Neovim configs

dblume authored 8 months ago

44) 
45) set t_Co=256
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

46) set colorcolumn=80
dblume Add Neovim configs

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

67) 
dblume Restore cursor line number...

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 8 months ago

77) set tags=tags;/
78) 
dblume First tweaks for neovim, tw...

dblume authored 8 months ago

79) set history=500
dblume Add Neovim configs

dblume authored 8 months ago

80) 
dblume Retrieve git branch only on...

dblume authored 7 months ago

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

dblume authored 8 months ago

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

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

dblume authored 8 months ago

84) endfunction
85) 
dblume Only show encoding and form...

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

307) 
dblume Only show encoding and form...

dblume authored 7 months ago

308)   autocmd BufNewFile,BufReadPost *
309)   \ let b:git_branch = GitBranch() |
310)   \ let b:enc_fmt = EncodingAndFormat()
311)   autocmd BufEnter *
312)   \ let b:git_branch = GitBranch() |
313)   \ let b:enc_fmt = EncodingAndFormat()
dblume Don't set cursorline if we'...

dblume authored 7 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 8 months ago

330) 
dblume Add commands SynStack and H...

dblume authored 6 months ago

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

dblume authored 8 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

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

dblume authored 7 months ago

379) 
dblume Add Neovim configs

dblume authored 8 months ago

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

dblume authored 6 months ago

401) " See https://wiki.dlma.com/neovim#cscope
402) lua << EOF
403)   require('cscope_maps').setup()
404) EOF
405)