289c1f4907ff8a712fb6b6d4131375f724c04374
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
13) set listchars+=tab:>-,precedes:<,extends:> " indicators of long lines
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
31) " Map jk to ESC in insert mode
32) inoremap jk <esc>
33) 
dblume Add easier window navigation.

dblume authored 2 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

43) 
44) syntax on
45) 
46) set t_Co=256
47) if v:version >= 703
48)   set colorcolumn=80
49) endif
50) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
51)   " Light backgrounds for GUI experiences
52)   set background=light
53)   " colorscheme peaksea                        " install peaksea
54)   colorscheme tolerable                        " install tolerable
55)   if v:version >= 703
56)     highlight ColorColumn ctermbg=255 guibg=#F6F6F6
57)   endif
dblume Better statusline color.

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 4 years ago

60)   if has('win32')
61)     set guifont=DejaVu_Sans_Mono_for_Powerline:h10:cANSI:qDRAFT
62)   endif
David Blume first commit

David Blume authored 8 years ago

63)   set lines=50 columns=100
64) else
65)   " Dark backgrounds for tty experiences
66)   set background=dark
67)   colorscheme desert                           " install desert
68)   if v:version >= 703
David Blume Windows PuTTY shows ctermbg...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

70)   endif
dblume Better statusline color.

dblume authored 2 years ago

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

David Blume authored 8 years ago

74) endif
dblume Better statusline color.

dblume authored 2 years ago

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

David Blume authored 8 years ago

77) 
78) " set mouse=v     " visual mode, not working great for PuTTY
79) 
80) set tags=tags;/
81) 
82) set history=50
83) set ruler
84) if has('statusline')
85)   set laststatus=2
86)   set statusline=%<%f\   " Filename
87)   set statusline+=%w%h%m%r " Options
88)   "set statusline+=%{fugitive#statusline()} " Git
dblume Remove some lines, allow mo...

dblume authored 2 years ago

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

David Blume authored 8 years ago

91) endif
92) 
93) set encoding=utf-8
94) 
95) nmap <leader>w :w!<cr>         " Fast saving
96) " I use relative number for cursor movement.
97) nmap <leader>r :set relativenumber!<cr>
98) nmap <leader>n :set number!<cr>
99) 
100) " Useful mappings for managing tabs
101) "
102) nmap <leader>th <esc>:tabprevious<cr>
103) nmap <leader>tl <esc>:tabnext<cr>
104) nmap <leader>tn :tabnew
105) nmap <leader>to :tabonly<cr>
106) nmap <leader>tc :tabclose<cr>
107) nmap <leader>tm :tabmove
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

117) 
118) " pastetoggle
119) nmap <leader>p :set invpaste paste?<cr>
120) 
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

131)         return
132)       endif
133)     endfor
134)   endif
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

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

David Blume authored 4 years ago

136) endfunction
137) nmap <leader>e :call ToggleNetrw()<cr>
138) 
David Blume Have NERDTree start in curr...

David Blume authored 7 years ago

139) nmap <leader>l :TlistToggle<cr>           " install taglist
140) nmap <leader>bd :Bdelete<cr>              " install vim-bbye
David Blume first commit

David Blume authored 8 years ago

141) 
142) " Visual mode mappings
143) """
144) 
145) " map sort function to a key
146) vnoremap <leader>s :sort<cr>
147) 
148) "easier moving of code blocks
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

149) vnoremap < <gv
150) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

151) 
152) " If too many file system events are getting triggered.
153) set nobackup       " ~ files
154) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
155) set noswapfile     " .swp files
156) 
157) " Allow tags to open another buffer even if this one is modified
158) set hidden
159) 
160) " Switch between source and header files
161) function! SwitchSourceHeader()
162)   let s:ext  = expand("%:e")
163)   let s:base = expand("%:t:r")
164)   let s:cmd  = "find " . s:base
165)   if (s:ext == "cpp" || s:ext == "c")
166)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
167)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
168)   else
169)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
170)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
171)   endif
172) endfunc
173) 
174) " Demonstrates a way to look in a mirror directory
175) " function! OpenOther()
176) "    if expand("%:e") == "cpp"
177) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
178) "    elseif expand("%:e") == "h"
179) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
180) "    endif
181) " endfunc
182) 
183) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
184) function! DeleteTrailingWS()
185)   exe "normal mz"
186)   %s/\s\+$//ge
187)   exe "normal `z"
188) endfunc
189) 
David Blume Add OpenInOtherWindow to .v...

David Blume authored 8 years ago

190) function! OpenInOtherWindow()
191)   if winnr('$') == 1
192)     exe "wincmd F"
193)   else
194)     let curNum = winnr()
195)     let oldBuf = bufnr( "%" )
196)     if curNum == 1
197)       let othNum = 2
198)     else
199)       let othNum = 1
200)     endif
201)     exe "normal! gF"
202)     let newBuf = bufnr( "%" )
203)     let newLine = line(".")
204)     exe 'hide buf' oldBuf
205)     exe othNum . "wincmd w"
206)     exe 'hide buf' newBuf
207)     exe "normal! " . newLine . "G"
208)   endif
209) endfunc
210) 
211) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
dblume Make OpenInOtherWindow easier.

dblume authored 2 years ago

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

David Blume authored 8 years ago

213) 
David Blume first commit

David Blume authored 8 years ago

214) if has("autocmd")
215)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
216)   " Don't let smartindent unindent the # character in Python files
217)   autocmd FileType python  inoremap # X<c-h>#
dblume Remove some lines, allow mo...

dblume authored 2 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

225) 
226)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
227)   autocmd FileType python  set foldlevel=99
228) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

230)   autocmd FileType c,cpp set foldmethod=syntax
231) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

232)   " autocmd FileType roku :let g:airline_extensions = []
233)   " autocmd FileType roku :let g:airline_section_warning = airline#section#create([])
234)   autocmd FileType roku :let g:airline#extensions#whitespace#enabled = 0
235) 
David Blume first commit

David Blume authored 8 years ago

236)   if v:version >= 703
237)     " I toggle out of relative number when Vim's focus is lost, because
238)     " if I'm not editing, then I may be referring to errors with line numbers.
239)     autocmd FocusLost * if &relativenumber | set number | endif
240)     autocmd FocusGained * if &number | set relativenumber | endif
241)   endif
242) 
dblume Remove some lines, allow mo...

dblume authored 2 years ago

243)   autocmd BufRead *.txt set wrap linebreak   " "soft" wrap of existing lines
244)   autocmd BufRead README set wrap linebreak  " "soft" wrap of existing lines
David Blume first commit

David Blume authored 8 years ago

245) 
246)   " When editing a file, always jump to the last cursor position
247)   autocmd BufReadPost *
David Blume Exclude p4changelist from t...

David Blume authored 3 years ago

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

David Blume authored 8 years ago

249)   \   exe "normal! g'\"" |
250)   \ endif
251) endif
252) 
253) " This requires vim to be compiled with +python
254) " Use auto complete in insert mode with ctrl-x, ctrl-o
255) " See :help new-omni-completion for more.
256) filetype plugin on
257) set omnifunc=syntaxcomplete#Complete
dblume Completion tweaks

dblume authored 2 years ago

258) 
259) " Torn on whether I like the omni completion preview window left open or not.
260) " autocmd CompleteDone * pclose
261) 
262) " Omni completion via ctrl-space (in addition to ctrl-x ctrl-o)
263) inoremap <Nul> <C-x><C-o>
264) 
265) " Next two map j and k to C-n (next) and C-p (prev).
266) " But it's affected by the 'jk to ESC' mapping above, so commented out.
267) "inoremap <expr> j ((pumvisible())?("\<C-n>"):("j"))
268) "inoremap <expr> k ((pumvisible())?("\<C-p>"):("k"))
David Blume first commit

David Blume authored 8 years ago

269) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

276)     set nocsverb
277)     " add any database in current directory
278)     if filereadable("cscope.out")
279)         cs add cscope.out
280)     " else add database pointed to by environment
281)     elseif $CSCOPE_DB != ""
282)         cs add $CSCOPE_DB
283)     endif
284)     set csverb
David Blume Add cscope support

David Blume authored 6 years ago

285) endif
286) 
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

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

dblume authored 2 years ago

292) autocmd! QuickfixCmdPost * call MaybeSortQuickfix('QfStrCmp')
293) 
294) function! MaybeSortQuickfix(fn)
295) "    exe 'normal! '  " Doesn't work. Wanted to jump back to where we were.
296)     let t = getqflist({'title': 1}).title
dblume QuickFix sorts for 'vimgrep...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

299)         call setqflist(sort(getqflist(), a:fn), 'r')
300)         call setqflist([], 'r', {'title': t})
301)     endif
302)     cwindow
David Blume Sort QuickFix tool by filen...

David Blume authored 3 years ago

303) endfunction
304) 
305) function! QfStrCmp(e1, e2)
306)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
307)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
308) endfunction
309) 
dblume Integrate ripgrep into vim.

dblume authored 2 years ago

310) " Use ripgrep for search instead of grep
311) if executable('rg')
312)     " set grepprg=rg\ --vimgrep\ --hidden\ —glob '!.git'
313)     set grepprg=rg
314) endif
315) " Navigate quickfix list with ease
316) nnoremap <silent> [q :cprevious<CR>
317) nnoremap <silent> ]q :cnext<CR>
318) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

334) 
335) " When using vim-airline
336) let g:airline_powerline_fonts = 1
David Blume Use vim-airline characters...

David Blume authored 4 years ago

337) if !exists('g:airline_symbols')
338)     let g:airline_symbols = {}
339) endif
340) let g:airline_symbols.whitespace = '✖'
341) let g:airline_symbols.linenr = 'Ξ'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

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

dblume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

348) let g:airline_left_sep = '▌'
349) let g:airline_right_sep = '▐'
350) let g:airline_left_alt_sep = '|'
351) let g:airline_right_alt_sep = '|'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

354) let g:airline#extensions#wordcount#enabled = 0