86f991bae2f90c6254af1022135fa55aaca5e53f
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

1) " Version 2020-07-08.1 - Use built-in netrw instead of NERDTree
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
62)   set lines=50 columns=100
63) else
64)   " Dark backgrounds for tty experiences
65)   set background=dark
66)   colorscheme desert                           " install desert
67)   if v:version >= 703
David Blume Windows PuTTY shows ctermbg...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

69)   endif
70)   highlight StatusLine   ctermfg=20 ctermbg=Gray " override scheme (overridden by powerline)
71)   highlight StatusLineNC ctermfg=17 ctermbg=DarkGray" override scheme
72) endif
73) " highlight Comment     term=bold ctermfg=Blue ctermbg=0 guifg=SlateBlue guibg=Black
74) 
75) " set mouse=v     " visual mode, not working great for PuTTY
76) 
77) set tags=tags;/
78) 
79) set history=50
80) set ruler
81) if has('statusline')
82)   set laststatus=2
83)   set statusline=%<%f\   " Filename
84)   set statusline+=%w%h%m%r " Options
85)   "set statusline+=%{fugitive#statusline()} " Git
86)   "set statusline+=\ [%{&ff}/%Y]            " filetype
87)   "set statusline+=\ [%{getcwd()}]          " current dir
88)   "set statusline+=\ [A=\%03.3b/H=\%02.2B]  " ASCII / Hexadecimal value of char
89)   set statusline+=%=%-14.(%l,%c%V%)\ %p%%   " Right aligned file nav info
90) endif
91) 
92) set encoding=utf-8
93) 
94) " I don't set comma for mapleader because it's useful for reverse-finding.
95) " let mapleader = ","
96) " let g:mapleader = ","
97) 
98) nmap <leader>w :w!<cr>         " Fast saving
99) " I use relative number for cursor movement.
100) nmap <leader>r :set relativenumber!<cr>
101) nmap <leader>n :set number!<cr>
102) 
103) 
104) " Useful mappings for managing tabs
105) "
106) nmap <leader>th <esc>:tabprevious<cr>
107) nmap <leader>tl <esc>:tabnext<cr>
108) nmap <leader>tn :tabnew
109) nmap <leader>to :tabonly<cr>
110) nmap <leader>tc :tabclose<cr>
111) nmap <leader>tm :tabmove
112) " Opens a new tab with the current buffer's path
113) nmap <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
114) 
115) " pastetoggle
116) nmap <leader>p :set invpaste paste?<cr>
117) 
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

118) " Control+p to paste onto next line
119) nmap <C-p> :pu<cr>
120) 
David Blume Remove NERDTree and use net...

David Blume authored 4 years ago

121) " Make netrw's Lexplore behave like NERDTreeToggle
122) let g:NetrwIsOpen=0
123) function! ToggleNetrw()
124)     if g:NetrwIsOpen
125)         let i = bufnr("$")
126)         while (i >= 1)
127)             if (getbufvar(i, "&filetype") == "netrw")
128)                 silent exe "bwipeout " . i 
129)             endif
130)             let i-=1
131)         endwhile
132)         let g:NetrwIsOpen=0
133)     else
134)         let g:NetrwIsOpen=1
135)         silent Lexplore %:p:h
136)     endif
137) endfunction
138) nmap <leader>e :call ToggleNetrw()<cr>
139) 
David Blume Have NERDTree start in curr...

David Blume authored 7 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

237)   if v:version >= 703
238)     " I toggle out of relative number when Vim's focus is lost, because
239)     " if I'm not editing, then I may be referring to errors with line numbers.
240)     autocmd FocusLost * if &relativenumber | set number | endif
241)     autocmd FocusGained * if &number | set relativenumber | endif
242)   endif
243) 
244)   " Since I have the undo tree saved to disk now (see above), I might prefer to
245)   " automatically save the file when focus is lost.
246)   " autocmd FocusLost * silent! wa
247) 
David Blume Let me explicitly hit Retur...

David Blume authored 5 years ago

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

David Blume authored 8 years ago

251)   autocmd BufRead *.txt set wrap linebreak nolist  " "soft" wrap of existing lines
252)   autocmd BufRead README set wrap linebreak nolist " "soft" wrap of existing lines
253) 
254)   " When editing a file, always jump to the last cursor position
255)   autocmd BufReadPost *
256)   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
257)   \   exe "normal! g'\"" |
258)   \ endif
259) endif
260) 
261) " This requires vim to be compiled with +python
262) " Use auto complete in insert mode with ctrl-x, ctrl-o
263) " See :help new-omni-completion for more.
264) filetype plugin on
265) set omnifunc=syntaxcomplete#Complete
266) " Auto completion via ctrl-space (instead of ctrl-x ctrl-o)
267) " set omnifunc=pythoncomplete#Complete
268) " inoremap <Nul> <C-x><C-o>
269) 
270) " This function attempts to reuse the same scratch
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

271) " buffer over and over, so you always see output in
David Blume first commit

David Blume authored 8 years ago

272) " the same location in your window layout.
273) function! ExecuteFileIntoScratchBuffer()
274)   write
275)   let f=expand("%:p")
276)   let cur_win = winnr()
277)   if buflisted("_vim_output")
278)     exe bufwinnr("_vim_output") . "wincmd w"
279)     enew
280)   else
281)     vnew
282)     let cur_win = cur_win+1
283)   endif
284)   setlocal buftype=nofile
285)   setlocal bufhidden=delete
286)   setlocal noswapfile
287)   silent file _vim_output
288)   execute '.! "'.f.'"'
289)   exe cur_win . "wincmd w"
290) endfunc
291) nmap <F5> :call ExecuteFileIntoScratchBuffer()<cr>
292) 
293) " Execute a selection of code
294) " Use Visual to select a range and then hit ctrl-h to execute it.
295) if has("python")
296) python << EOL
297) import vim
298) def EvaluateCurrentRange():
299)     eval(compile('\n'.join(vim.current.range),'','exec'),globals())
300) EOL
301) vnoremap <C-h> :py EvaluateCurrentRange()<cr>
302) endif
303) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

307)     set csto=1     " 0=cscope first; 1=ctags first
David Blume Add cscope support

David Blume authored 6 years ago

308)     set cscopeverbose
309) endif
310) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 4 years ago

316) " Settings that make netrw more like NERDTree
317) let g:netrw_banner = 0
318) let g:netrw_liststyle = 3
319) let g:netrw_browse_split = 4
320) let g:netrw_altv = 1
321) " let g:netrw_winsize = -28 (for absolute width)
322) let g:netrw_winsize = 35
323) " sort is affecting only: directories on the top, files below
324) let g:netrw_sort_sequence = '[\/]$,*'
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

325) 
326) " When using vim-airline
327) let g:airline_powerline_fonts = 1
328) let g:airline_theme = 'powerlineish'
David Blume Disable vim-airline wordcount.

David Blume authored 6 years ago

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

David Blume authored 6 years ago

330) " let g:airline_exclude_filetypes = []
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

331)