bbfaa02a0c8372cc005bf7c0882546d62680d2cc
David Blume Sort QuickFix tool by filen...

David Blume authored 2 years ago

1) " Version 2021-09-24.1 - Sort Quickfix list by filename
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
115) " Opens a new tab with the current buffer's path
116) nmap <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
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) 
dblume Maximize vim window and ret...

dblume authored 2 years ago

152) " Make <C-W>o toggle maximizing a window.
153) " https://vim.fandom.com/wiki/Maximize_window_and_return_to_previous_split_structure
154) nnoremap <C-W>o :call MaximizeToggle()<CR>
155) function! MaximizeToggle()
156)   if exists("s:maximize_session")
157)     exec "source " . s:maximize_session
158)     call delete(s:maximize_session)
159)     unlet s:maximize_session
160)     let &hidden=s:maximize_hidden_save
161)     unlet s:maximize_hidden_save
162)     " ColorColumn highlight gets changed. Workaround: unset it.
163)     highlight clear ColorColumn
164)   else
165)     let s:maximize_hidden_save = &hidden
166)     let s:maximize_session = tempname()
167)     set hidden
168)     exec "mksession! " . s:maximize_session
169)     only
170)   endif
171) endfunction
172) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

211) function! OpenInOtherWindow()
212)   if winnr('$') == 1
213)     exe "wincmd F"
214)   else
215)     let curNum = winnr()
216)     let oldBuf = bufnr( "%" )
217)     if curNum == 1
218)       let othNum = 2
219)     else
220)       let othNum = 1
221)     endif
222)     exe "normal! gF"
223)     let newBuf = bufnr( "%" )
224)     let newLine = line(".")
225)     exe 'hide buf' oldBuf
226)     exe othNum . "wincmd w"
227)     exe 'hide buf' newBuf
228)     exe "normal! " . newLine . "G"
229)   endif
230) endfunc
231) 
232) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
233) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

246) 
247)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
248)   autocmd FileType python  set foldlevel=99
249) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

253)   " autocmd FileType roku :let g:airline_extensions = []
254)   " autocmd FileType roku :let g:airline_section_warning = airline#section#create([])
255)   autocmd FileType roku :let g:airline#extensions#whitespace#enabled = 0
256) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 5 years ago

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

David Blume authored 8 years ago

271)   autocmd BufRead *.txt set wrap linebreak nolist  " "soft" wrap of existing lines
272)   autocmd BufRead README set wrap linebreak nolist " "soft" wrap of existing lines
273) 
274)   " When editing a file, always jump to the last cursor position
275)   autocmd BufReadPost *
David Blume Exclude p4changelist from t...

David Blume authored 3 years ago

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

David Blume authored 8 years ago

277)   \   exe "normal! g'\"" |
278)   \ endif
279) endif
280) 
281) " This requires vim to be compiled with +python
282) " Use auto complete in insert mode with ctrl-x, ctrl-o
283) " See :help new-omni-completion for more.
284) filetype plugin on
285) set omnifunc=syntaxcomplete#Complete
286) " Auto completion via ctrl-space (instead of ctrl-x ctrl-o)
287) " set omnifunc=pythoncomplete#Complete
288) " inoremap <Nul> <C-x><C-o>
289) 
dblume Maximize vim window and ret...

dblume authored 2 years ago

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

David Blume authored 8 years ago

292) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

296)     set csto=1     " 0=cscope first; 1=ctags first
David Blume Use local cscope.out databa...

David Blume authored 3 years ago

297)     set nocsverb
298)     " add any database in current directory
299)     if filereadable("cscope.out")
300)         cs add cscope.out
301)     " else add database pointed to by environment
302)     elseif $CSCOPE_DB != ""
303)         cs add $CSCOPE_DB
304)     endif
305)     set csverb
David Blume Add cscope support

David Blume authored 6 years ago

306) endif
307) 
David Blume Sort QuickFix tool by filen...

David Blume authored 2 years ago

308) " From https://stackoverflow.com/questions/15393301/how-to-automatically-sort-quickfix-entries-by-line-text-in-vim
309) " :grep term %
310) " :grep -r term path/
311) " :cw
312) " :ccl (or C-w,q)
313) autocmd! QuickfixCmdPost * call SortQuickfix('QfStrCmp')
314) 
315) function! SortQuickfix(fn)
316)     call setqflist(sort(getqflist(), a:fn), 'r')
317) endfunction
318) 
319) function! QfStrCmp(e1, e2)
320)     let [t1, t2] = [bufname(a:e1.bufnr), bufname(a:e2.bufnr)]
321)     return t1 <# t2 ? -1 : t1 ==# t2 ? 0 : 1
322) endfunction
323) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 3 years ago

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

David Blume authored 4 years ago

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

David Blume authored 6 years ago

339) 
340) " When using vim-airline
341) let g:airline_powerline_fonts = 1
David Blume Use vim-airline characters...

David Blume authored 4 years ago

342) if !exists('g:airline_symbols')
343)     let g:airline_symbols = {}
344) endif
345) let g:airline_symbols.whitespace = '✖'
346) let g:airline_symbols.linenr = 'Ξ'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

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

dblume authored 2 years ago

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

David Blume authored 3 years ago

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

David Blume authored 3 years ago

353) let g:airline_left_sep = '▌'
354) let g:airline_right_sep = '▐'
355) let g:airline_left_alt_sep = '|'
356) let g:airline_right_alt_sep = '|'
David Blume Make vim easier to tweak wh...

David Blume authored 3 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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