2012-05-30 04:12:10 +08:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" Important:
|
2022-10-16 03:10:05 +08:00
|
|
|
" This requires that you install https://github.com/amix/vimrc !
|
2012-05-30 04:12:10 +08:00
|
|
|
"
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => GUI related
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" Set font according to system
|
|
|
|
if has("mac") || has("macunix")
|
2017-11-24 21:54:40 +08:00
|
|
|
set gfn=IBM\ Plex\ Mono:h14,Hack:h14,Source\ Code\ Pro:h15,Menlo:h15
|
2012-05-30 04:12:10 +08:00
|
|
|
elseif has("win16") || has("win32")
|
2017-11-24 21:54:40 +08:00
|
|
|
set gfn=IBM\ Plex\ Mono:h14,Source\ Code\ Pro:h12,Bitstream\ Vera\ Sans\ Mono:h11
|
2016-01-15 13:43:56 +08:00
|
|
|
elseif has("gui_gtk2")
|
2019-11-16 23:57:25 +08:00
|
|
|
set gfn=IBM\ Plex\ Mono\ 14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11
|
2012-05-30 04:12:10 +08:00
|
|
|
elseif has("linux")
|
2019-11-16 23:57:25 +08:00
|
|
|
set gfn=IBM\ Plex\ Mono\ 14,:Hack\ 14,Source\ Code\ Pro\ 12,Bitstream\ Vera\ Sans\ Mono\ 11
|
2013-07-14 00:07:32 +08:00
|
|
|
elseif has("unix")
|
2013-04-14 02:15:26 +08:00
|
|
|
set gfn=Monospace\ 11
|
2012-05-30 04:12:10 +08:00
|
|
|
endif
|
|
|
|
|
2012-08-25 06:00:53 +08:00
|
|
|
" Disable scrollbars (real hackers don't use scrollbars for navigation!)
|
|
|
|
set guioptions-=r
|
|
|
|
set guioptions-=R
|
|
|
|
set guioptions-=l
|
|
|
|
set guioptions-=L
|
|
|
|
|
2013-12-29 19:31:16 +08:00
|
|
|
" Colorscheme
|
2016-05-14 20:22:32 +08:00
|
|
|
set background=dark
|
2021-08-04 21:51:30 +08:00
|
|
|
colorscheme peaksea
|
2013-12-29 19:31:16 +08:00
|
|
|
|
2012-05-30 04:12:10 +08:00
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Fast editing and reloading of vimrc configs
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2012-05-31 00:54:47 +08:00
|
|
|
map <leader>e :e! ~/.vim_runtime/my_configs.vim<cr>
|
2016-10-25 04:00:55 +08:00
|
|
|
autocmd! bufwritepost ~/.vim_runtime/my_configs.vim source ~/.vim_runtime/my_configs.vim
|
2012-05-30 04:12:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Turn persistent undo on
|
|
|
|
" means that you can undo even when you close a buffer/VIM
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
try
|
2012-05-31 00:54:47 +08:00
|
|
|
set undodir=~/.vim_runtime/temp_dirs/undodir
|
2012-05-30 04:12:10 +08:00
|
|
|
set undofile
|
|
|
|
catch
|
|
|
|
endtry
|
|
|
|
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Command mode related
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" Smart mappings on the command line
|
|
|
|
cno $h e ~/
|
|
|
|
cno $d e ~/Desktop/
|
|
|
|
cno $j e ./
|
|
|
|
cno $c e <C-\>eCurrentFileDir("e")<cr>
|
|
|
|
|
|
|
|
" $q is super useful when browsing on the command line
|
|
|
|
" it deletes everything until the last slash
|
|
|
|
cno $q <C-\>eDeleteTillSlash()<cr>
|
|
|
|
|
|
|
|
" Bash like keys for the command line
|
|
|
|
cnoremap <C-A> <Home>
|
|
|
|
cnoremap <C-E> <End>
|
|
|
|
cnoremap <C-K> <C-U>
|
|
|
|
|
|
|
|
cnoremap <C-P> <Up>
|
|
|
|
cnoremap <C-N> <Down>
|
|
|
|
|
2012-05-31 00:54:47 +08:00
|
|
|
" Map ½ to something useful
|
|
|
|
map ½ $
|
|
|
|
cmap ½ $
|
|
|
|
imap ½ $
|
|
|
|
|
2012-05-30 04:12:10 +08:00
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2012-05-30 05:32:24 +08:00
|
|
|
" => Parenthesis/bracket
|
2012-05-30 04:12:10 +08:00
|
|
|
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
vnoremap $1 <esc>`>a)<esc>`<i(<esc>
|
|
|
|
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
|
|
|
|
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
|
|
|
|
vnoremap $$ <esc>`>a"<esc>`<i"<esc>
|
|
|
|
vnoremap $q <esc>`>a'<esc>`<i'<esc>
|
2020-07-11 11:28:47 +08:00
|
|
|
vnoremap $e <esc>`>a`<esc>`<i`<esc>
|
2012-05-30 04:12:10 +08:00
|
|
|
|
|
|
|
" Map auto complete of (, ", ', [
|
|
|
|
inoremap $1 ()<esc>i
|
|
|
|
inoremap $2 []<esc>i
|
|
|
|
inoremap $3 {}<esc>i
|
|
|
|
inoremap $4 {<esc>o}<esc>O
|
|
|
|
inoremap $q ''<esc>i
|
|
|
|
inoremap $e ""<esc>i
|
|
|
|
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => General abbreviations
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
2019-11-30 19:54:13 +08:00
|
|
|
iab xdate <C-r>=strftime("%d/%m/%y %H:%M:%S")<cr>
|
2012-05-30 04:12:10 +08:00
|
|
|
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Omni complete functions
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
|
|
|
|
|
|
|
|
|
2017-04-01 20:29:02 +08:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Ack searching and cope displaying
|
|
|
|
" requires ack.vim - it's much better than vimgrep/grep
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" Use the the_silver_searcher if possible (much faster than Ack)
|
|
|
|
if executable('ag')
|
|
|
|
let g:ackprg = 'ag --vimgrep --smart-case'
|
|
|
|
endif
|
|
|
|
|
|
|
|
" When you press gv you Ack after the selected text
|
|
|
|
vnoremap <silent> gv :call VisualSelection('gv', '')<CR>
|
|
|
|
|
|
|
|
" Open Ack and put the cursor in the right position
|
|
|
|
map <leader>g :Ack
|
|
|
|
|
|
|
|
" When you press <leader>r you can search and replace the selected text
|
|
|
|
vnoremap <silent> <leader>r :call VisualSelection('replace', '')<CR>
|
|
|
|
|
|
|
|
" Do :help cope if you are unsure what cope is. It's super useful!
|
|
|
|
"
|
|
|
|
" When you search with Ack, display your results in cope by doing:
|
|
|
|
" <leader>cc
|
|
|
|
"
|
|
|
|
" To go to the next search result do:
|
|
|
|
" <leader>n
|
|
|
|
"
|
|
|
|
" To go to the previous search results do:
|
|
|
|
" <leader>p
|
|
|
|
"
|
|
|
|
map <leader>cc :botright cope<cr>
|
|
|
|
map <leader>co ggVGy:tabnew<cr>:set syntax=qf<cr>pgg
|
|
|
|
map <leader>n :cn<cr>
|
|
|
|
map <leader>p :cp<cr>
|
|
|
|
|
2019-08-22 23:34:32 +08:00
|
|
|
" Make sure that enter is never overriden in the quickfix window
|
|
|
|
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
|
2017-04-01 20:29:02 +08:00
|
|
|
|
2012-05-30 04:12:10 +08:00
|
|
|
|
2022-02-06 11:28:02 +08:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Cscope/Vim key mappings
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
if has("cscope")
|
|
|
|
" use both cscope and ctag for 'ctrl-]', ':ta', and 'vim -t'
|
|
|
|
set cscopetag
|
|
|
|
|
|
|
|
" check cscope for definition of a symbol before checking ctags
|
|
|
|
" set to 1 if you want the reverse check order.
|
|
|
|
set csto=0
|
|
|
|
|
|
|
|
" add any cscope database in current directory
|
|
|
|
if filereadable("cscope.out")
|
|
|
|
cs add cscope.out
|
|
|
|
" else add the database pointed to by environment variable
|
|
|
|
elseif $CSCOPE_DB != ""
|
|
|
|
cs add $CSCOPE_DB
|
|
|
|
endif
|
|
|
|
|
|
|
|
" show msg when any other cscope db added
|
|
|
|
set cscopeverbose
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
"
|
|
|
|
" The following maps all invoke one of the following cscope search types:
|
|
|
|
"
|
|
|
|
" 's' symbol: find all references to the token under cursor
|
|
|
|
" 'g' global: find global definition(s) of the token under cursor
|
|
|
|
" 'c' calls: find all calls to the function name under cursor
|
|
|
|
" 't' text: find all instances of the text under cursor
|
|
|
|
" 'e' egrep: egrep search for the word under cursor
|
|
|
|
" 'f' file: open the filename under cursor
|
|
|
|
" 'i' includes: find files that include the filename under cursor
|
|
|
|
" 'd' called: find functions that function under cursor calls
|
|
|
|
"
|
|
|
|
" Using CTRL-\ as the starting keys for these maps, as it's unlikely
|
|
|
|
" that you need its default mapping (CTRL-\'s default use is as part
|
|
|
|
" of CTRL-\ CTRL-N typemap, which basically just does the same thing
|
|
|
|
" as hitting 'escape').
|
|
|
|
"
|
|
|
|
" If you don't like using CTRL-\, you can change some or all of these
|
|
|
|
" maps to use other keys. One likely candidate is 'CTRL-_' (which also
|
|
|
|
" maps to CTRL-/, which is easier to type). By default it is used to
|
|
|
|
" switch between Hebrew and English keyboard mode.
|
|
|
|
"
|
|
|
|
" To do the navigation, hit 'CTRL-\', followed by one of the cscope
|
|
|
|
" search types above (s,g,c,t,e,f,i,d). The result of your cscope
|
|
|
|
" search will be displayed in the current window. You can use CTRL-T
|
|
|
|
" to go back to where you were before the search.
|
|
|
|
"
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
let b:cscope_mapping_start_key = '<C-_>'
|
|
|
|
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'s :cs find s <C-R>=expand("<cword>")<CR><CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'g :cs find g <C-R>=expand("<cword>")<CR><CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'c :cs find c <C-R>=expand("<cword>")<CR><CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'t :cs find t <C-R>=expand("<cword>")<CR><CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'e :cs find e <C-R>=expand("<cword>")<CR><CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'f :cs find f <C-R>=expand("<cfile>")<CR><CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>'
|
|
|
|
exe 'nmap '.b:cscope_mapping_start_key.'d :cs find d <C-R>=expand("<cword>")<CR><CR>'
|
|
|
|
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
"
|
|
|
|
" These key maps use multiple keystrokes (2 or 3 keys). If you find that
|
|
|
|
" vim keeps timing you out before you can complete them, try changing
|
|
|
|
" your timeout settings as explained below.
|
|
|
|
"
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
|
|
|
|
" By default Vim will only wait 1 second for each keystroke in a mapping.
|
|
|
|
" You may find that too short with the above typemaps. If so, you should
|
|
|
|
" either turn off mapping timeouts via 'notimeout'.
|
|
|
|
"
|
|
|
|
"set notimeout
|
|
|
|
|
|
|
|
" Or, you can keep timeouts, by uncommenting the timeoutlen line below,
|
|
|
|
" with your own personal favorite value (in milliseconds):
|
|
|
|
set timeoutlen=4000
|
|
|
|
|
|
|
|
" Either way, since mapping timeout settings by default also set the
|
|
|
|
" timeouts for multicharacter 'keys codes' (like <F1>), you should also
|
|
|
|
" set ttimeout and ttimeoutlen: otherwise, you will experience strange
|
|
|
|
" delays as vim waits for a keystroke after you hit ESC (it will be
|
|
|
|
" waiting to see if the ESC is actually part of a key code like <F1>).
|
|
|
|
set ttimeout
|
|
|
|
|
|
|
|
" Personally a tenth of a second works well for key code timeouts. If you
|
|
|
|
" experience problems and have a slow terminal or network connection,
|
|
|
|
" set it higher. If you don't set ttimeoutlen, the value for timeoutlen
|
|
|
|
" (default: 1000 = 1 second, which is sluggish) is used.
|
|
|
|
set ttimeoutlen=100
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
2012-05-30 04:12:10 +08:00
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
" => Helper functions
|
|
|
|
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
|
|
|
func! DeleteTillSlash()
|
|
|
|
let g:cmd = getcmdline()
|
|
|
|
|
|
|
|
if has("win16") || has("win32")
|
|
|
|
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "")
|
|
|
|
else
|
|
|
|
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "")
|
|
|
|
endif
|
|
|
|
|
|
|
|
if g:cmd == g:cmd_edited
|
|
|
|
if has("win16") || has("win32")
|
|
|
|
let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "")
|
|
|
|
else
|
|
|
|
let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "")
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
return g:cmd_edited
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
func! CurrentFileDir(cmd)
|
2022-10-16 03:17:55 +08:00
|
|
|
return a:cmd . " " . escape(expand("%:p:h"), " ") . "/"
|
2012-05-30 04:12:10 +08:00
|
|
|
endfunc
|
2021-07-05 05:07:53 +08:00
|
|
|
|
|
|
|
"=================================================================================
|
|
|
|
"
|
|
|
|
" Following file contains the commands on how to run the currently open code.
|
|
|
|
" The default mapping is set to F5 like most code editors.
|
|
|
|
" Change it as you feel comfortable with, keeping in mind that it does not
|
|
|
|
" clash with any other keymapping.
|
|
|
|
"
|
|
|
|
" NOTE: Compilers for different systems may differ. For example, in the case
|
|
|
|
" of C and C++, we have assumed it to be gcc and g++ respectively, but it may
|
|
|
|
" not be the same. It is suggested to check first if the compilers are installed
|
|
|
|
" before running the code, or maybe even switch to a different compiler.
|
|
|
|
"
|
|
|
|
" NOTE: Adding support for more programming languages
|
|
|
|
"
|
|
|
|
" Just add another elseif block before the 'endif' statement in the same
|
|
|
|
" way it is done in each case. Take care to add tabbed spaces after each
|
|
|
|
" elseif block (similar to python). For example:
|
|
|
|
"
|
|
|
|
" elseif &filetype == '<your_file_extension>'
|
|
|
|
" exec '!<your_compiler> %'
|
|
|
|
"
|
|
|
|
" NOTE: The '%' sign indicates the name of the currently open file with extension.
|
|
|
|
" The time command displays the time taken for execution. Remove the
|
|
|
|
" time command if you dont want the system to display the time
|
|
|
|
"
|
|
|
|
"=================================================================================
|
|
|
|
|
|
|
|
map <F5> :call CompileRun()<CR>
|
|
|
|
imap <F5> <Esc>:call CompileRun()<CR>
|
|
|
|
vmap <F5> <Esc>:call CompileRun()<CR>
|
|
|
|
|
|
|
|
func! CompileRun()
|
|
|
|
exec "w"
|
|
|
|
if &filetype == 'c'
|
|
|
|
exec "!gcc % -o %<"
|
|
|
|
exec "!time ./%<"
|
|
|
|
elseif &filetype == 'cpp'
|
|
|
|
exec "!g++ % -o %<"
|
|
|
|
exec "!time ./%<"
|
|
|
|
elseif &filetype == 'java'
|
|
|
|
exec "!javac %"
|
|
|
|
exec "!time java %"
|
|
|
|
elseif &filetype == 'sh'
|
|
|
|
exec "!time bash %"
|
|
|
|
elseif &filetype == 'python'
|
|
|
|
exec "!time python3 %"
|
|
|
|
elseif &filetype == 'html'
|
|
|
|
exec "!google-chrome % &"
|
|
|
|
elseif &filetype == 'go'
|
|
|
|
exec "!go build %<"
|
|
|
|
exec "!time go run %"
|
|
|
|
elseif &filetype == 'matlab'
|
|
|
|
exec "!time octave %"
|
|
|
|
endif
|
|
|
|
endfunc
|