Advertisement
QinghaoHu

My mac vimrc

Oct 7th, 2023
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 4.99 KB | None | 0 0
  1.  
  2. set modelines=0     " CVE-2007-2438
  3.  
  4. " Normally we use vim-extensions. If you want true vi-compatibility
  5. " remove change the following statements
  6. set nocompatible    " Use Vim defaults instead of 100% vi compatibility
  7. set backspace=2     " more powerful backspacing
  8.  
  9. " Don't write backup file if vim is being called by "crontab -e"
  10. au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
  11. " Don't write backup file if vim is being called by "chpass"
  12. au BufWrite /private/etc/pw.* set nowritebackup nobackup
  13.  
  14. let skip_defaults_vim=1
  15.  
  16. :inoremap ( ()<ESC>i
  17. :inoremap ) <c-r>=ClosePair(')')<CR>
  18. :inoremap { {<CR>}<ESC>O
  19. :inoremap } <c-r>=ClosePair('}')<CR>
  20. :inoremap [ []<ESC>i
  21. :inoremap ] <c-r>=ClosePair(']')<CR>
  22. :inoremap " ""<ESC>i
  23. :inoremap ' ''<ESC>i
  24. function! ClosePair(char)
  25.    if getline('.')[col('.') - 1] == a:char
  26.        return "\<Right>"
  27.    else
  28.        return a:char
  29.    endif
  30. endfunction
  31.  
  32. set number
  33. syntax on
  34. set autoindent
  35. set tabstop=4
  36. set softtabstop=4
  37. set shiftwidth=4
  38.  
  39. set smartindent
  40.  
  41. map <C-A> ggVGY     "映射全选 ctrl+A
  42.  
  43. vmap <C-C> "+y      "映射复制 ctrl+C
  44.  
  45. map <C-V> "+gP      "映射粘贴ctrl+V
  46.  
  47. set history=1000
  48.  
  49. set nobackup
  50. set noswapfile
  51. set noexpandtab
  52. set noundofile
  53.  
  54. set guifont=Monaco:h12
  55.  
  56. if has("autocmd")
  57.  au VimEnter,InsertLeave * silent execute '!echo -ne "\e[2 q"' | redraw!
  58.  au InsertEnter,InsertChange *
  59.    \ if v:insertmode == 'i' |
  60.    \  silent execute '!echo -ne "\e[6 q"' | redraw! |
  61.    \ elseif v:insertmode == 'r' |
  62.    \  silent execute '!echo -ne "\e[4 q"' | redraw! |
  63.    \ endif
  64.  au VimLeave * silent execute '!echo -ne "\e[ q"' | redraw!
  65. endif
  66.  
  67. set mouse=a
  68.  
  69. func! CompileGcc()
  70.    exec "w"
  71.    let compilecmd="!gcc "
  72.    let compileflag="-o %< "
  73.    if search("mpi\.h") != 0
  74.        let compilecmd = "!mpicc "
  75.    endif
  76.    if search("glut\.h") != 0
  77.        let compileflag .= " -lglut -lGLU -lGL "
  78.    endif
  79.    if search("cv\.h") != 0
  80.        let compileflag .= " -lcv -lhighgui -lcvaux "
  81.    endif
  82.    if search("omp\.h") != 0
  83.        let compileflag .= " -fopenmp "
  84.    endif
  85.    if search("math\.h") != 0
  86.        let compileflag .= " -lm "
  87.    endif
  88.    exec compilecmd." % ".compileflag
  89. endfunc
  90. func! CompileGpp()
  91.    exec "w"
  92.    let compilecmd="!clang++ -O2 -Wall -Wextra"
  93.    let compileflag="-o %<"
  94.    if search("mpi\.h") != 0
  95.        let compilecmd = "!mpic++ "
  96.    endif
  97.    if search("glut\.h") != 0
  98.        let compileflag .= " -lglut -lGLU -lGL "
  99.    endif
  100.    if search("cv\.h") != 0
  101.        let compileflag .= " -lcv -lhighgui -lcvaux "
  102.    endif
  103.    if search("omp\.h") != 0
  104.        let compileflag .= " -fopenmp "
  105.    endif
  106.    if search("math\.h") != 0
  107.        let compileflag .= " -lm "
  108.    endif
  109.    exec compilecmd." % ".compileflag
  110. endfunc
  111.  
  112. func! RunPython()
  113.        exec "!python %"
  114. endfunc
  115. func! CompileJava()
  116.    exec "!javac %"
  117. endfunc
  118.  
  119.  
  120. func! CompileCode()
  121.        exec "w"
  122.        if &filetype == "cpp"
  123.                exec "call CompileGpp()"
  124.        elseif &filetype == "c"
  125.                exec "call CompileGcc()"
  126.        elseif &filetype == "python"
  127.                exec "call RunPython()"
  128.        elseif &filetype == "java"
  129.                exec "call CompileJava()"
  130.        endif
  131. endfunc
  132.  
  133. func! RunResult()
  134.        exec "w"
  135.        if search("mpi\.h") != 0
  136.            exec "!mpirun -np 4 ./%<"
  137.        elseif &filetype == "cpp"
  138.            exec "! ./%<"
  139.        elseif &filetype == "c"
  140.            exec "! ./%<"
  141.        elseif &filetype == "python"
  142.            exec "call RunPython"
  143.        elseif &filetype == "java"
  144.            exec "!java %<"
  145.        endif
  146. endfunc
  147.  
  148. map <F5> :call CompileCode()<CR>
  149. imap <F5> <ESC>:call CompileCode()<CR>
  150. vmap <F5> <ESC>:call CompileCode()<CR>
  151.  
  152. map <F6> :call RunResult()<CR>
  153.  
  154. call plug#begin()
  155. Plug 'preservim/nerdtree'
  156. Plug 'tomasiser/vim-code-dark'
  157. Plug 'vim-airline/vim-airline'
  158. Plug 'majutsushi/tagbar'
  159. Plug 'mhinz/vim-startify'
  160. Plug 'vim-airline/vim-airline-themes'
  161. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  162. Plug 'neoclide/coc-java'
  163. Plug 'yggdroot/indentline'
  164. call plug#end()
  165. set laststatus=2
  166. "let g:airline_powerline_fonts = 1
  167. let g:airline#extensions#tabline#enabled = 1
  168.  
  169. colorscheme retrobox
  170. map <silent> <F2> :NERDTreeToggle<CR>
  171.  
  172. autocmd BufNewFile *.cpp 0r ~/a.cpp
  173.  
  174. nmap <F8> :TagbarToggle<CR>
  175. nmap <F3> :bnext<CR>
  176.  
  177. "indent line plugin
  178. let g:indentLine_setConceal = 0
  179. let g:indentLine_setColors = 1
  180. let g:indentLine_char_list = ['|', '¦', '', '']
  181.  
  182. "COC extensions
  183. set hidden
  184. set updatetime=300
  185. nmap <silent> [g <Plug>(coc-diagnostic-prev)
  186. nmap <silent> ]g <Plug>(coc-diagnostic-next)
  187.  
  188. nmap <silent> gd <Plug>(coc-definition)
  189. nmap <silent> gy <Plug>(coc-type-definition)
  190. nmap <silent> gi <Plug>(coc-implementation)
  191. nmap <silent> gr <Plug>(coc-references)
  192. inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
  193.                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  194.  
  195. augroup VIMRC
  196.     au!
  197.     au BufWritePost .vimrc so %
  198. augroup END
  199.  
  200.  
Tags: vimrc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement