3471524e73e07920eda91a41fd271e8f59576ddb
dblume Add - as a word character

dblume authored 10 months ago

1) " Version 2023-12-15.1 - Stop using vim-airline
David Blume first commit

David Blume authored 8 years ago

2) set nocompatible    " Use Vim defaults, forget compatibility with vi.
3) set bs=2            " allow backspacing over everything in insert mode
4) set wildmenu        " Allows command-line completion with tab
5) set autoindent      " Copy indent from current line when starting a new line
6) set smartindent     " Do smart auto indenting when starting  new line
7) set smarttab        " Honor 'shiftwidth', 'tabstop' or 'softtabstop'
8) set hlsearch        " highlight all matches for previous search
dblume Better fold settings for zA

dblume authored 1 year ago

9) set foldlevel=99
David Blume first commit

David Blume authored 8 years ago

10) set nowrap          " no wrapping text lines on the screen (exceptions below)
11) set sidescroll=5
dblume May use nbsp in PS1; add it...

dblume authored 2 years ago

12) set listchars+=tab:>-,precedes:<,extends:>,nbsp:· " for :set list
dblume Add - as a word character

dblume authored 10 months ago

13) set iskeyword+=-    " Add - to list of non-word-breaking chars.
David Blume first commit

David Blume authored 8 years ago

14) 
15) if v:version >= 703
16)   " Do save the undo tree to file, but not in the local directory.
17)   " Don't forget to mkdir ~/.vim_undo
18)   set undodir=~/.vim_undo,.
19)   set undofile        " undo even after closing and reopening a file
20) endif
21) 
22) " The following two lines set the use of perl regex, aka "very magic"
23) nnoremap / /\v
24) vnoremap / /\v
25) 
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

26) " Make j and k move to the next row, not file line
27) nnoremap j gj
28) nnoremap k gk
29) 
30) " From Steve Losh: http://learnvimscriptthehardway.stevelosh.com/chapters/10.html
dblume Use j and k for navigating...

dblume authored 1 year ago

31) " Map jk to ESC in insert mode (except when navigating popup menu)
32) inoremap <expr> jk pumvisible() ? '' : '<esc>'
33) inoremap <expr> j pumvisible() ? '<Down>' : 'j'
34) inoremap <expr> k pumvisible() ? '<Up>' : 'k'
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

35) 
dblume Add easier window navigation.

dblume authored 2 years ago

36) " https://stevelosh.com/blog/2010/09/coming-home-to-vim/#s3-why-i-came-back-to-vim
37) nnoremap <leader>v <C-w>v<C-w>l
38) nnoremap <C-h> <C-w>h
39) nnoremap <C-j> <C-w>j
40) nnoremap <C-k> <C-w>k
41) nnoremap <C-l> <C-w>l
42) 
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

43) " clear search highlights
44) nnoremap <cr> :noh<cr><cr>
David Blume first commit

David Blume authored 8 years ago

45) 
dblume tab key navigation of buffers

dblume authored 1 year ago

46) " tab switches to previous/next buffer
47) nnoremap <Tab> :bp<cr>
48) nnoremap <S-Tab> :bn<cr>
49) 
David Blume first commit

David Blume authored 8 years ago

50) syntax on
51) 
52) set t_Co=256
53) if v:version >= 703
54)   set colorcolumn=80
55) endif
56) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
57)   " Light backgrounds for GUI experiences
58)   set background=light
59)   " colorscheme peaksea                        " install peaksea
60)   colorscheme tolerable                        " install tolerable
61)   if v:version >= 703
62)     highlight ColorColumn ctermbg=255 guibg=#F6F6F6
63)   endif
dblume Maybe I like these statusli...

dblume authored 11 months ago

64)   highlight statusline   ctermfg=17 ctermbg=Gray " override scheme
65)   highlight statuslineNC ctermfg=20 ctermbg=LightGray" override scheme
David Blume Specify a font for gvim on...

David Blume authored 4 years ago

66)   if has('win32')
67)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
68)   endif
David Blume first commit

David Blume authored 8 years ago

69)   set lines=50 columns=100
70) else
71)   " Dark backgrounds for tty experiences
72)   set background=dark
73)   colorscheme desert                           " install desert
74)   if v:version >= 703
David Blume Windows PuTTY shows ctermbg...

David Blume authored 6 years ago

75)     highlight ColorColumn ctermbg=233 guibg=Black " dark gray (or 17, dark blue)
David Blume first commit

David Blume authored 8 years ago

76)   endif
dblume Maybe I like these statusli...

dblume authored 11 months ago

77)   highlight statusline   ctermfg=24 ctermbg=250  " override scheme
78)   highlight statuslineNC ctermfg=236 ctermbg=Gray  " override scheme
dblume Better statusline color.

dblume authored 2 years ago

79)   highlight MatchParen   term=reverse ctermbg=23  " 23 is more subtle than default
David Blume first commit

David Blume authored 8 years ago

80) endif
dblume Better statusline color.

dblume authored 2 years ago

81) 
dblume vim insert mode to stand ou...

dblume authored 11 months ago

82) au InsertEnter * hi statusline guibg=Cyan ctermfg=20 guifg=Black ctermbg=248
dblume Maybe I like these statusli...

dblume authored 11 months ago

83) au InsertLeave * hi statusline term=bold,reverse cterm=bold,reverse ctermfg=24 ctermbg=250 guifg=black guibg=#c2bfa5
84) 
David Blume first commit

David Blume authored 8 years ago

85) " set mouse=v     " visual mode, not working great for PuTTY
86) 
87) set tags=tags;/
88) 
89) set history=50
dblume Update vim statusline to pr...

dblume authored 11 months ago

90) set laststatus=2
91) 
92) function! StatuslineGit()
93)   let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
94)   return strlen(l:branchname) > 0 ? ' | branch:'.l:branchname : ''
95) endfunction
96) 
97) "    \ '' : 'S·BLOCK',
98) let g:currentmode={
99)     \ 'n'  : 'NORMAL',
100)     \ 'v'  : 'VISUAL',
101)     \ 'V'  : 'V·LINE',
102)     \ '' : 'V·BLOCK',
103)     \ 's'  : 'SELECT',
104)     \ 'S'  : 'S·LINE',
105)     \ 'i'  : 'INSERT',
dblume Move vim gittab commands to...

dblume authored 10 months ago

106)     \ 'r'  : 'replace',
dblume Update vim statusline to pr...

dblume authored 11 months ago

107)     \ 'R'  : 'REPLACE',
108)     \ 'Rv' : 'V·REPLACE',
109)     \ 'c'  : 'COMMAND',
110)     \}
111) 
112) function! Trim_brackets(fn)
dblume Support older vim on raspi

dblume authored 11 months ago

113)   if v:version > 800
114)     return trim(a:fn, "[]")
115)   else
116)     return a:fn
117)   endif
dblume Update vim statusline to pr...

dblume authored 11 months ago

118) endfunction
119) 
120) set statusline=
121) set statusline+=\ %{g:currentmode[mode()]}
122) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
123) "set statusline+=%{StatuslineGit()}
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#
131) set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
132) set statusline+=\[%{&fileformat}\]
133) set statusline+=\ \|\ %p%%\ Ξ
134) set statusline+=\ %l/%L\ :\ %c
135) set statusline+=\ 
David Blume first commit

David Blume authored 8 years ago

136) 
137) set encoding=utf-8
138) 
dblume No comments after key mappi...

dblume authored 1 year ago

139) " Fast saving
140) nmap <leader>w :w!<cr>
David Blume first commit

David Blume authored 8 years ago

141) " I use relative number for cursor movement.
142) nmap <leader>r :set relativenumber!<cr>
143) nmap <leader>n :set number!<cr>
144) 
145) " Useful mappings for managing tabs
dblume Remove bad vim mappings for...

dblume authored 2 years ago

146) " Tab Previous: gT or C-PageUp
147) " Tab Next: gt or C-PageDown
David Blume first commit

David Blume authored 8 years ago

148) nmap <leader>tn :tabnew
149) nmap <leader>to :tabonly<cr>
150) nmap <leader>tc :tabclose<cr>
151) nmap <leader>tm :tabmove
dblume Add shortcuts for tab selec...

dblume authored 2 years ago

152) nmap <leader>1 1gt
153) nmap <leader>2 2gt
154) nmap <leader>3 3gt
155) nmap <leader>4 4gt
156) nmap <leader>5 5gt
157) nmap <leader>6 6gt
158) nmap <leader>7 7gt
159) nmap <leader>8 8gt
160) nmap <leader>9 9gt
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

161) 
162) " Open current buffer in new tab. Close with C-w,c
163) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
164) function! OpenCurrentAsNewTab()
dblume Restore entire window view...

dblume authored 2 years ago

165)     let l:currentView = winsaveview()
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

166)     tabedit %
dblume Restore entire window view...

dblume authored 2 years ago

167)     call winrestview(l:currentView)
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

168) endfunction
169) nmap <leader>o :call OpenCurrentAsNewTab()<CR>
David Blume first commit

David Blume authored 8 years ago

170) 
171) " pastetoggle
172) nmap <leader>p :set invpaste paste?<cr>
173) 
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

174) " Control+p to paste onto next line
175) nmap <C-p> :pu<cr>
176) 
David Blume Will use netrw's Explore in...

David Blume authored 3 years ago

177) " Make netrw's Explore behave a little like NERDTreeToggle
178) " http://vimcasts.org/blog/2013/01/oil-and-vinegar-split-windows-and-project-drawer/
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

179) function! ToggleNetrw()
David Blume Improve the toggling of the...

David Blume authored 3 years ago

180)   if bufwinnr("NetrwTreeListing") > 0
181)     for i in range(1, bufnr("$"))
182)       if (getbufvar(i, "&filetype") == "netrw")
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

183)         silent exe "bwipeout " . i
David Blume Improve the toggling of the...

David Blume authored 3 years ago

184)         return
185)       endif
186)     endfor
187)   endif
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

188)   silent Vexplore %:p:h
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

189) endfunction
190) nmap <leader>e :call ToggleNetrw()<cr>
191) 
dblume No comments after key mappi...

dblume authored 1 year ago

192) " install taglist
193) let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
194) let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
195) let Tlist_Close_On_Select = 1          " Close taglist window on select
196) nmap <leader>l :TlistToggle<cr>
197) 
198) " install vim-bbye
199) nmap <leader>bd :Bdelete<cr>
David Blume first commit

David Blume authored 8 years ago

200) 
201) " Visual mode mappings
202) """
203) 
204) " map sort function to a key
205) vnoremap <leader>s :sort<cr>
206) 
207) "easier moving of code blocks
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

208) vnoremap < <gv
209) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

210) 
211) " If too many file system events are getting triggered.
212) set nobackup       " ~ files
213) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
214) set noswapfile     " .swp files
215) 
216) " Allow tags to open another buffer even if this one is modified
217) set hidden
218) 
219) " Switch between source and header files
220) function! SwitchSourceHeader()
221)   let s:ext  = expand("%:e")
222)   let s:base = expand("%:t:r")
223)   let s:cmd  = "find " . s:base
224)   if (s:ext == "cpp" || s:ext == "c")
225)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
226)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
227)   else
228)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
229)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
230)   endif
231) endfunc
232) 
233) " Demonstrates a way to look in a mirror directory
234) " function! OpenOther()
235) "    if expand("%:e") == "cpp"
236) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
237) "    elseif expand("%:e") == "h"
238) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
239) "    endif
240) " endfunc
241) 
242) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
243) function! DeleteTrailingWS()
244)   exe "normal mz"
245)   %s/\s\+$//ge
246)   exe "normal `z"
247) endfunc
248) 
David Blume Add OpenInOtherWindow to .v...

David Blume authored 8 years ago

249) function! OpenInOtherWindow()
250)   if winnr('$') == 1
251)     exe "wincmd F"
252)   else
253)     let curNum = winnr()
254)     let oldBuf = bufnr( "%" )
255)     if curNum == 1
256)       let othNum = 2
257)     else
258)       let othNum = 1
259)     endif
260)     exe "normal! gF"
261)     let newBuf = bufnr( "%" )
262)     let newLine = line(".")
263)     exe 'hide buf' oldBuf
264)     exe othNum . "wincmd w"
265)     exe 'hide buf' newBuf
266)     exe "normal! " . newLine . "G"
267)   endif
268) endfunc
269) 
270) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
dblume Make OpenInOtherWindow easier.

dblume authored 2 years ago

271) nmap <silent> <leader>f :call OpenInOtherWindow()<cr>
David Blume Add OpenInOtherWindow to .v...

David Blume authored 8 years ago

272) 
David Blume first commit

David Blume authored 8 years ago

273) if has("autocmd")
274)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
275)   " Don't let smartindent unindent the # character in Python files
276)   autocmd FileType python  inoremap # X<c-h>#
dblume expand tabs for Python

dblume authored 1 year ago

277)   autocmd FileType python,c,cpp,php,brs,sh  set expandtab  " Use spaces instead of tabs
David Blume first commit

David Blume authored 8 years ago

278)   autocmd Filetype make    setl noexpandtab       " ...not for files that use tabs.
279) 
280)   " Use the vim command %retab before applying the following
281)   " two with files that have 8-space tabs.
David Blume Add .vimrc tab values for ....

David Blume authored 8 years ago

282)   autocmd FileType c,cpp,python,php  set tabstop=4
dblume Remove some lines, allow mo...

dblume authored 2 years ago

283)   autocmd FileType c,cpp,php  set shiftwidth=4
David Blume first commit

David Blume authored 8 years ago

284) 
285)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
286) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

287)   autocmd FileType c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
David Blume first commit

David Blume authored 8 years ago

288)   autocmd FileType c,cpp set foldmethod=syntax
289) 
290)   if v:version >= 703
291)     " I toggle out of relative number when Vim's focus is lost, because
292)     " if I'm not editing, then I may be referring to errors with line numbers.
293)     autocmd FocusLost * if &relativenumber | set number | endif
294)     autocmd FocusGained * if &number | set relativenumber | endif
295)   endif
296) 
dblume Remove some lines, allow mo...

dblume authored 2 years ago

297)   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
298)   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
dblume Add .local/bin to $PATH

dblume authored 1 year ago

299)   autocmd BufRead *.rs :setlocal tags=./rusty-tags.vi;/
David Blume first commit

David Blume authored 8 years ago

300) 
301)   " When editing a file, always jump to the last cursor position
302)   autocmd BufReadPost *
dblume Exempt gitcommit filetype f...

dblume authored 1 year ago

303)   \ if &ft != "p4changelist" && &ft != "gitcommit" && line("'\"") > 0 && line ("'\"") <= line("$") |
David Blume first commit

David Blume authored 8 years ago

304)   \   exe "normal! g'\"" |
305)   \ endif
306) endif
307) 
308) " This requires vim to be compiled with +python
309) " Use auto complete in insert mode with ctrl-x, ctrl-o
310) " See :help new-omni-completion for more.
311) filetype plugin on
312) set omnifunc=syntaxcomplete#Complete
dblume Completion tweaks

dblume authored 2 years ago

313) 
314) " Torn on whether I like the omni completion preview window left open or not.
315) " autocmd CompleteDone * pclose
316) 
317) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
318) inoremap <Nul> <C-x><C-o>
319) 
David Blume Add cscope support

David Blume authored 6 years ago

320) " cscope
321) if has("cscope")
322)     set cscopetag  " Use both cscope and ctag for 'ctrl-]'
David Blume I prefer ctags to be search...

David Blume authored 6 years ago

323)     set csto=1     " 0=cscope first; 1=ctags first
dblume Use QuickFix for cscope.

dblume authored 2 years ago

324)     set cscopequickfix=s-,c-,d-,i-,t-,e-,a- " cscope to quickfix window
325) 
David Blume Use local cscope.out databa...

David Blume authored 3 years ago

326)     set nocsverb
327)     " add any database in current directory
328)     if filereadable("cscope.out")
329)         cs add cscope.out
330)     " else add database pointed to by environment
331)     elseif $CSCOPE_DB != ""
332)         cs add $CSCOPE_DB
333)     endif
334)     set csverb
David Blume Add cscope support

David Blume authored 6 years ago

335) endif
336) 
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

337) " From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
338) " :grep term %
339) " :grep -r term path/
340) " :cw
341) " :ccl (or C-w,q)
dblume QuickFix window: only sort...

dblume authored 2 years ago

342) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
343) 
344) function! MaybeSortQuickfix(fn)
345) "    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
346)     let t = getqflist({'title': 1}).title
dblume QuickFix sorts for 'vimgrep...

dblume authored 2 years ago

347)     " Only sort the files if for search-style commands, not "make".
dblume Follow up integrate ripgrep...

dblume authored 2 years ago

348)     if stridx(t, "cs ") == 0 || stridx(t, ":gr") == 0 || stridx(t, ":vim") == 0 || stridx(t, ":rg") == 0
dblume QuickFix window: only sort...

dblume authored 2 years ago

349)         call setqflist(sort(getqflist(), a:fn), 'r')
350)         call setqflist([], 'r', {'title': t})
351)     endif
352)     cwindow
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

353) endfunction
354) 
355) function! QfStrCmp(e1, e2)
356)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
357)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
358) endfunction
359) 
dblume Integrate ripgrep into vim.

dblume authored 2 years ago

360) " Use ripgrep for search instead of grep
361) if executable('rg')
362)     " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
363)     set grepprg=rg
364) endif
365) " Navigate quickfix list with ease
366) nnoremap <silent> [q :cprevious<CR>
367) nnoremap <silent> ]q :cnext<CR>
368) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

369) " I use Roboto Mono from https://github.com/powerline/fonts
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

370) " On iTerm2, Preferences -> Profiles -> Text -> Font
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

371) " Cygwin64 won't let you choose it. Launch Cygwin64 as follows:
372) " C:\cygwin64\bin\mintty.exe -i /Cygwin-Terminal.ico -o Font="Roboto Mono for Powerline" -
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

373) 
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

374) " Settings that make netrw more like NERDTree
375) let g:netrw_banner = 0
376) let g:netrw_liststyle = 3
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

377) let g:netrw_browse_split = 4
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

378) let g:netrw_altv = 1
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

379) " set g:netrw_winsize to negative for absolute width, positive for relative
380) let g:netrw_winsize = -36
381) " let g:netrw_winsize = 35
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

382) " sort is affecting only: directories on the top, files below
383) let g:netrw_sort_sequence = '[\/]$,*'
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

384) 
dblume Added vim-rooter.

dblume authored 2 years ago

385) " Experimenting with vim-rooter
386) let g:rooter_patterns = ['.git', 'Makefile', 'builds/']
dblume Make vim-rooter manual.

dblume authored 2 years ago

387) let g:rooter_cd_cmd = 'lcd'
388) let g:rooter_manual_only = 1