4756af81c1b2c1d8a9ba873305a6f614ff215c92
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!
dblume Set scrolloff to 0, EC2 def...

dblume authored 8 months ago

15) set scrolloff=0     " EC2 defaults to 5. Set explicitly to be consistent
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

dblume authored 1 year ago

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

David Blume authored 6 years ago

37) 
dblume Add easier window navigation.

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

47) 
dblume tab key navigation of buffers

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 8 months ago

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

David Blume authored 4 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

dblume authored 11 months ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

82) endif
dblume Better statusline color.

dblume authored 2 years ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 10 months ago

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

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 3 years ago

179) " Make netrw's Explore behave a little like NERDTreeToggle
180) " 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

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

274) 
David Blume first commit

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

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

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

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

David Blume authored 3 years ago

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

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

386) 
dblume Added vim-rooter.

dblume authored 2 years ago

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

dblume authored 2 years ago

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