4d1ad0d5e38d2bb051763ec24540cc9ccd6262cb
David Blume vimrc key remappings. jk as...

David Blume authored 6 years ago

1) " Version 2018-05-12.1 - jk and remove comments on same line as remaps
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) " inoremap kj <esc>
34) 
35) " clear search highlights
36) nnoremap <cr> :noh<cr><cr>
David Blume first commit

David Blume authored 8 years ago

37) 
38) " Commented out because I want tags searches to always be case sensitive.
39) " Override with \c anywhere in your search.
40) "set ignorecase      " If you enter all lowercase, it's case insensitive,
41) "set smartcase       " if you use mixed-case terms, it's case sensitive.
42) 
43) syntax on
44) 
45) " If you think this is hard to read,
46) " change the color of comments in vim, or
47) " use another color scheme like desert or peaksea
48) "
49) set t_Co=256
50) if v:version >= 703
51)   set colorcolumn=80
52) endif
53) if has('gui_running') " Didn't work: if &term != 'builtin_gui'
54)   " Light backgrounds for GUI experiences
55)   set background=light
56)   " colorscheme peaksea                        " install peaksea
57)   colorscheme tolerable                        " install tolerable
58)   if v:version >= 703
59)     highlight ColorColumn ctermbg=255 guibg=#F6F6F6
60)   endif
61)   highlight StatusLine   ctermfg=17 ctermbg=Gray " override scheme (overridden by powerline)
62)   highlight StatusLineNC ctermfg=20 ctermbg=LightGray" override scheme
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
69)     highlight ColorColumn ctermbg=234 guibg=Black " dark gray (or 17, dark blue)
70)   endif
71)   highlight StatusLine   ctermfg=20 ctermbg=Gray " override scheme (overridden by powerline)
72)   highlight StatusLineNC ctermfg=17 ctermbg=DarkGray" override scheme
73) endif
74) " highlight Comment     term=bold ctermfg=Blue ctermbg=0 guifg=SlateBlue guibg=Black
75) 
76) " set mouse=v     " visual mode, not working great for PuTTY
77) 
78) set tags=tags;/
79) 
80) set history=50
81) set ruler
82) if has('statusline')
83)   set laststatus=2
84)   set statusline=%<%f\   " Filename
85)   set statusline+=%w%h%m%r " Options
86)   "set statusline+=%{fugitive#statusline()} " Git
87)   "set statusline+=\ [%{&ff}/%Y]            " filetype
88)   "set statusline+=\ [%{getcwd()}]          " current dir
89)   "set statusline+=\ [A=\%03.3b/H=\%02.2B]  " ASCII / Hexadecimal value of char
90)   set statusline+=%=%-14.(%l,%c%V%)\ %p%%   " Right aligned file nav info
91) endif
92) 
93) set encoding=utf-8
94) 
95) " I don't set comma for mapleader because it's useful for reverse-finding.
96) " let mapleader = ","
97) " let g:mapleader = ","
98) 
99) nmap <leader>w :w!<cr>         " Fast saving
100) " I use relative number for cursor movement.
101) nmap <leader>r :set relativenumber!<cr>
102) nmap <leader>n :set number!<cr>
103) 
104) 
105) " Useful mappings for managing tabs
106) "
107) nmap <leader>th <esc>:tabprevious<cr>
108) nmap <leader>tl <esc>:tabnext<cr>
109) nmap <leader>tn :tabnew
110) nmap <leader>to :tabonly<cr>
111) nmap <leader>tc :tabclose<cr>
112) nmap <leader>tm :tabmove
113) " Opens a new tab with the current buffer's path
114) nmap <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
115) 
116) " pastetoggle
117) nmap <leader>p :set invpaste paste?<cr>
118) 
David Blume Have NERDTree start in curr...

David Blume authored 7 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

130) vnoremap < <gv
131) vnoremap > >gv
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 8 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

286)     set cscopeverbose
287) endif
288) 
David Blume Add tip for using Roboto Mo...

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

302)