028880fb6e61d6fdc78ea24f6949c897e06ce3a0
dblume Remove explicit settings th...

dblume authored 1 year ago

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

dblume authored 1 year 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 1 year ago

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

dblume authored 1 year 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 1 year ago

14) set hidden          " Don't abandon Scratch buffer when hidden.
dblume Add Neovim configs

dblume authored 1 year ago

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

dblume authored 1 year ago

45) set colorcolumn=80
dblume Add Neovim configs

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

54)   if has('win32')
55)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
56)   endif
57)   set lines=50 columns=100
58) else
59)   " Dark backgrounds for tty experiences
60)   set background=dark
61)   colorscheme nvim_desert
62) endif
63) 
dblume Soften the status line colo...

dblume authored 11 months ago

64) au InsertEnter * hi statusline guibg=Cyan ctermfg=26 guifg=Black ctermbg=248
dblume Add Neovim configs

dblume authored 1 year ago

65) au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=24 ctermbg=250 guifg=black guibg=#c2bfa5
66) 
dblume First tweaks for neovim, tw...

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

73) set history=500
dblume Add Neovim configs

dblume authored 1 year ago

74) 
dblume Retrieve git branch only on...

dblume authored 11 months ago

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

dblume authored 11 months ago

76)   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 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

300) 
dblume Only show encoding and form...

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

375)