34f1fe7e00baaf8e34d974af76d02f1ae02c53f0
dblume Make OpenInOtherWindow easier.

dblume authored 2 years ago

1) " Version 2022-03-10.1 - Use Quickfix for cscope, add OpenCurrentAsNewTab
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
9) set nofoldenable    " start unfolded
10) set foldlevel=0
11) set nowrap          " no wrapping text lines on the screen (exceptions below)
12) set sidescroll=5
dblume May use nbsp in PS1; add it...

dblume authored 2 years ago

13) set listchars+=tab:>-,precedes:<,extends:>,nbsp:· " for :set list
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) 
dblume map <leader>c and d to use...

dblume authored 1 year ago

43) " https://levelup.gitconnected.com/7-surprising-vim-tricks-that-will-save-you-hours-b158d23fe9b7
dblume Add git Blame to vim; add g...

dblume authored 1 year ago

44) "nnoremap d "_d
45) "nnoremap D "_D
46) "nnoremap c "_c
47) "nnoremap C "_C
48) "nnoremap x "_x
49) "nnoremap X "_X
50) "nnoremap <leader>d d
51) "nnoremap <leader>D D
52) "nnoremap <leader>c c
53) "nnoremap <leader>C C
54) "nnoremap <leader>x x
55) "nnoremap <leader>X X
dblume map <leader>c and d to use...

dblume authored 1 year ago

56) 
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

57) " clear search highlights
58) nnoremap <cr> :noh<cr><cr>
David Blume first commit

David Blume authored 8 years ago

59) 
60) syntax on
61) 
62) set t_Co=256
63) if v:version >= 703
64)   set colorcolumn=80
65) endif
66) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
67)   " Light backgrounds for GUI experiences
68)   set background=light
69)   " colorscheme peaksea                        " install peaksea
70)   colorscheme tolerable                        " install tolerable
71)   if v:version >= 703
72)     highlight ColorColumn ctermbg=255 guibg=#F6F6F6
73)   endif
dblume Better statusline color.

dblume authored 2 years ago

74)   highlight StatusLine   ctermfg=17 ctermbg=Gray " override scheme
David Blume first commit

David Blume authored 8 years ago

75)   highlight StatusLineNC ctermfg=20 ctermbg=LightGray" override scheme
David Blume Specify a font for gvim on...

David Blume authored 4 years ago

76)   if has('win32')
77)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
78)   endif
David Blume first commit

David Blume authored 8 years ago

79)   set lines=50 columns=100
80) else
81)   " Dark backgrounds for tty experiences
82)   set background=dark
83)   colorscheme desert                           " install desert
84)   if v:version >= 703
David Blume Windows PuTTY shows ctermbg...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

86)   endif
dblume Better statusline color.

dblume authored 2 years ago

87)   highlight StatusLine   ctermfg=24 ctermbg=LightGray  " override scheme
88)   highlight StatusLineNC ctermfg=236 ctermbg=Gray  " override scheme
89)   highlight MatchParen   term=reverse ctermbg=23  " 23 is more subtle than default
David Blume first commit

David Blume authored 8 years ago

90) endif
dblume Better statusline color.

dblume authored 2 years ago

91) 
92) " let g:loaded_airline = 1  " For testing the statusline settings above
David Blume first commit

David Blume authored 8 years ago

93) 
94) " set mouse=v     " visual mode, not working great for PuTTY
95) 
96) set tags=tags;/
97) 
98) set history=50
99) set ruler
100) if has('statusline')
101)   set laststatus=2
102)   set statusline=%<%f\   " Filename
103)   set statusline+=%w%h%m%r " Options
104)   "set statusline+=%{fugitive#statusline()} " Git
dblume Remove some lines, allow mo...

dblume authored 2 years ago

105)   set statusline+=\[%{&ff}/%Y]              " filetype
106)   set statusline+=%=%-12.(%l,%c%V%)\ %p%%   " Right aligned file nav info
David Blume first commit

David Blume authored 8 years ago

107) endif
108) 
109) set encoding=utf-8
110) 
dblume No comments after key mappi...

dblume authored 1 year ago

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

David Blume authored 8 years ago

113) " I use relative number for cursor movement.
114) nmap <leader>r :set relativenumber!<cr>
115) nmap <leader>n :set number!<cr>
116) 
117) " Useful mappings for managing tabs
dblume Remove bad vim mappings for...

dblume authored 2 years ago

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

David Blume authored 8 years ago

120) nmap <leader>tn :tabnew
121) nmap <leader>to :tabonly<cr>
122) nmap <leader>tc :tabclose<cr>
123) nmap <leader>tm :tabmove
dblume Add shortcuts for tab selec...

dblume authored 2 years ago

124) nmap <leader>1 1gt
125) nmap <leader>2 2gt
126) nmap <leader>3 3gt
127) nmap <leader>4 4gt
128) nmap <leader>5 5gt
129) nmap <leader>6 6gt
130) nmap <leader>7 7gt
131) nmap <leader>8 8gt
132) nmap <leader>9 9gt
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

142) 
dblume Add git Blame to vim; add g...

dblume authored 1 year ago

143) " git blame (uses # instead of % for file)
144) " Delete this line when you install https://github.com/tpope/vim-fugitive
145) command Blame tabnew | r! git blame #
146) 
David Blume first commit

David Blume authored 8 years ago

147) " pastetoggle
148) nmap <leader>p :set invpaste paste?<cr>
149) 
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

160)         return
161)       endif
162)     endfor
163)   endif
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

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

David Blume authored 4 years ago

165) endfunction
166) nmap <leader>e :call ToggleNetrw()<cr>
167) 
dblume No comments after key mappi...

dblume authored 1 year ago

168) " install taglist
169) let Tlist_GainFocus_On_ToggleOpen = 1  " Jump to taglist window on open
170) let Tlist_Exit_OnlyWindow = 1          " if you are the last, kill yourself
171) let Tlist_Close_On_Select = 1          " Close taglist window on select
172) nmap <leader>l :TlistToggle<cr>
173) 
174) " install vim-bbye
175) nmap <leader>bd :Bdelete<cr>
David Blume first commit

David Blume authored 8 years ago

176) 
177) " Visual mode mappings
178) """
179) 
180) " map sort function to a key
181) vnoremap <leader>s :sort<cr>
182) 
183) "easier moving of code blocks
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

184) vnoremap < <gv
185) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

186) 
187) " If too many file system events are getting triggered.
188) set nobackup       " ~ files
189) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
190) set noswapfile     " .swp files
191) 
192) " Allow tags to open another buffer even if this one is modified
193) set hidden
194) 
195) " Switch between source and header files
196) function! SwitchSourceHeader()
197)   let s:ext  = expand("%:e")
198)   let s:base = expand("%:t:r")
199)   let s:cmd  = "find " . s:base
200)   if (s:ext == "cpp" || s:ext == "c")
201)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
202)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
203)   else
204)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
205)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
206)   endif
207) endfunc
208) 
209) " Demonstrates a way to look in a mirror directory
210) " function! OpenOther()
211) "    if expand("%:e") == "cpp"
212) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
213) "    elseif expand("%:e") == "h"
214) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
215) "    endif
216) " endfunc
217) 
218) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
219) function! DeleteTrailingWS()
220)   exe "normal mz"
221)   %s/\s\+$//ge
222)   exe "normal `z"
223) endfunc
224) 
David Blume Add OpenInOtherWindow to .v...

David Blume authored 8 years ago

225) function! OpenInOtherWindow()
226)   if winnr('$') == 1
227)     exe "wincmd F"
228)   else
229)     let curNum = winnr()
230)     let oldBuf = bufnr( "%" )
231)     if curNum == 1
232)       let othNum = 2
233)     else
234)       let othNum = 1
235)     endif
236)     exe "normal! gF"
237)     let newBuf = bufnr( "%" )
238)     let newLine = line(".")
239)     exe 'hide buf' oldBuf
240)     exe othNum . "wincmd w"
241)     exe 'hide buf' newBuf
242)     exe "normal! " . newLine . "G"
243)   endif
244) endfunc
245) 
246) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
dblume Make OpenInOtherWindow easier.

dblume authored 2 years ago

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

David Blume authored 8 years ago

248) 
David Blume first commit

David Blume authored 8 years ago

249) if has("autocmd")
250)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
251)   " Don't let smartindent unindent the # character in Python files
252)   autocmd FileType python  inoremap # X<c-h>#
dblume Whitespace.

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

260) 
261)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
262)   autocmd FileType python  set foldlevel=99
263) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

265)   autocmd FileType c,cpp set foldmethod=syntax
266) 
dblume Change filetype from roku t...

dblume authored 1 year ago

267)   " autocmd FileType rokulog :let g:airline_extensions = []
268)   " autocmd FileType rokulog :let g:airline_section_warning = airline#section#create([])
269)   autocmd FileType rokulog :let g:airline#extensions#whitespace#enabled = 0
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

270) 
David Blume first commit

David Blume authored 8 years ago

271)   if v:version >= 703
272)     " I toggle out of relative number when Vim's focus is lost, because
273)     " if I'm not editing, then I may be referring to errors with line numbers.
274)     autocmd FocusLost * if &relativenumber | set number | endif
275)     autocmd FocusGained * if &number | set relativenumber | endif
276)   endif
277) 
dblume Remove some lines, allow mo...

dblume authored 2 years ago

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

dblume authored 1 year ago

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

David Blume authored 8 years ago

281) 
282)   " When editing a file, always jump to the last cursor position
283)   autocmd BufReadPost *
dblume Exempt gitcommit filetype f...

dblume authored 1 year ago

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

David Blume authored 8 years ago

285)   \   exe "normal! g'\"" |
286)   \ endif
287) endif
288) 
289) " This requires vim to be compiled with +python
290) " Use auto complete in insert mode with ctrl-x, ctrl-o
291) " See :help new-omni-completion for more.
292) filetype plugin on
293) set omnifunc=syntaxcomplete#Complete
dblume Completion tweaks

dblume authored 2 years ago

294) 
295) " Torn on whether I like the omni completion preview window left open or not.
296) " autocmd CompleteDone * pclose
297) 
298) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
299) inoremap <Nul> <C-x><C-o>
300) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

307)     set nocsverb
308)     " add any database in current directory
309)     if filereadable("cscope.out")
310)         cs add cscope.out
311)     " else add database pointed to by environment
312)     elseif $CSCOPE_DB != ""
313)         cs add $CSCOPE_DB
314)     endif
315)     set csverb
David Blume Add cscope support

David Blume authored 6 years ago

316) endif
317) 
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

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

dblume authored 2 years ago

323) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
324) 
325) function! MaybeSortQuickfix(fn)
326) "    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
327)     let t = getqflist({'title': 1}).title
dblume QuickFix sorts for 'vimgrep...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

330)         call setqflist(sort(getqflist(), a:fn), 'r')
331)         call setqflist([], 'r', {'title': t})
332)     endif
333)     cwindow
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

334) endfunction
335) 
336) function! QfStrCmp(e1, e2)
337)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
338)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
339) endfunction
340) 
dblume Integrate ripgrep into vim.

dblume authored 2 years ago

341) " Use ripgrep for search instead of grep
342) if executable('rg')
343)     " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
344)     set grepprg=rg
345) endif
346) " Navigate quickfix list with ease
347) nnoremap <silent> [q :cprevious<CR>
348) nnoremap <silent> ]q :cnext<CR>
349) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

365) 
366) " When using vim-airline
367) let g:airline_powerline_fonts = 1
David Blume Use vim-airline characters...

David Blume authored 4 years ago

368) if !exists('g:airline_symbols')
369)     let g:airline_symbols = {}
370) endif
371) let g:airline_symbols.whitespace = '✖'
372) let g:airline_symbols.linenr = 'Ξ'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

373) let g:airline_symbols.maxlinenr = ''
dblume Add better readonly char op...

dblume authored 2 years ago

374) " If using a powerline font, don't override .readonly. Otherwise pick one.
375) "let g:airline_symbols.readonly = '◆'
376) "let g:airline_symbols.readonly = '🔒'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

377) 
378) " If no "...for Powerline" font is available, uncomment these four:
David Blume tmux status line pane refin...

David Blume authored 3 years ago

379) let g:airline_left_sep = '▌'
380) let g:airline_right_sep = '▐'
381) let g:airline_left_alt_sep = '|'
382) let g:airline_right_alt_sep = '|'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

383) 
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

384) let g:airline_theme = 'powerlineish'
David Blume Disable vim-airline wordcount.

David Blume authored 6 years ago

385) let g:airline#extensions#wordcount#enabled = 0
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

386) " let g:airline_exclude_filetypes = []
dblume Added vim-rooter.

dblume authored 2 years ago

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