e52be429c656659c8a691c5c25b3f0055c3c2431
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',
106)     \ 'R'  : 'REPLACE',
107)     \ 'Rv' : 'V·REPLACE',
108)     \ 'c'  : 'COMMAND',
109)     \}
110) 
111) function! Trim_brackets(fn)
dblume Support older vim on raspi

dblume authored 11 months ago

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

dblume authored 11 months ago

117) endfunction
118) 
119) set statusline=
120) set statusline+=\ %{g:currentmode[mode()]}
121) set statusline+=%{&paste?'\ \ ·\ PASTE':''}
122) "set statusline+=%{StatuslineGit()}
123) set statusline+=\ \|\ %f
124) set statusline+=%m\ 
125) set statusline+=%r\ 
126) set statusline+=%=
127) set statusline+=%h
128) set statusline+=\ %{Trim_brackets(&filetype)}\ 
129) set statusline+=%#StatusLineNC#
130) set statusline+=\ %{&fileencoding?&fileencoding:&encoding}
131) set statusline+=\[%{&fileformat}\]
132) set statusline+=\ \|\ %p%%\ Ξ
133) set statusline+=\ %l/%L\ :\ %c
134) set statusline+=\ 
David Blume first commit

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

169) 
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

170) " git blame, show, diff and log
dblume Add git blame, show commit,...

dblume authored 1 year ago

171) " Delete these functions when you install https://github.com/tpope/vim-fugitive
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

172) 
173) "A helper function that tries to show a buffer if it already exists
174) function! ShowBufInNewTab(bufname)
175)    let l:bnr = bufnr(a:bufname)
176)    if l:bnr > 0
177)        tabnew
178)        exec 'buffer ' . l:bnr
179)        return 1
180)    endif
181)    return 0
182) endfunction
183) 
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

184) "A helper function that tries to show a buffer if it already exists
185) function! ShowBufInNewSplit(bufname)
186)    let l:bnr = bufnr(a:bufname)
187)    if l:bnr > 0
188) "       bo vne
189)        vne
190)        exec 'buffer ' . l:bnr
191)        return 1
192)    endif
193)    return 0
194) endfunction
195) 
dblume Add git blame, show commit,...

dblume authored 1 year ago

196) function! GitBlame()
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

197)     let l:hash = expand('<cword>')
dblume 'Blame' in vim restores you...

dblume authored 1 year ago

198)     let l:currentView = winsaveview()
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

199)     " If in a Blame window already, do blame for some prior commit
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

200)     if l:hash =~ '^[0-9a-f]\{7,40}$' && stridx(expand('%'), ' -- ') != -1
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

201)         let l:fname = split(expand('%'), ' -- ')[-1]
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

202)         let l:bufname = 'git blame ' . l:hash . '^ -- ' . l:fname
203)         if !ShowBufInNewTab(l:bufname)
204)             exec 'tabnew | r! git blame ' . l:hash . '^ -- ' . shellescape(l:fname)
dblume Use fnamescape (for raspber...

dblume authored 1 year ago

205)             exec 'silent :file ' . fnameescape(l:bufname)
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

206)         endif
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

207)     else
208)         let l:fname = expand('%')
dblume Support Blame a ShowFile; b...

dblume authored 10 months ago

209)         let l:hash = ''
210)         " Show fnames will have ':' in them.
211)         if stridx(l:fname, ':') != -1
212)             let l:fname_parts = split(l:fname, ':')
213)             let l:fname = l:fname_parts[-1]
214)             let l:hash = split(l:fname_parts[0], ' ')[-1]
215)         endif
216)         if strlen(l:hash)
217)             let l:bufname = 'git blame ' . l:hash . ' -- ' . l:fname
218)             if !ShowBufInNewTab(l:bufname)
219)                 exec 'tabnew | r! git blame ' . l:hash . ' -- ' . shellescape(l:fname)
220)                 exec 'silent :file ' . fnameescape(l:bufname)
221)             endif
222)         else
223)             let l:bufname = 'git blame -- ' . l:fname
224)             if !ShowBufInNewTab(l:bufname)
225)                 exec 'tabnew | r! git blame -- ' . shellescape(l:fname)
226)                 exec 'silent :file ' . fnameescape(l:bufname)
227)             endif
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

228)         endif
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

229)     endif
230)     0d_
dblume 'Blame' in vim restores you...

dblume authored 1 year ago

231)     call winrestview(l:currentView)
dblume Add git blame, show commit,...

dblume authored 1 year ago

232)     setl buftype=nofile
233) endfunction
234) command Blame :call GitBlame()
235) 
dblume Add vim command ShowFile fo...

dblume authored 1 year ago

236) function! GitShow(commit_or_file)
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

237)     let l:fname = expand('%')
dblume Add git blame, show commit,...

dblume authored 1 year ago

238)     let l:hash = expand('<cword>')
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

239)     if l:hash =~ '^[0-9a-f]\{7,40}$'
240)         if stridx(l:fname, ' -- ') != -1
241)             let l:fname = split(l:fname, ' -- ')[-1]
dblume Whitespace fix

dblume authored 1 year ago

242)         endif
dblume Add vim command ShowFile fo...

dblume authored 1 year ago

243)         if a:commit_or_file != "file"
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

244)             let l:bufname = 'git show ' . l:hash . ' -- ' . l:fname
245)             if !ShowBufInNewTab(l:bufname)
246)                 " Have Show show all the affected files, so don't actually use  "--"
247)                 " exec 'tabnew | r! git show ' . l:hash . ' -- ' . shellescape(l:fname)
248)                 exec 'tabnew | r! git show ' . l:hash
249)                 " We lie here (' -- ') to have a filename the other git commands can use.
dblume Use fnamescape (for raspber...

dblume authored 1 year ago

250)                 exec 'silent :file ' . fnameescape(l:bufname)
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

251)             endif
dblume Support Blame a ShowFile; b...

dblume authored 10 months ago

252)             0d_
dblume Add vim command ShowFile fo...

dblume authored 1 year ago

253)         else
dblume Support Blame a ShowFile; b...

dblume authored 10 months ago

254)             let l:currentView = winsaveview()
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

255)             let l:bufname = 'git show ' . l:hash . ':' . l:fname
256)             if !ShowBufInNewTab(l:bufname)
257)                 exec 'tabnew | r! git show ' . l:hash . ':' . shellescape(l:fname)
dblume Use fnamescape (for raspber...

dblume authored 1 year ago

258)                 exec 'silent :file ' . fnameescape(l:bufname)
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

259)             endif
dblume Support Blame a ShowFile; b...

dblume authored 10 months ago

260)             0d_
261)             call winrestview(l:currentView)
dblume Add vim command ShowFile fo...

dblume authored 1 year ago

262)         endif
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

263)         setl buftype=nofile
264)     else
265)         echo l:hash . ' is not a git hash.'
266)     endif
dblume Add git blame, show commit,...

dblume authored 1 year ago

267) endfunction
dblume Add vim command ShowFile fo...

dblume authored 1 year ago

268) command Show :call GitShow("commit")
269) command ShowFile :call GitShow("file")
dblume Add git blame, show commit,...

dblume authored 1 year ago

270) 
271) function! GitDiff()
dblume Better filename expansion f...

dblume authored 1 year ago

272)     let l:fname = expand('%:.')
dblume Add git blame, show commit,...

dblume authored 1 year ago

273)     let l:buf = winbufnr(0)
dblume Add git log to vim; make gi...

dblume authored 1 year ago

274)     let l:commit = 'HEAD'
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

275)     let l:hash = expand('<cword>')
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

276)     let l:currentView = winsaveview()
dblume Add git log to vim; make gi...

dblume authored 1 year ago

277) 
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

278)     " If the current word is a hash, then diff that vs. previous
279)     if l:hash =~ '^[0-9a-f]\{7,40}$' && stridx(expand('%'), ' -- ') != -1
280)         let l:fname = split(expand('%'), ' -- ')[-1]
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

281)         let l:bufname = 'git show ' . l:hash . '^:' . l:fname
282)         if !ShowBufInNewTab(l:bufname)
283)             exec ':tabnew | silent r! git show ' . l:hash . '^:$(git rev-parse --show-prefix)' . shellescape(l:fname)
284)             setl buftype=nofile
285)             0d_
286)             exec 'silent :file ' . fnameescape(l:bufname)
287) 	endif
dblume Add git log to vim; make gi...

dblume authored 1 year ago

288) 
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

289)         let l:bufname = 'git show ' . l:hash . ':' . l:fname
290)         if !ShowBufInNewSplit(l:bufname)
291)             exec 'vne | silent r! git show ' . l:hash . ':$(git rev-parse --show-prefix)' . shellescape(l:fname)
292)             setl buftype=nofile
293)             exec 'silent :file ' . fnameescape(l:bufname)
294)             0d_
295)         endif
296)     elseif stridx(expand('%'), ':') != -1
297)         " If we're in a 'git show' buffer, then extract fname and hash from there
298)         let l:fname_parts = split(l:fname, ':')
299)         let l:fname = l:fname_parts[-1]
300)         let l:hash = split(l:fname_parts[0], ' ')[-1]
301) 	" TODO: Below few lines are identical to above, so remove dupes.
302)         let l:bufname = 'git show ' . l:hash . '^:' . l:fname
303)         if !ShowBufInNewTab(l:bufname)
304)             exec ':tabnew | silent r! git show ' . l:hash . '^:$(git rev-parse --show-prefix)' . shellescape(l:fname)
305)             setl buftype=nofile
306)             0d_
307)             exec 'silent :file ' . fnameescape(l:bufname)
308) 	endif
309) 
310)         let l:bufname = 'git show ' . l:hash . ':' . l:fname
311)         if !ShowBufInNewSplit(l:bufname)
312)             exec 'vne | silent r! git show ' . l:hash . ':$(git rev-parse --show-prefix)' . shellescape(l:fname)
313)             setl buftype=nofile
314)             exec 'silent :file ' . fnameescape(l:bufname)
315)             0d_
316)         endif
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

317)     else
318)         " If the buffer is not different then repo, then diff HEAD vs file's previous commit
319)         let l:o = system("git status --porcelain | grep " . l:fname)
320)         if v:shell_error != 0
321)             let l:commit = system('git log -2 --pretty=format:"%h" -- ' . l:fname . ' | tail -n 1')
322)         endif
dblume Whitespace fix

dblume authored 1 year ago

323) 
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

324)         let l:bufname = 'git show ' . l:commit . ':' . l:fname
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

325)         " Bug if l:filename includes ".."
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

326)         if !ShowBufInNewTab(l:bufname)
327)             exec ':tabnew | r! git show ' . l:commit . ':$(git rev-parse --show-prefix)' . l:fname
328)             setl buftype=nofile
329)             0d_
330)             exec 'silent :file ' . fnameescape(l:bufname)
331)         endif
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

332)         exec 'vert sb '.l:buf
333)     endif
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

334)     call winrestview(l:currentView)
dblume Add git blame, show commit,...

dblume authored 1 year ago

335)     windo diffthis
336)     setl buftype=nofile
337)     wincmd r
338)     wincmd l
339) endfunction
340) command Diff :call GitDiff()
dblume Add git Blame to vim; add g...

dblume authored 1 year ago

341) 
dblume Default log commands only s...

dblume authored 1 year ago

342) function! GitLog(flags)
dblume Harmonize Git in vim; If <c...

dblume authored 1 year ago

343)     let l:fname = expand('%')
dblume Log command should check fo...

dblume authored 1 year ago

344)     if stridx(l:fname, ' -- ') != -1
345)         let l:fname = split(l:fname, ' -- ')[-1]
dblume vim Diff to work with ShowF...

dblume authored 10 months ago

346)     elseif stridx(l:fname, ':') != -1
347)         let l:fname = split(l:fname, ':')[-1]
dblume Log command should check fo...

dblume authored 1 year ago

348)     endif
dblume Default log commands only s...

dblume authored 1 year ago

349)     let l:bufname = 'git log ' . a:flags . '-- ' . l:fname
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

350)     if !ShowBufInNewTab(l:bufname)
dblume Default log commands only s...

dblume authored 1 year ago

351)         exec 'tabnew | r! git log --no-color --graph --date=short ' . a:flags . '--pretty="format:\%h \%ad \%s \%an \%d" -- ' . shellescape(l:fname)
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

352)         setl buftype=nofile
353)         0d_
dblume Use fnamescape (for raspber...

dblume authored 1 year ago

354)         exec 'silent :file ' . fnameescape(l:bufname)
dblume Avoid duplicate buffer name...

dblume authored 1 year ago

355)     endif
dblume Add git log to vim; make gi...

dblume authored 1 year ago

356) endfunction
dblume Default log commands only s...

dblume authored 1 year ago

357) command Logall :call GitLog('--all ')
358) command Log :call GitLog('')
dblume Add git log to vim; make gi...

dblume authored 1 year ago

359) 
David Blume first commit

David Blume authored 8 years ago

360) " pastetoggle
361) nmap <leader>p :set invpaste paste?<cr>
362) 
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

373)         return
374)       endif
375)     endfor
376)   endif
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

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

David Blume authored 4 years ago

378) endfunction
379) nmap <leader>e :call ToggleNetrw()<cr>
380) 
dblume No comments after key mappi...

dblume authored 1 year ago

381) " install taglist
382) let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
383) let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
384) let Tlist_Close_On_Select = 1          " Close taglist window on select
385) nmap <leader>l :TlistToggle<cr>
386) 
387) " install vim-bbye
388) nmap <leader>bd :Bdelete<cr>
David Blume first commit

David Blume authored 8 years ago

389) 
390) " Visual mode mappings
391) """
392) 
393) " map sort function to a key
394) vnoremap <leader>s :sort<cr>
395) 
396) "easier moving of code blocks
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

397) vnoremap < <gv
398) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

399) 
400) " If too many file system events are getting triggered.
401) set nobackup       " ~ files
402) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
403) set noswapfile     " .swp files
404) 
405) " Allow tags to open another buffer even if this one is modified
406) set hidden
407) 
408) " Switch between source and header files
409) function! SwitchSourceHeader()
410)   let s:ext  = expand("%:e")
411)   let s:base = expand("%:t:r")
412)   let s:cmd  = "find " . s:base
413)   if (s:ext == "cpp" || s:ext == "c")
414)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
415)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
416)   else
417)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
418)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
419)   endif
420) endfunc
421) 
422) " Demonstrates a way to look in a mirror directory
423) " function! OpenOther()
424) "    if expand("%:e") == "cpp"
425) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
426) "    elseif expand("%:e") == "h"
427) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
428) "    endif
429) " endfunc
430) 
431) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
432) function! DeleteTrailingWS()
433)   exe "normal mz"
434)   %s/\s\+$//ge
435)   exe "normal `z"
436) endfunc
437) 
David Blume Add OpenInOtherWindow to .v...

David Blume authored 8 years ago

438) function! OpenInOtherWindow()
439)   if winnr('$') == 1
440)     exe "wincmd F"
441)   else
442)     let curNum = winnr()
443)     let oldBuf = bufnr( "%" )
444)     if curNum == 1
445)       let othNum = 2
446)     else
447)       let othNum = 1
448)     endif
449)     exe "normal! gF"
450)     let newBuf = bufnr( "%" )
451)     let newLine = line(".")
452)     exe 'hide buf' oldBuf
453)     exe othNum . "wincmd w"
454)     exe 'hide buf' newBuf
455)     exe "normal! " . newLine . "G"
456)   endif
457) endfunc
458) 
459) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
dblume Make OpenInOtherWindow easier.

dblume authored 2 years ago

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

David Blume authored 8 years ago

461) 
David Blume first commit

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

473) 
474)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
475) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

477)   autocmd FileType c,cpp set foldmethod=syntax
478) 
479)   if v:version >= 703
480)     " I toggle out of relative number when Vim's focus is lost, because
481)     " if I'm not editing, then I may be referring to errors with line numbers.
482)     autocmd FocusLost * if &relativenumber | set number | endif
483)     autocmd FocusGained * if &number | set relativenumber | endif
484)   endif
485) 
dblume Remove some lines, allow mo...

dblume authored 2 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

489) 
490)   " When editing a file, always jump to the last cursor position
491)   autocmd BufReadPost *
dblume Exempt gitcommit filetype f...

dblume authored 1 year ago

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

David Blume authored 8 years ago

493)   \   exe "normal! g'\"" |
494)   \ endif
495) endif
496) 
497) " This requires vim to be compiled with +python
498) " Use auto complete in insert mode with ctrl-x, ctrl-o
499) " See :help new-omni-completion for more.
500) filetype plugin on
501) set omnifunc=syntaxcomplete#Complete
dblume Completion tweaks

dblume authored 2 years ago

502) 
503) " Torn on whether I like the omni completion preview window left open or not.
504) " autocmd CompleteDone * pclose
505) 
506) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
507) inoremap <Nul> <C-x><C-o>
508) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

515)     set nocsverb
516)     " add any database in current directory
517)     if filereadable("cscope.out")
518)         cs add cscope.out
519)     " else add database pointed to by environment
520)     elseif $CSCOPE_DB != ""
521)         cs add $CSCOPE_DB
522)     endif
523)     set csverb
David Blume Add cscope support

David Blume authored 6 years ago

524) endif
525) 
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

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

dblume authored 2 years ago

531) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
532) 
533) function! MaybeSortQuickfix(fn)
534) "    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
535)     let t = getqflist({'title': 1}).title
dblume QuickFix sorts for 'vimgrep...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

538)         call setqflist(sort(getqflist(), a:fn), 'r')
539)         call setqflist([], 'r', {'title': t})
540)     endif
541)     cwindow
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

542) endfunction
543) 
544) function! QfStrCmp(e1, e2)
545)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
546)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
547) endfunction
548) 
dblume Integrate ripgrep into vim.

dblume authored 2 years ago

549) " Use ripgrep for search instead of grep
550) if executable('rg')
551)     " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
552)     set grepprg=rg
553) endif
554) " Navigate quickfix list with ease
555) nnoremap <silent> [q :cprevious<CR>
556) nnoremap <silent> ]q :cnext<CR>
557) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

573) 
dblume Added vim-rooter.

dblume authored 2 years ago

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

dblume authored 2 years ago

576) let g:rooter_cd_cmd = 'lcd'
577) let g:rooter_manual_only = 1