Remove explicit settings th...
dblume authored 11 months ago
|
1) " Version 2024-03-07.1 - First misc fixes
|
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
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
|
Remove explicit settings th...
dblume authored 11 months ago
|
11) set undofile " undo even after closing and reopening a file
|
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
|
nvim set hidden
dblume authored 11 months ago
|
14) set hidden " Don't abandon Scratch buffer when hidden.
|
Restore cursor line number...
dblume authored 10 months ago
|
15) set cursorline " For CursorLineNR formatting similar to pre 8.0.
|
Add Neovim configs
dblume authored 11 months ago
|
16)
17) " Make j and k move to the next row, not file line
18) nnoremap j gj
19) nnoremap k gk
20)
21) " From Steve Losh: http://learnvimscriptthehardway.stevelosh.com/chapters/10.html
22) " Map jk to ESC in insert mode (except when navigating popup menu)
23) inoremap <expr> jk pumvisible() ? '' : '<esc>'
24) inoremap <expr> j pumvisible() ? '<Down>' : 'j'
25) inoremap <expr> k pumvisible() ? '<Up>' : 'k'
26)
27) " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
28) nnoremap <leader>v <C-w>v<C-w>l
29) nnoremap <C-h> <C-w>h
30) nnoremap <C-j> <C-w>j
31) nnoremap <C-k> <C-w>k
32) nnoremap <C-l> <C-w>l
33)
34) " clear search highlights
35) nnoremap <cr> :noh<cr><cr>
36)
37) " tab switches to previous/next buffer
38) nnoremap <Tab> :bp<cr>
39) nnoremap <S-Tab> :bn<cr>
40)
41) set t_Co=256
|
First tweaks for neovim, tw...
dblume authored 11 months ago
|
42) set colorcolumn=80
|
Add Neovim configs
dblume authored 11 months ago
|
43) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
44) " Light backgrounds for GUI experiences
45) set background=light
46) " colorscheme peaksea
47) colorscheme tolerable
|
First tweaks for neovim, tw...
dblume authored 11 months ago
|
48) highlight ColorColumn ctermbg=255 guibg=#F6F6F6
|
nvim ColorColumn was inverted
dblume authored 11 months ago
|
49) highlight statusline ctermfg=17 ctermbg=Gray " override scheme
50) highlight statuslineNC ctermfg=20 ctermbg=LightGray " override scheme
|
Add Neovim configs
dblume authored 11 months ago
|
51) if has('win32')
52) set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
53) endif
54) set lines=50 columns=100
55) else
56) " Dark backgrounds for tty experiences
57) set background=dark
58) colorscheme nvim_desert
59) endif
60)
|
Vim insert mode's blue shou...
dblume authored 10 months ago
|
61) au InsertEnter * hi statusline guibg=Cyan ctermfg=25 guifg=Black ctermbg=248
|
Make the normal statusbar m...
dblume authored 10 months ago
|
62) au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=23 ctermbg=250 guifg=black guibg=#c2bfa5
|
Add Neovim configs
dblume authored 11 months ago
|
63)
|
Restore cursor line number...
dblume authored 10 months ago
|
64) " See https://neovim.io/doc/user/vim_diff.html#_default-mouse
65) set mouse= " neovim defaults to nvi
|
Add Neovim configs
dblume authored 11 months ago
|
66)
|
Make c-] show taglist like...
dblume authored 10 months ago
|
67) " Make c-] show a list of tags, or jump straight if only single tag
68) nnoremap <c-]> g<c-]>
69) vnoremap <c-]> g<c-]>
70) nnoremap g<c-]> <c-]>
71) vnoremap g<c-]> <c-]>
|
First tweaks for neovim, tw...
dblume authored 11 months ago
|
72) " Consider neovim default "./tags;,tags"
|
Add Neovim configs
dblume authored 11 months ago
|
73) set tags=tags;/
74)
|
First tweaks for neovim, tw...
dblume authored 11 months ago
|
75) set history=500
|
Add Neovim configs
dblume authored 11 months ago
|
76)
|
Retrieve git branch only on...
dblume authored 11 months ago
|
77) function! GitBranch()
|
Make vim StatuslineGit() re...
dblume authored 11 months ago
|
78) let l:branchname = system("git -C " . expand('%:p:h') . " rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
|
Make git branch fit on stat...
dblume authored 11 months ago
|
79) return strlen(l:branchname) > 0 ? ' │ '.l:branchname : ''
|
Add Neovim configs
dblume authored 11 months ago
|
80) endfunction
81)
|
Only show encoding and form...
dblume authored 10 months ago
|
82) function! EncodingAndFormat()
83) if (len(&fileencoding) && &fileencoding != 'utf-8') || &fileformat != 'unix'
84) return &fileencoding?&fileencoding:&encoding .'['. &fileformat . '] │ '
85) endif
86) return ''
87) endfunction
88)
|
Make "set ruler!" change st...
dblume authored 10 months ago
|
89) function! OnRuler()
90) if &ruler
91) return '│ '.line('.').':'.col('.').' '
92) endif
93) return ''
94) endfunction
95)
|
Add Neovim configs
dblume authored 11 months ago
|
96) function! Current_mode()
97) let l:currentmode={
98) \ 'n' : 'NORMAL',
99) \ 'v' : 'VISUAL',
100) \ 'V' : 'V·LINE',
101) \ '' : 'V·BLOCK',
102) \ 's' : 'SELECT',
103) \ 'S' : 'S·LINE',
104) \ 'i' : 'INSERT',
105) \ 'r' : 'I·REPLACE',
106) \ 'R' : 'REPLACE',
107) \ 'Rv' : 'V·REPLACE',
108) \ 'c' : 'COMMAND',
109) \}
110) return get(l:currentmode, mode(), mode())
111) endfunction
112)
113) function! Trim_brackets(fn)
114) if v:version > 800
115) return trim(a:fn, "[]")
116) else
117) return a:fn
118) endif
119) endfunction
120)
121) set statusline=\ %{Current_mode()}
122) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
|
Retrieve git branch only on...
dblume authored 11 months ago
|
123) set statusline+=%{b:git_branch}
|
Add Neovim configs
dblume authored 11 months ago
|
124) set statusline+=\ │\ %f
125) set statusline+=%m
126) set statusline+=\ %r
127) set statusline+=\ %=
128) set statusline+=%h
129) set statusline+=\ %{Trim_brackets(&filetype)}
130) set statusline+=\ %#StatusLineNC#
|
Only show encoding and form...
dblume authored 10 months ago
|
131) set statusline+=\ %{b:enc_fmt}
132) set statusline+=%p%%\ of
|
Drop column and line number...
dblume authored 11 months ago
|
133) set statusline+=\ %L\
|
Make "set ruler!" change st...
dblume authored 10 months ago
|
134) set statusline+=%{OnRuler()}
|
Add Neovim configs
dblume authored 11 months ago
|
135)
136) " Fast saving
137) nmap <leader>w :w!<cr>
138) " I use relative number for cursor movement.
139) nmap <leader>r :set relativenumber!<cr>
140) nmap <leader>n :set number!<cr>
141)
142) " Useful mappings for managing tabs
143) " Tab Previous: gT or C-PageUp
144) " Tab Next: gt or C-PageDown
145) nmap <leader>tn :tabnew
146) nmap <leader>to :tabonly<cr>
147) nmap <leader>tc :tabclose<cr>
148) nmap <leader>tm :tabmove
149) nmap <leader>1 1gt
150) nmap <leader>2 2gt
151) nmap <leader>3 3gt
152) nmap <leader>4 4gt
153) nmap <leader>5 5gt
154) nmap <leader>6 6gt
155) nmap <leader>7 7gt
156) nmap <leader>8 8gt
157) nmap <leader>9 9gt
158)
159) " Open current buffer in new tab. Close with C-w,c
160) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
161) function! OpenCurrentAsNewTab()
162) let l:currentView = winsaveview()
163) tabedit %
164) call winrestview(l:currentView)
165) endfunction
166) nmap <leader>o :call OpenCurrentAsNewTab()<CR>
167)
168) " pastetoggle
169) nmap <leader>p :set invpaste paste?<cr>
170)
171) " Control+p to paste onto next line
172) nmap <C-p> :pu<cr>
173)
174) " Make netrw's Explore behave a little like NERDTreeToggle
175) " http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
176) function! ToggleNetrw()
177) if bufwinnr("NetrwTreeListing") > 0
178) for i in range(1, bufnr("$"))
179) if (getbufvar(i, "&filetype") == "netrw")
180) silent exe "bwipeout " . i
181) return
182) endif
183) endfor
184) endif
185) silent Vexplore %:p:h
186) endfunction
187) nmap <leader>e :call ToggleNetrw()<cr>
188)
189) " install taglist
190) let Tlist_GainFocus_On_ToggleOpen = 1 " Jump to taglist window on open
191) let Tlist_Exit_OnlyWindow = 1 " if you are the last, kill yourself
192) let Tlist_Close_On_Select = 1 " Close taglist window on select
193) nmap <leader>l :TlistToggle<cr>
194)
195) " install vim-bbye
196) nmap <leader>bd :Bdelete<cr>
197)
198) " Visual mode mappings
199) """
200)
201) " map sort function to a key
202) vnoremap <leader>s :sort<cr>
203)
204) "easier moving of code blocks
205) vnoremap < <gv
206) vnoremap > >gv
207)
208) " If too many file system events are getting triggered.
209) set nobackup " ~ files
210) set nowritebackup " Don't write buff to temp, delete orig, rename temp to orig
211) set noswapfile " .swp files
212)
213) " Switch between source and header files
214) function! SwitchSourceHeader()
215) let s:ext = expand("%:e")
216) let s:base = expand("%:t:r")
217) let s:cmd = "find " . s:base
218) if (s:ext == "cpp" || s:ext == "c")
219) if findfile(s:base . ".h" ) != "" | exe s:cmd . ".h" | return | en
220) if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
221) else
222) if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
223) if findfile(s:base . ".c" ) != "" | exe s:cmd . ".c" | return | en
224) endif
225) endfunc
226)
227) " Demonstrates a way to look in a mirror directory
228) " function! OpenOther()
229) " if expand("%:e") == "cpp"
230) " exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
231) " elseif expand("%:e") == "h"
232) " exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
233) " endif
234) " endfunc
235)
236) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
237) function! DeleteTrailingWS()
238) exe "normal mz"
239) %s/\s\+$//ge
240) exe "normal `z"
241) endfunc
242)
243) function! OpenInOtherWindow()
244) if winnr('$') == 1
245) exe "wincmd F"
246) else
247) let curNum = winnr()
248) let oldBuf = bufnr( "%" )
249) if curNum == 1
250) let othNum = 2
251) else
252) let othNum = 1
253) endif
254) exe "normal! gF"
255) let newBuf = bufnr( "%" )
256) let newLine = line(".")
257) exe 'hide buf' oldBuf
258) exe othNum . "wincmd w"
259) exe 'hide buf' newBuf
260) exe "normal! " . newLine . "G"
261) endif
262) endfunc
263)
264) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
265) nmap <silent> <leader>f :call OpenInOtherWindow()<cr>
266)
267) if has("autocmd")
268) autocmd BufWrite *.py :call DeleteTrailingWS() " Delete trailing whitespace
269) " Don't let smartindent unindent the # character in Python files
270) autocmd FileType python inoremap # X<c-h>#
271) autocmd FileType python,c,cpp,php,brs,sh set expandtab " Use spaces instead of tabs
272) autocmd Filetype make setl noexpandtab " ...not for files that use tabs.
273)
274) " Use the vim command %retab before applying the following
275) " two with files that have 8-space tabs.
276) autocmd FileType c,cpp,python,php set tabstop=4
277) autocmd FileType c,cpp,php set shiftwidth=4
278)
279) autocmd FileType python set foldmethod=indent " 'za' to fold
280)
281) autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
282) autocmd FileType c,cpp set foldmethod=syntax
283)
|
Improve focus-based switchi...
dblume authored 10 months ago
|
284) " https://jeffkreeftmeijer.com/vim-number/
285) augroup numbertoggle
286) autocmd!
287) autocmd BufEnter,FocusGained,InsertLeave,WinEnter * if &nu && mode() != "i" | set rnu | endif
288) autocmd BufLeave,FocusLost,InsertEnter,WinLeave * if &nu | set nornu | endif
289) augroup END
|
Add Neovim configs
dblume authored 11 months ago
|
290)
291) autocmd BufRead *.txt set wrap linebreak " "soft" wrap of existing lines
292) autocmd BufRead README set wrap linebreak " "soft" wrap of existing lines
293) autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
294)
|
Always start on first line...
dblume authored 11 months ago
|
295) " When editing a file, always jump to the last cursor position...
|
Add Neovim configs
dblume authored 11 months ago
|
296) autocmd BufReadPost *
|
Always start on first line...
dblume authored 11 months ago
|
297) \ if line("'\"") > 0 && line ("'\"") <= line("$") |
|
Add Neovim configs
dblume authored 11 months ago
|
298) \ exe "normal! g'\"" |
299) \ endif
|
Always start on first line...
dblume authored 11 months ago
|
300) " ...except for gitcommit where we always want to start at the top
301) autocmd FileType gitcommit exe "normal! gg"
|
Retrieve git branch only on...
dblume authored 11 months ago
|
302)
|
Only show encoding and form...
dblume authored 10 months ago
|
303) autocmd BufNewFile,BufReadPost *
304) \ let b:git_branch = GitBranch() |
305) \ let b:enc_fmt = EncodingAndFormat()
306) autocmd BufEnter *
307) \ let b:git_branch = GitBranch() |
308) \ let b:enc_fmt = EncodingAndFormat()
|
Add Neovim configs
dblume authored 11 months ago
|
309) endif
310)
311) " This requires vim to be compiled with +python
312) " Use auto complete in insert mode with ctrl-x, ctrl-o
313) " See :help new-omni-completion for more.
314) filetype plugin on
315) set omnifunc=syntaxcomplete#Complete
316)
317) " Torn on whether I like the omni completion preview window left open or not.
318) " autocmd CompleteDone * pclose
319)
320) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
|
Sensibly, in neovim <C-Spac...
dblume authored 11 months ago
|
321) inoremap <C-Space> <C-x><C-o>
|
Add Neovim configs
dblume authored 11 months ago
|
322)
323) " cscope
324) if has("cscope")
325) set cscopetag " Use both cscope and ctag for 'ctrl-]'
326) set csto=1 " 0=cscope first; 1=ctags first
327) set cscopequickfix=s-,c-,d-,i-,t-,e-,a- " cscope to quickfix window
328)
329) set nocsverb
330) " add any database in current directory
331) if filereadable("cscope.out")
332) cs add cscope.out
333) " else add database pointed to by environment
334) elseif $CSCOPE_DB != ""
335) cs add $CSCOPE_DB
336) endif
337) set csverb
338) endif
339)
340) " From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
341) " :grep term %
342) " :grep -r term path/
343) " :cw
344) " :ccl (or C-w,q)
345) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
346)
347) function! MaybeSortQuickfix(fn)
348) " exe 'normal! ' " Doesn't work. Wanted to jump back to where we were.
349) let t = getqflist({'title': 1}).title
350) " Only sort the files if for search-style commands, not "make".
351) if stridx(t, "cs ") == 0 || stridx(t, ":gr") == 0 || stridx(t, ":vim") == 0 || stridx(t, ":rg") == 0
352) call setqflist(sort(getqflist(), a:fn), 'r')
353) call setqflist([], 'r', {'title': t})
354) endif
355) cwindow
356) endfunction
357)
358) function! QfStrCmp(e1, e2)
359) let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
360) return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
361) endfunction
362)
363) " Use ripgrep for search instead of grep
364) if executable('rg')
365) " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
366) set grepprg=rg
367) endif
368) " Navigate quickfix list with ease
369) nnoremap <silent> [q :cprevious<CR>
370) nnoremap <silent> ]q :cnext<CR>
371)
|
Add DiffOrig from the vim h...
dblume authored 10 months ago
|
372) " From `:help :DiffOrig`.
|
Make "set ruler!" change st...
dblume authored 10 months ago
|
373) if exists(":DiffOrig") != 2
374) command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_
|
Add DiffOrig from the vim h...
dblume authored 10 months ago
|
375) \ | diffthis | wincmd p | diffthis
|
Make "set ruler!" change st...
dblume authored 10 months ago
|
376) endif
|
Add DiffOrig from the vim h...
dblume authored 10 months ago
|
377)
|