03597b1150a73d1ba6300765edacda0d1cff1488
dblume Remove vim-airline plugin

dblume authored 11 months ago

1) " Version 2023-11-22.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
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

dblume authored 1 year ago

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

David Blume authored 6 years ago

34) 
dblume Add easier window navigation.

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

44) 
dblume tab key navigation of buffers

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 11 months ago

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

David Blume authored 4 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

dblume authored 11 months ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

79) endif
dblume Better statusline color.

dblume authored 2 years ago

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

dblume authored 11 months ago

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

dblume authored 11 months ago

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

David Blume authored 8 years ago

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

dblume authored 11 months ago

89) set laststatus=2
90) 
91) function! StatuslineGit()
92)   let l:branchname = system("git rev-parse --abbrev-ref HEAD 2>/dev/null | tr -d '\n'")
93)   return strlen(l:branchname) > 0 ? ' | branch:'.l:branchname : ''
94) endfunction
95) 
96) "    \ '' : 'S·BLOCK',
97) let g:currentmode={
98)     \ 'n'  : 'NORMAL',
99)     \ 'v'  : 'VISUAL',
100)     \ 'V'  : 'V·LINE',
101)     \ '' : 'V·BLOCK',
102)     \ 's'  : 'SELECT',
103)     \ 'S'  : 'S·LINE',
104)     \ 'i'  : 'INSERT',
105)     \ 'R'  : 'REPLACE',
106)     \ 'Rv' : 'V·REPLACE',
107)     \ 'c'  : 'COMMAND',
108)     \}
109) 
110) function! Trim_brackets(fn)
dblume Support older vim on raspi

dblume authored 11 months ago

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

dblume authored 11 months ago

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

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

168) 
dblume Repeatedly call Blame to go...

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 11 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

340) 
dblume Default log commands only s...

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 10 months ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

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

dblume authored 1 year ago

358) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

460) 
David Blume first commit

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

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

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

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

David Blume authored 3 years ago

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

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

572) 
dblume Added vim-rooter.

dblume authored 2 years ago

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

dblume authored 2 years ago

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