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