83d6ad77af1acd6344073054aa2fc9a8ce701849
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

112) 
113) " Visual mode mappings
114) """
115) 
116) " map sort function to a key
117) vnoremap <leader>s :sort<cr>
118) 
119) "easier moving of code blocks
120) vnoremap < <gv  " better indentation
121) vnoremap > >gv  " better indentation
122) 
123) " If too many file system events are getting triggered.
124) set nobackup       " ~ files
125) set nowritebackup  " Don't write buff to temp, delete orig, rename temp to orig
126) set noswapfile     " .swp files
127) 
128) " Allow tags to open another buffer even if this one is modified
129) set hidden
130) 
131) " Switch between source and header files
132) function! SwitchSourceHeader()
133)   let s:ext  = expand("%:e")
134)   let s:base = expand("%:t:r")
135)   let s:cmd  = "find " . s:base
136)   if (s:ext == "cpp" || s:ext == "c")
137)     if findfile(s:base . ".h"  ) != "" | exe s:cmd . ".h"   | return | en
138)     if findfile(s:base . ".hpp") != "" | exe s:cmd . ".hpp" | return | en
139)   else
140)     if findfile(s:base . ".cpp") != "" | exe s:cmd . ".cpp" | return | en
141)     if findfile(s:base . ".c"  ) != "" | exe s:cmd . ".c"   | return | en
142)   endif
143) endfunc
144) 
145) " Demonstrates a way to look in a mirror directory
146) " function! OpenOther()
147) "    if expand("%:e") == "cpp"
148) "      exe "split" fnameescape(expand("%:p:r:s?src?include?").".h")
149) "    elseif expand("%:e") == "h"
150) "      exe "split" fnameescape(expand("%:p:r:s?include?src?").".cpp")
151) "    endif
152) " endfunc
153) 
154) " Delete trailing white space on save, useful for Python and CoffeeScript ;)
155) function! DeleteTrailingWS()
156)   exe "normal mz"
157)   %s/\s\+$//ge
158)   exe "normal `z"
159) endfunc
160) 
David Blume Add OpenInOtherWindow to .v...

David Blume authored 8 years ago

161) function! OpenInOtherWindow()
162)   if winnr('$') == 1
163)     exe "wincmd F"
164)   else
165)     let curNum = winnr()
166)     let oldBuf = bufnr( "%" )
167)     if curNum == 1
168)       let othNum = 2
169)     else
170)       let othNum = 1
171)     endif
172)     exe "normal! gF"
173)     let newBuf = bufnr( "%" )
174)     let newLine = line(".")
175)     exe 'hide buf' oldBuf
176)     exe othNum . "wincmd w"
177)     exe 'hide buf' newBuf
178)     exe "normal! " . newLine . "G"
179)   endif
180) endfunc
181) 
182) nmap <silent> <leader>F :call OpenInOtherWindow()<cr>
183) 
David Blume first commit

David Blume authored 8 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

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

David Blume authored 7 years ago

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

David Blume authored 8 years ago

196) 
197)   autocmd FileType python  set foldmethod=indent  " 'za' to fold
198)   autocmd FileType python  set foldlevel=99
199) 
200)   autocmd Filetype c,cpp nmap <buffer> <leader>s :call SwitchSourceHeader()<cr>
201)   autocmd FileType c,cpp set foldmethod=syntax
202) 
203)   if v:version >= 703
204)     " I toggle out of relative number when Vim's focus is lost, because
205)     " if I'm not editing, then I may be referring to errors with line numbers.
206)     autocmd FocusLost * if &relativenumber | set number | endif
207)     autocmd FocusGained * if &number | set relativenumber | endif
208)   endif
209) 
210)   " Since I have the undo tree saved to disk now (see above), I might prefer to
211)   " automatically save the file when focus is lost.
212)   " autocmd FocusLost * silent! wa
213) 
214)   autocmd BufRead *.txt set tw=78                  " Limit width of text to 78 chars
215)   autocmd BufRead *.txt set wrap linebreak nolist  " "soft" wrap of existing lines
216)   autocmd BufRead README set wrap linebreak nolist " "soft" wrap of existing lines
217) 
218)   " When editing a file, always jump to the last cursor position
219)   autocmd BufReadPost *
220)   \ if line("'\"") > 0 && line ("'\"") <= line("$") |
221)   \   exe "normal! g'\"" |
222)   \ endif
223) endif
224) 
225) " This requires vim to be compiled with +python
226) " Use auto complete in insert mode with ctrl-x, ctrl-o
227) " See :help new-omni-completion for more.
228) filetype plugin on
229) set omnifunc=syntaxcomplete#Complete
230) " Auto completion via ctrl-space (instead of ctrl-x ctrl-o)
231) " set omnifunc=pythoncomplete#Complete
232) " inoremap <Nul> <C-x><C-o>
233) 
234) " This function attempts to reuse the same scratch
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

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

David Blume authored 8 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

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

David Blume authored 6 years ago

272)     set cscopeverbose
273) endif
274) 
David Blume Change from vim-powerline t...

David Blume authored 6 years ago

275) " I use 12p Roboto Mono from https://github.com/powerline/fonts
276) " On iTerm2, Preferences -> Profiles -> Text -> Font
277) 
278) " When using vim-powerline
279) let g:Powerline_symbols = 'fancy'
280) 
281) " When using vim-airline
282) let g:airline_powerline_fonts = 1
283) let g:airline_theme = 'powerlineish'
284)