8d6559e922ae59a9163e46cdcc1180e528d5bc7c
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.
dblume Starting trial with vim 'in...

dblume authored 9 months ago

14) set incsearch       " Navigate to matched strings while typing. Toggle: :set is!
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

dblume authored 1 year ago

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

David Blume authored 6 years ago

36) 
dblume Add easier window navigation.

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

46) 
dblume tab key navigation of buffers

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 11 months ago

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

David Blume authored 4 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

dblume authored 11 months ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

81) endif
dblume Better statusline color.

dblume authored 2 years ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

David Blume authored 8 years ago

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

dblume authored 1 year ago

91) set laststatus=2
92) 
93) function! StatuslineGit()
94)   let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
95)   return strlen(l:branchname) > 0 ? ' | branch:'.l:branchname : ''
96) endfunction
97) 
dblume Default to mode() if not in...

dblume authored 10 months ago

98) function! Current_mode()
99)   let l:currentmode={
dblume Update vim statusline to pr...

dblume authored 1 year ago

100)     \ 'n'  : 'NORMAL',
101)     \ 'v'  : 'VISUAL',
102)     \ 'V'  : 'V·LINE',
103)     \ '' : 'V·BLOCK',
104)     \ 's'  : 'SELECT',
105)     \ 'S'  : 'S·LINE',
106)     \ 'i'  : 'INSERT',
dblume Default to mode() if not in...

dblume authored 10 months ago

107)     \ 'r'  : 'I·REPLACE',
dblume Update vim statusline to pr...

dblume authored 1 year ago

108)     \ 'R'  : 'REPLACE',
109)     \ 'Rv' : 'V·REPLACE',
110)     \ 'c'  : 'COMMAND',
111)     \}
dblume Default to mode() if not in...

dblume authored 10 months ago

112)     return get(l:currentmode, mode(), mode())
113) endfunction
dblume Update vim statusline to pr...

dblume authored 1 year ago

114) 
115) function! Trim_brackets(fn)
dblume Support older vim on raspi

dblume authored 1 year ago

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

dblume authored 1 year ago

121) endfunction
122) 
dblume Default to mode() if not in...

dblume authored 10 months ago

123) set statusline=\ %{Current_mode()}
dblume Update vim statusline to pr...

dblume authored 1 year ago

124) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
125) "set statusline+=%{StatuslineGit()}
dblume vimrc use box drawing vertical

dblume authored 10 months ago

126) set statusline+=\ │\ %f
dblume Default to mode() if not in...

dblume authored 10 months ago

127) set statusline+=%m
128) set statusline+=\ %r
129) set statusline+=\ %=
dblume Update vim statusline to pr...

dblume authored 1 year ago

130) set statusline+=%h
dblume Default to mode() if not in...

dblume authored 10 months ago

131) set statusline+=\ %{Trim_brackets(&filetype)}
132) set statusline+=\ %#StatusLineNC#
dblume Update vim statusline to pr...

dblume authored 1 year ago

133) set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
134) set statusline+=\[%{&fileformat}\]
dblume vimrc use box drawing vertical

dblume authored 10 months ago

135) set statusline+=\ │\ %p%%\ =
dblume Default to mode() if not in...

dblume authored 10 months ago

136) set statusline+=\ %l/%L\ :\ %c\ 
David Blume first commit

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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
dblume Remove bad vim mappings for...

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

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()
dblume Restore entire window view...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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/
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

dblume authored 1 year ago

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
197) nmap <leader>l :TlistToggle<cr>
198) 
199) " install vim-bbye
200) nmap <leader>bd :Bdelete<cr>
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

273) 
David Blume first commit

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

305)   \   exe "normal! g'\"" |
306)   \ endif
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
dblume Completion tweaks

dblume authored 2 years ago

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)
319) inoremap <Nul> <C-x><C-o>
320) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

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
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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)
dblume QuickFix window: only sort...

dblume authored 2 years ago

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
dblume QuickFix sorts for 'vimgrep...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

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

David Blume authored 3 years ago

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) 
dblume Integrate ripgrep into vim.

dblume authored 2 years ago

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) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

372) " Cygwin64 won't let you choose it. Launch Cygwin64 as follows:
373) " 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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

385) 
dblume Added vim-rooter.

dblume authored 2 years ago

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

dblume authored 2 years ago

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