Advertisement
QinghaoHu

My vimrc

Sep 30th, 2023
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 5.31 KB | Software | 0 0
  1. " Vim with all enhancements
  2. source $VIMRUNTIME/vimrc_example.vim
  3.  
  4. " Remap a few keys for Windows behavior
  5. source $VIMRUNTIME/mswin.vim
  6.  
  7. " Use the internal diff if available.
  8. " Otherwise use the special 'diffexpr' for Windows.
  9. if &diffopt !~# 'internal'
  10.   set diffexpr=MyDiff()
  11. endif
  12. function MyDiff()
  13.   let opt = '-a --binary '
  14.   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  15.   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  16.   let arg1 = v:fname_in
  17.   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  18.   let arg1 = substitute(arg1, '!', '\!', 'g')
  19.   let arg2 = v:fname_new
  20.   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  21.   let arg2 = substitute(arg2, '!', '\!', 'g')
  22.   let arg3 = v:fname_out
  23.   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  24.   let arg3 = substitute(arg3, '!', '\!', 'g')
  25.   if $VIMRUNTIME =~ ' '
  26.     if &sh =~ '\<cmd'
  27.       if empty(&shellxquote)
  28.         let l:shxq_sav = ''
  29.         set shellxquote&
  30.       endif
  31.       let cmd = '"' . $VIMRUNTIME . '\diff"'
  32.     else
  33.       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
  34.     endif
  35.   else
  36.     let cmd = $VIMRUNTIME . '\diff'
  37.   endif
  38.   let cmd = substitute(cmd, '!', '\!', 'g')
  39.   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  40.   if exists('l:shxq_sav')
  41.     let &shellxquote=l:shxq_sav
  42.   endif
  43. endfunction
  44.  
  45. set encoding=utf-8  "设置文件的代码形式 utf8
  46. set termencoding=utf-8
  47. set fileencoding=utf-8
  48. set fileencodings=ucs-bom,utf-8,chinese,cp936
  49. set relativenumber
  50.  
  51. :inoremap ( ()<ESC>i
  52. :inoremap ) <c-r>=ClosePair(')')<CR>
  53. :inoremap { {<CR>}<ESC>O
  54. :inoremap } <c-r>=ClosePair('}')<CR>
  55. :inoremap [ []<ESC>i
  56. :inoremap ] <c-r>=ClosePair(']')<CR>
  57. :inoremap " ""<ESC>i
  58. :inoremap ' ''<ESC>i
  59. function! ClosePair(char)
  60.    if getline('.')[col('.') - 1] == a:char
  61.        return "\<Right>"
  62.    else
  63.        return a:char
  64.    endif
  65. endfunction
  66.  
  67. set number
  68. syntax on
  69. set autoindent
  70. set tabstop=4
  71. set softtabstop=4
  72. set shiftwidth=4
  73.  
  74.  
  75. set smartindent
  76.  
  77. map <C-A> ggVGY     "映射全选 ctrl+A
  78.  
  79. vmap <C-C> "+y      "映射复制 ctrl+C
  80.  
  81. map <C-V> "+gP      "映射粘贴ctrl+V
  82.  
  83. set history=1000
  84.  
  85.  
  86. set nobackup
  87. set noswapfile
  88. set noexpandtab
  89. set noundofile
  90.  
  91. "Vim_plug
  92. call plug#begin('~/vimfiles/plugged')
  93. Plug 'scrooloose/nerdtree'
  94. Plug 'tomasiser/vim-code-dark'
  95. Plug 'vim-airline/vim-airline'
  96. Plug 'morhetz/gruvbox'
  97. Plug 'Yggdroot/indentLine'
  98. Plug 'preservim/tagbar'
  99. Plug 'vim-airline/vim-airline-themes'
  100. Plug 'nanotech/jellybeans.vim'
  101. "Plug 'valloric/youcompleteme'
  102. Plug 'neoclide/coc.nvim', {'branch': 'release'}
  103. call plug#end()
  104.  
  105. set laststatus=2  "永远显示状态栏
  106. let g:airline_powerline_fonts = 1  " 支持 powerline 字体
  107. let g:airline#extensions#tabline#enabled = 1
  108.  
  109. colorscheme retrobox
  110. map <F2> :NERDTreeToggle<CR>
  111.  
  112.  
  113. set guifont=Cascadia_Mono:h14
  114.  
  115. func! CompileGcc()
  116.    exec "w"
  117.    let compilecmd="!gcc "
  118.    let compileflag="-o %< "
  119.    if search("mpi\.h") != 0
  120.        let compilecmd = "!mpicc "
  121.    endif
  122.    if search("glut\.h") != 0
  123.        let compileflag .= " -lglut -lGLU -lGL "
  124.    endif
  125.    if search("cv\.h") != 0
  126.        let compileflag .= " -lcv -lhighgui -lcvaux "
  127.    endif
  128.    if search("omp\.h") != 0
  129.        let compileflag .= " -fopenmp "
  130.    endif
  131.    if search("math\.h") != 0
  132.        let compileflag .= " -lm "
  133.    endif
  134.    exec compilecmd." % ".compileflag
  135. endfunc
  136. func! CompileGpp()
  137.    exec "w"
  138.    let compilecmd="!clang++"
  139.    let compileflag="-o %<.exe "
  140.    if search("mpi\.h") != 0
  141.        let compilecmd = "!mpic++ "
  142.    endif
  143.    if search("glut\.h") != 0
  144.        let compileflag .= " -lglut -lGLU -lGL "
  145.    endif
  146.    if search("cv\.h") != 0
  147.        let compileflag .= " -lcv -lhighgui -lcvaux "
  148.    endif
  149.    if search("omp\.h") != 0
  150.        let compileflag .= " -fopenmp "
  151.    endif
  152.    if search("math\.h") != 0
  153.        let compileflag .= " -lm "
  154.    endif
  155.    exec compilecmd." % ".compileflag
  156. endfunc
  157.  
  158. func! RunPython()
  159.        exec "!python %"
  160. endfunc
  161. func! CompileJava()
  162.    exec "!javac %"
  163. endfunc
  164.  
  165.  
  166. func! CompileCode()
  167.        exec "w"
  168.        if &filetype == "cpp"
  169.                exec "call CompileGpp()"
  170.        elseif &filetype == "c"
  171.                exec "call CompileGcc()"
  172.        elseif &filetype == "python"
  173.                exec "call RunPython()"
  174.        elseif &filetype == "java"
  175.                exec "call CompileJava()"
  176.        endif
  177. endfunc
  178.  
  179. func! RunResult()
  180.        exec "w"
  181.        if search("mpi\.h") != 0
  182.            exec "!mpirun -np 4 ./%<"
  183.        elseif &filetype == "cpp"
  184.            exec "! %<"
  185.        elseif &filetype == "c"
  186.            exec "! %<"
  187.        elseif &filetype == "python"
  188.            exec "call RunPython"
  189.        elseif &filetype == "java"
  190.            exec "!java %<"
  191.        endif
  192. endfunc
  193.  
  194. map <F5> :call CompileCode()<CR>
  195. imap <F5> <ESC>:call CompileCode()<CR>
  196. vmap <F5> <ESC>:call CompileCode()<CR>
  197.  
  198. map <F6> :call RunResult()<CR>
  199.  
  200. autocmd BufNewFile *.cpp 0r ~\vimfiles\template\a.cpp
  201.  
  202. nmap <F8> :TagbarToggle<CR>
  203. nmap <F3> :bnext<CR>
  204.  
  205. "coc plugin
  206. set hidden
  207. set updatetime=100
  208. inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm()
  209.                              \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
  210.  
  211. "indentLine plugin
  212.  
  213.  
  214. augroup VIMRC
  215.     au!
  216.     au BufWritePost .vimrc so %
  217. augroup END
  218.  
Tags: vim
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement