60c2c0d4162e6393eace160c63aab496a0498475
David Blume Add mapping to paste onto n...

David Blume authored 6 years ago

1) " Version 2018-08-22.1 - added Control+p for paste onto next line
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 Have NERDTree start in curr...

David Blume authored 7 years ago

121) nmap <leader>e :NERDTreeToggle %:p:h<cr>  " install nerdtree (e for Explore)
122) nmap <leader>l :TlistToggle<cr>           " install taglist
123) nmap <leader>bd :Bdelete<cr>              " install vim-bbye
David Blume first commit

David Blume authored 8 years ago

124) 
125) " Visual mode mappings
126) """
127) 
128) " map sort function to a key
129) vnoremap <leader>s :sort<cr>
130) 
131) "easier moving of code blocks
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

132) vnoremap < <gv
133) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

173) function! OpenInOtherWindow()
174)   if winnr('$') == 1
175)     exe "wincmd F"
176)   else
177)     let curNum = winnr()
178)     let oldBuf = bufnr( "%" )
179)     if curNum == 1
180)       let othNum = 2
181)     else
182)       let othNum = 1
183)     endif
184)     exe "normal! gF"
185)     let newBuf = bufnr( "%" )
186)     let newLine = line(".")
187)     exe 'hide buf' oldBuf
188)     exe othNum . "wincmd w"
189)     exe 'hide buf' newBuf
190)     exe "normal! " . newLine . "G"
191)   endif
192) endfunc
193) 
194) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
195) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

208) 
209)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
210)   autocmd FileType python  set foldlevel=99
211) 
David Blume Disable vim-airline whitesp...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

215)   " autocmd FileType roku :let g:airline_extensions = []
216)   " autocmd FileType roku :let g:airline_section_warning = airline#section#create([])
217)   autocmd FileType roku :let g:airline#extensions#whitespace#enabled = 0
218) 
David Blume first commit

David Blume authored 8 years ago

219)   if v:version >= 703
220)     " I toggle out of relative number when Vim's focus is lost, because
221)     " if I'm not editing, then I may be referring to errors with line numbers.
222)     autocmd FocusLost * if &relativenumber | set number | endif
223)     autocmd FocusGained * if &number | set relativenumber | endif
224)   endif
225) 
226)   " Since I have the undo tree saved to disk now (see above), I might prefer to
227)   " automatically save the file when focus is lost.
228)   " autocmd FocusLost * silent! wa
229) 
230)   autocmd BufRead *.txt set tw=78                  " Limit width of text to 78 chars
231)   autocmd BufRead *.txt set wrap linebreak nolist  " "soft" wrap of existing lines
232)   autocmd BufRead README set wrap linebreak nolist " "soft" wrap of existing lines
233) 
234)   " When editing a file, always jump to the last cursor position
235)   autocmd BufReadPost *
236)   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
237)   \   exe "normal! g'\"" |
238)   \ endif
239) endif
240) 
241) " This requires vim to be compiled with +python
242) " Use auto complete in insert mode with ctrl-x, ctrl-o
243) " See :help new-omni-completion for more.
244) filetype plugin on
245) set omnifunc=syntaxcomplete#Complete
246) " Auto completion via ctrl-space (instead of ctrl-x ctrl-o)
247) " set omnifunc=pythoncomplete#Complete
248) " inoremap <Nul> <C-x><C-o>
249) 
250) " This function attempts to reuse the same scratch
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

252) " the same location in your window layout.
253) function! ExecuteFileIntoScratchBuffer()
254)   write
255)   let f=expand("%:p")
256)   let cur_win = winnr()
257)   if buflisted("_vim_output")
258)     exe bufwinnr("_vim_output") . "wincmd w"
259)     enew
260)   else
261)     vnew
262)     let cur_win = cur_win+1
263)   endif
264)   setlocal buftype=nofile
265)   setlocal bufhidden=delete
266)   setlocal noswapfile
267)   silent file _vim_output
268)   execute '.! "'.f.'"'
269)   exe cur_win . "wincmd w"
270) endfunc
271) nmap <F5> :call ExecuteFileIntoScratchBuffer()<cr>
272) 
273) " Execute a selection of code
274) " Use Visual to select a range and then hit ctrl-h to execute it.
275) if has("python")
276) python << EOL
277) import vim
278) def EvaluateCurrentRange():
279)     eval(compile('\n'.join(vim.current.range),'','exec'),globals())
280) EOL
281) vnoremap <C-h> :py EvaluateCurrentRange()<cr>
282) endif
283) 
David Blume Add cscope support

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

288)     set cscopeverbose
289) endif
290) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

295) 
296) " When using vim-powerline
297) let g:Powerline_symbols = 'fancy'
298) 
299) " When using vim-airline
300) let g:airline_powerline_fonts = 1
301) let g:airline_theme = 'powerlineish'
David Blume Disable vim-airline wordcount.

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

304)