524e4b031b9a1b7e2a2b4183d66b44f1458694bb
dblume Use QuickFix for cscope.

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) 
34) " clear search highlights
35) nnoremap <cr> :noh<cr><cr>
David Blume first commit

David Blume authored 8 years ago

36) 
37) " Commented out because I want tags searches to always be case sensitive.
38) " Override with \c anywhere in your search.
39) "set ignorecase      " If you enter all lowercase, it's case insensitive,
40) "set smartcase       " if you use mixed-case terms, it's case sensitive.
41) 
42) syntax on
43) 
44) " If you think this is hard to read,
45) " change the color of comments in vim, or
46) " use another color scheme like desert or peaksea
47) "
48) set t_Co=256
49) if v:version >= 703
50)   set colorcolumn=80
51) endif
52) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
53)   " Light backgrounds for GUI experiences
54)   set background=light
55)   " colorscheme peaksea                        " install peaksea
56)   colorscheme tolerable                        " install tolerable
57)   if v:version >= 703
58)     highlight ColorColumn ctermbg=255 guibg=#F6F6F6
59)   endif
60)   highlight StatusLine   ctermfg=17 ctermbg=Gray " override scheme (overridden by powerline)
61)   highlight StatusLineNC ctermfg=20 ctermbg=LightGray" override scheme
David Blume Specify a font for gvim on...

David Blume authored 4 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

72)   endif
73)   highlight StatusLine   ctermfg=20 ctermbg=Gray " override scheme (overridden by powerline)
74)   highlight StatusLineNC ctermfg=17 ctermbg=DarkGray" override scheme
75) endif
76) " highlight Comment     term=bold ctermfg=Blue ctermbg=0 guifg=SlateBlue guibg=Black
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
89)   "set statusline+=\ [%{&ff}/%Y]            " filetype
90)   "set statusline+=\ [%{getcwd()}]          " current dir
91)   "set statusline+=\ [A=\%03.3b/H=\%02.2B]  " ASCII / Hexadecimal value of char
92)   set statusline+=%=%-14.(%l,%c%V%)\ %p%%   " Right aligned file nav info
93) endif
94) 
95) set encoding=utf-8
96) 
97) " I don't set comma for mapleader because it's useful for reverse-finding.
98) " let mapleader = ","
99) " let g:mapleader = ","
100) 
101) nmap <leader>w :w!<cr>         " Fast saving
102) " I use relative number for cursor movement.
103) nmap <leader>r :set relativenumber!<cr>
104) nmap <leader>n :set number!<cr>
105) 
106) 
107) " Useful mappings for managing tabs
108) "
109) nmap <leader>th <esc>:tabprevious<cr>
110) nmap <leader>tl <esc>:tabnext<cr>
111) nmap <leader>tn :tabnew
112) nmap <leader>to :tabonly<cr>
113) nmap <leader>tc :tabclose<cr>
114) nmap <leader>tm :tabmove
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

dblume authored 2 years ago

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

David Blume authored 8 years ago

124) 
125) " pastetoggle
126) nmap <leader>p :set invpaste paste?<cr>
127) 
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

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

David Blume authored 3 years ago

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

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

138)         return
139)       endif
140)     endfor
141)   endif
David Blume Use netrw Vexplore to assur...

David Blume authored 3 years ago

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

David Blume authored 4 years ago

143) endfunction
144) nmap <leader>e :call ToggleNetrw()<cr>
145) 
David Blume Have NERDTree start in curr...

David Blume authored 7 years ago

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

David Blume authored 8 years ago

148) 
149) " Visual mode mappings
150) """
151) 
152) " map sort function to a key
153) vnoremap <leader>s :sort<cr>
154) 
155) "easier moving of code blocks
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

156) vnoremap < <gv
157) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

158) 
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

159) " TODO: Delete this MaximizeToggle(), use OpenCurrentAsNewTab() instead.
dblume Maximize vim window and ret...

dblume authored 2 years ago

160) " Make <C-W>o toggle maximizing a window.
161) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
dblume Use <leader>o OpenCurrentAs...

dblume authored 2 years ago

162) "nnoremap <C-W>o :call MaximizeToggle()<CR>
dblume Maximize vim window and ret...

dblume authored 2 years ago

163) function! MaximizeToggle()
164)   if exists("s:maximize_session")
165)     exec "source " . s:maximize_session
166)     call delete(s:maximize_session)
167)     unlet s:maximize_session
168)     let &hidden=s:maximize_hidden_save
169)     unlet s:maximize_hidden_save
170)     " ColorColumn highlight gets changed. Workaround: unset it.
171)     highlight clear ColorColumn
172)   else
173)     let s:maximize_hidden_save = &hidden
174)     let s:maximize_session = tempname()
175)     set hidden
176)     exec "mksession! " . s:maximize_session
177)     only
178)   endif
179) endfunction
180) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

219) function! OpenInOtherWindow()
220)   if winnr('$') == 1
221)     exe "wincmd F"
222)   else
223)     let curNum = winnr()
224)     let oldBuf = bufnr( "%" )
225)     if curNum == 1
226)       let othNum = 2
227)     else
228)       let othNum = 1
229)     endif
230)     exe "normal! gF"
231)     let newBuf = bufnr( "%" )
232)     let newLine = line(".")
233)     exe 'hide buf' oldBuf
234)     exe othNum . "wincmd w"
235)     exe 'hide buf' newBuf
236)     exe "normal! " . newLine . "G"
237)   endif
238) endfunc
239) 
240) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
241) 
David Blume first commit

David Blume authored 8 years ago

242) if has("autocmd")
243)   autocmd! BufWritePost .vimrc source %           " re-source this file when saved.
244)   autocmd BufWrite *.py :call DeleteTrailingWS()  " Delete trailing whitespace
245)   " Don't let smartindent unindent the # character in Python files
246)   autocmd FileType python  inoremap # X<c-h>#
David Blume Add .vimrc tab values for ....

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

252)   autocmd FileType c,cpp,python,php  set tabstop=4
253)   autocmd FileType c,cpp,python,php  set shiftwidth=4
David Blume first commit

David Blume authored 8 years ago

254) 
255)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
256)   autocmd FileType python  set foldlevel=99
257) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

261)   " autocmd FileType roku :let g:airline_extensions = []
262)   " autocmd FileType roku :let g:airline_section_warning = airline#section#create([])
263)   autocmd FileType roku :let g:airline#extensions#whitespace#enabled = 0
264) 
David Blume first commit

David Blume authored 8 years ago

265)   if v:version >= 703
266)     " I toggle out of relative number when Vim's focus is lost, because
267)     " if I'm not editing, then I may be referring to errors with line numbers.
268)     autocmd FocusLost * if &relativenumber | set number | endif
269)     autocmd FocusGained * if &number | set relativenumber | endif
270)   endif
271) 
272)   " Since I have the undo tree saved to disk now (see above), I might prefer to
273)   " automatically save the file when focus is lost.
274)   " autocmd FocusLost * silent! wa
275) 
David Blume Let me explicitly hit Retur...

David Blume authored 5 years ago

276)   " I'm in the habit of hitting Return myself.
277)   " autocmd BufRead *.txt set textwidth=78         " Limit width of text to 78 chars
278) 
David Blume first commit

David Blume authored 8 years ago

279)   autocmd BufRead *.txt set wrap linebreak nolist  " "soft" wrap of existing lines
280)   autocmd BufRead README set wrap linebreak nolist " "soft" wrap of existing lines
281) 
282)   " When editing a file, always jump to the last cursor position
283)   autocmd BufReadPost *
David Blume Exclude p4changelist from t...

David Blume authored 3 years ago

284)   \ if &ft != "p4changelist" && 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
294) " Auto completion via ctrl-space (instead of ctrl-x ctrl-o)
295) " set omnifunc=pythoncomplete#Complete
296) " inoremap <Nul> <C-x><C-o>
297) 
dblume Maximize vim window and ret...

dblume authored 2 years ago

298) " See git history for ExecuteFileIntoScratchBuffer.
299) " Instead use: tmux and entr to run code after saving edits.
David Blume first commit

David Blume authored 8 years ago

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
328)     " Only sort the files if cscope generated the list, not for "make" commands.
329)     if stridx(t, "cs ") == 0
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) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

356) 
357) " When using vim-airline
358) let g:airline_powerline_fonts = 1
David Blume Use vim-airline characters...

David Blume authored 4 years ago

359) if !exists('g:airline_symbols')
360)     let g:airline_symbols = {}
361) endif
362) let g:airline_symbols.whitespace = '✖'
363) let g:airline_symbols.linenr = 'Ξ'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

370) let g:airline_left_sep = '▌'
371) let g:airline_right_sep = '▐'
372) let g:airline_left_alt_sep = '|'
373) let g:airline_right_alt_sep = '|'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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