vimrc
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by 2 " the call to :runtime you can find below. If you wish to change any of those 3 " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim 4 " will be overwritten everytime an upgrade of the vim packages is performed. 5 " It is recommended to make changes after sourcing debian.vim since it alters 6 " the value of the 'compatible' option. 7 8 " This line should not be removed as it ensures that various options are 9 " properly set to work with the Vim-related packages available in Debian. 10 runtime! debian.vim 11 " Uncomment the next line to make Vim more Vi-compatible 12 " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous 13 " options, so any other options should be set AFTER setting 'compatible'. 14 "set compatible 15 16 " Vim5 and later versions support syntax highlighting. Uncommenting the next 17 " line enables syntax highlighting by default. 18 if has("syntax") 19 syntax on 20 endif 21 22 " If using a dark background within the editing area and syntax highlighting 23 " turn on this option as well 24 "set background=dark 25 26 " Uncomment the following to have Vim jump to the last position when 27 " reopening a file 28 "if has("autocmd") 29 " au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif 30 "endif 31 32 " Uncomment the following to have Vim load indentation rules and plugins 33 " according to the detected filetype. 34 "if has("autocmd") 35 " filetype plugin indent on 36 "endif 37 38 " The following are commented out as they cause vim to behave a lot 39 " differently from regular Vi. They are highly recommended though. 40 set showcmd " Show (partial) command in status line. 41 set showmatch " Show matching brackets. 42 "set ignorecase " Do case insensitive matching 43 "set smartcase " Do smart case matching 44 "set incsearch " Incremental search 45 set autowrite " Automatically save before commands like :next and :make 46 "set hidden " Hide buffers when they are abandoned 47 set mouse=a " Enable mouse usage (all modes) 48 49 " Source a global configuration file if available 50 if filereadable("/etc/vim/vimrc.local") 51 source /etc/vim/vimrc.local 52 endif 53 54 set nu 55 set tabstop=4 56 set softtabstop=4 57 set shiftwidth=4 58 "set smartindent 59 set cursorline 60 set ruler 61 "set autoindent 62 set showcmd 63 set formatoptions=tcrqn "自动格式化 64 set clipboard+=unnamed 65 set autowrite 66 "set confirm 67 set smarttab 68 set history=1000 69 set autoread 70 "禁止生成临时文件 71 set nobackup 72 set noswapfile 73 74 set foldenable "允许折叠 75 set foldmethod=manual "手动折叠 76 77 " 匹配括号高亮的时间(单位是十分之一秒) 78 set matchtime=1 79 80 set backspace=2 81 " 允许backspace和光标键跨越行边界 82 83 map<F2> :call AddHeader()<CR> 84 "auto BufNewFile *.cpp exec ":call AddHeader()" 85 func AddHeader() 86 if &filetype == 'cpp' 87 call setline(line("."),"#include <stdio.h>") 88 let l=line(".")-1 89 let l=l+1 | call append(l,"#include <queue>") 90 let l=l+1 | call append(l,"#include <cstring>") 91 let l=l+1 | call append(l,"#include <cstdlib>") 92 let l=l+1 | call append(l,"#include <algorithm>") 93 let l=l+1 | call append(l,"#include <vector>") 94 let l=l+1 | call append(l,"#include <map>") 95 let l=l+1 | call append(l,"#include <set>") 96 let l=l+1 | call append(l,"#include <ctime>") 97 let l=l+1 | call append(l,"#include <cmath>") 98 let l=l+1 | call append(l,"#include <cctype>") 99 endif 100 autocmd BufNewFile * normal Gkkk 101 endfunc 102 103 auto BufNewFile *.cpp exec ":call Addline()" 104 map<F3> :call Addline()<CR> 105 func Addline() 106 if &filetype == 'cpp' 107 call setline(line("."),"#include <bits/stdc++.h>") 108 let l=line(".")-1 109 let l=l+1 | call append(l,"using namespace std;") 110 let l=l+1 | call append(l,"typedef long long LL;") 111 let l=l+1 | call append(l,"const int N=1e5+10;") 112 let l=l+1 | call append(l,"const int INF=0x3f3f3f3f;") 113 let l=l+1 | call append(l,"int cas=1,T;") 114 let l=l+1 | call append(l,"int main()") 115 let l=l+1 | call append(l,"{") 116 let l=l+1 | call append(l,"// freopen(\"1.in\",\"w\",stdout);") 117 let l=l+1 | call append(l,"// freopen(\"1.in\",\"r\",stdin);") 118 let l=l+1 | call append(l,"// freopen(\"1.out\",\"w\",stdout);") 119 let l=l+1 | call append(l,"// scanf(\"%d\",&T);") 120 let l=l+1 | call append(l,"// cerr<<\"time=\"<<(double)clock()/CLOCKS_PER_SEC<<endl;") 121 let l=l+1 | call append(l," return 0;") 122 let l=l+1 | call append(l,"}") 123 endif 124 autocmd BufNewFile * normal Gkk 125 endfunc 126 127 128 "编码相关 129 set encoding=utf-8 130 set fileencoding=chinese 131 set fileencodings=ucs-bom,utf-8,chinese 132 set termencoding=utf-8 133 134 " 自动切换目录为当前编辑文件所在目录 135 au BufRead,BufNewFile,BufEnter * cd %:p:h 136 " 如果你想保存到你的文档下也可以在_vimrc中添加: 137 cd G:\cpp 138 139 "键盘命令 140 """""""""""""""""""""""""""""""""""""""""""""""""" 141 nmap <leader>w :w!<cr> 142 nmap <leader>f :find<cr> 143 "映射全选+复制 ctrl+a 144 map <C-A> <Esc>ggVGY 145 "map! <C-A> <Esc>ggVGY 146 map <F12> gg=G 147 "选中状态下 ctrl+c 复制 148 vmap <C-c> "+y 149 map zz 0i//<Esc> 150 map tt 0lli<Backspace><Backspace><Esc> 151 152 "C,C++ 按F5编译运行 153 map <F5> :call CompileRunGcc()<CR> 154 func! CompileRunGcc() 155 :w 156 if &filetype == 'c' 157 :! gcc % -o %< 158 :! %<.exe 159 elseif &filetype == 'cpp' 160 ":! g++ -std=c++11 % -o %< 161 ":! %<.exe 162 :!g++ -std=c++11 % -o G:/exe/%< 163 :! G:/exe/%<.exe 164 elseif &filetype == 'java' 165 :! javac % 166 :! java %< 167 elseif &filetype == 'sh' 168 :! %<.sh 169 elseif &filetype == 'html' 170 :! chrome G:/cpp/% 171 else 172 :!python G:/cpp/% 173 endif 174 endfunc 175 176 " getline('.')获取当前行字符串 line('.')获取当前行行号 177 " col('.')获取当前列号 178 "自动补全 179 "inoremap ( ()<Left> 180 "inoremap ) <c-r>=ClosePair(')')<CR> 181 "inoremap { {}<Left> 182 "inoremap } <c-r>=ClosePair('}')<CR> 183 "inoremap [ []<Left> 184 "inoremap ] <c-r>=ClosePair(']')<CR> 185 "inoremap <CR> <c-r>=Line('}')<CR> 186 "inoremap " <c-r>=Pair('"')<CR> 187 "inoremap ' <c-r>=Pair("\'")<CR> 188 function! Line(char) 189 if getline('.')[col('.')-1] == a:char 190 return "\<CR>\<CR>\<Up>\t" 191 else 192 return "\<CR>" 193 endif 194 endfunction 195 function! Pair(char) 196 if getline('.')[col('.')-1] == a:char 197 return "\<Right>" 198 else 199 let s=a:char.a:char."\<Left>" 200 return s 201 endif 202 endfunction 203 function! ClosePair(char) 204 if getline('.')[col('.') - 1] == a:char 205 return "\<Right>" 206 else 207 return a:char 208 endif 209 endfunction 210 filetype plugin indent on 211 "打开文件类型检测, 加了这句才可以用智能补全 212 set completeopt=longest,menu 213 """"""""""""""""""""""""'"" 214 215 " 显示相关 216 " """"""""""""""""""" 217 set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示 218 winpos -4 -4 " 设定窗口位置 219 set lines=40 columns=170 " 设定窗口大小 220 " "set nu " 显示行号 221 " set go= " 不要图形按钮 222 colorscheme desert " 设置背景主题 223 set guifont=Consolas:h14:cANSI " 设置字体 224 " "syntax on " 语法高亮 225 " autocmd InsertLeave * se nocul " 用浅色高亮当前行 226 "autocmd InsertEnter * se cul " 用浅色高亮当前行 227 " "set ruler " 显示标尺 228 " set showcmd " 输入的命令显示出来,看的清楚些 229 set cmdheight=1 " 命令行(在状态行下)的高度,设置为1 230 "set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) 231 set scrolloff=10 " 光标移动到buffer的顶部和底部时保持3行距离 232 "set novisualbell " 不要闪烁(不明白) 233 " set statusline=%F%m%r%h%w\ [FORMAT=%{ 234 " &ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{ 235 " strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 236 " set laststatus=1 " 启动显示状态行(1),总是显示状态行(2) 237 " set foldenable " 允许折叠 238 " set foldmethod=manual " 手动折叠 239 "set background=dark "背景使用黑色 240 " set nocompat 241 " 242 243 " 解决菜单乱码 244 "----------------------------------- 245 set langmenu=zh_CN 246 let $LANG = 'zh_CN.UTF-8' 247 source $VIMRUNTIME/delmenu.vim 248 source $VIMRUNTIME/menu.vim 249 250 source $VIMRUNTIME/vimrc_example.vim 251 source $VIMRUNTIME/mswin.vim 252 behave mswin 253 "----------------------------------- 254 255 "//////////////////////////////////////////////////////////////////////////////////////// 256 "vim 提示信息乱码解决方法 257 "language messages zh_CN.UTF-8 258 if has("win32") 259 set termencoding=chinese 260 language message zh_CN.UTF-8 261 endif
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 " All system-wide defaults are set in $VIMRUNTIME/debian.vim and sourced by 2 " the call to :runtime you can find below. If you wish to change any of those 3 " settings, you should do it in this file (/etc/vim/vimrc), since debian.vim 4 " will be overwritten everytime an upgrade of the vim packages is performed. 5 " It is recommended to make changes after sourcing debian.vim since it alters 6 " the value of the 'compatible' option. 7 8 " This line should not be removed as it ensures that various options are 9 " properly set to work with the Vim-related packages available in Debian. 10 runtime! debian.vim 11 " Uncomment the next line to make Vim more Vi-compatible 12 " NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous 13 " options, so any other options should be set AFTER setting 'compatible'. 14 "set compatible 15 16 " Vim5 and later versions support syntax highlighting. Uncommenting the next 17 " line enables syntax highlighting by default. 18 if has("syntax") 19 syntax on 20 endif 21 22 " If using a dark background within the editing area and syntax highlighting 23 " turn on this option as well 24 "set background=dark 25 26 " Uncomment the following to have Vim jump to the last position when 27 " reopening a file 28 "if has("autocmd") 29 " au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif 30 "endif 31 32 " Uncomment the following to have Vim load indentation rules and plugins 33 " according to the detected filetype. 34 "if has("autocmd") 35 " filetype plugin indent on 36 "endif 37 38 " The following are commented out as they cause vim to behave a lot 39 " differently from regular Vi. They are highly recommended though. 40 set showcmd " Show (partial) command in status line. 41 set showmatch " Show matching brackets. 42 "set ignorecase " Do case insensitive matching 43 "set smartcase " Do smart case matching 44 "set incsearch " Incremental search 45 set autowrite " Automatically save before commands like :next and :make 46 "set hidden " Hide buffers when they are abandoned 47 "set mouse=a " Enable mouse usage (all modes) 48 49 " Source a global configuration file if available 50 if filereadable("/etc/vim/vimrc.local") 51 source /etc/vim/vimrc.local 52 endif 53 54 set nu 55 set tabstop=4 56 set softtabstop=4 57 set shiftwidth=4 58 "set smartindent 59 set cursorline 60 set ruler 61 "set autoindent 62 set showcmd 63 set formatoptions=tcrqn "自动格式化 64 set clipboard+=unnamed 65 set autowrite 66 "set confirm 67 set smarttab 68 set history=1000 69 set autoread 70 "禁止生成临时文件 71 set nobackup 72 set noswapfile 73 74 set foldenable "允许折叠 75 set foldmethod=manual "手动折叠 76 77 " 匹配括号高亮的时间(单位是十分之一秒) 78 set matchtime=1 79 80 set backspace=2 81 " 允许backspace和光标键跨越行边界 82 83 map<F2> :call AddHeader()<CR> 84 "auto BufNewFile *.cpp exec ":call AddHeader()" 85 func AddHeader() 86 if &filetype == 'cpp' 87 call setline(line("."),"#include <stdio.h>") 88 let l=line(".")-1 89 let l=l+1 | call append(l,"#include <queue>") 90 let l=l+1 | call append(l,"#include <cstring>") 91 let l=l+1 | call append(l,"#include <cstdlib>") 92 let l=l+1 | call append(l,"#include <algorithm>") 93 let l=l+1 | call append(l,"#include <vector>") 94 let l=l+1 | call append(l,"#include <map>") 95 let l=l+1 | call append(l,"#include <set>") 96 let l=l+1 | call append(l,"#include <ctime>") 97 let l=l+1 | call append(l,"#include <cmath>") 98 let l=l+1 | call append(l,"#include <cctype>") 99 endif 100 autocmd BufNewFile * normal Gkkk 101 endfunc 102 103 auto BufNewFile *.cpp exec ":call Addline()" 104 map<F3> :call Addline()<CR> 105 func Addline() 106 if &filetype == 'cpp' 107 call setline(line("."),"#include <bits/stdc++.h>") 108 let l=line(".")-1 109 let l=l+1 | call append(l,"using namespace std;") 110 let l=l+1 | call append(l,"typedef long long LL;") 111 let l=l+1 | call append(l,"const int N=1e5+10;") 112 let l=l+1 | call append(l,"const int INF=0x3f3f3f3f;") 113 let l=l+1 | call append(l,"int cas=1,T;") 114 let l=l+1 | call append(l,"int main()") 115 let l=l+1 | call append(l,"{") 116 let l=l+1 | call append(l,"// freopen(\"1.in\",\"w\",stdout);") 117 let l=l+1 | call append(l,"// freopen(\"1.in\",\"r\",stdin);") 118 let l=l+1 | call append(l,"// freopen(\"1.out\",\"w\",stdout);") 119 let l=l+1 | call append(l,"// scanf(\"%d\",&T);") 120 let l=l+1 | call append(l,"// cerr<<\"time=\"<<(double)clock()/CLOCKS_PER_SEC<<endl;") 121 let l=l+1 | call append(l," return 0;") 122 let l=l+1 | call append(l,"}") 123 endif 124 autocmd BufNewFile * normal Gkk 125 endfunc 126 127 128 "编码相关 129 set encoding=utf-8 130 set fileencoding=chinese 131 set fileencodings=ucs-bom,utf-8,chinese 132 set termencoding=utf-8 133 134 " 自动切换目录为当前编辑文件所在目录 135 au BufRead,BufNewFile,BufEnter * cd %:p:h 136 " 如果你想保存到你的文档下也可以在_vimrc中添加: 137 "cd G:\cpp 138 139 "键盘命令 140 """""""""""""""""""""""""""""""""""""""""""""""""" 141 nmap <leader>w :w!<cr> 142 nmap <leader>f :find<cr> 143 "映射全选+复制 ctrl+a 144 map <C-A> <Esc>ggVGY 145 "map! <C-A> <Esc>ggVGY 146 map <F12> gg=G 147 "选中状态下 ctrl+c 复制 148 vmap <C-c> "+y 149 map P "+p 150 map zz 0i//<esc> 151 map tt 0lli<Backspace><Backspace><Esc> 152 153 "C,C++ 按F5编译运行 154 map <F5> :call CompileRunGcc()<CR> 155 func! CompileRunGcc() 156 :w 157 if &filetype == 'c' 158 :! gcc % -o %< 159 :! ./%< 160 elseif &filetype == 'cpp' 161 :! g++ -std=c++11 % -o %< 162 :! ./%< 163 ":!g++ -std=c++11 % -o G:/exe/%< 164 ":! G:/exe/%<.exe 165 elseif &filetype == 'java' 166 :! javac % 167 :! java %< 168 elseif &filetype == 'sh' 169 :! bash % 170 elseif &filetype == 'html' 171 :! chrome % 172 ":! chrome G:/cpp/% 173 elseif &filetype == 'python' 174 :! python3 % 175 ":!python G:/cpp/% 176 elseif &filetype == 'javascript' 177 :! node % 178 elseif &filetype == 'go' 179 :! go run % 180 endif 181 endfunc 182 183 " getline('.')获取当前行字符串 line('.')获取当前行行号 184 " col('.')获取当前列号 185 "自动补全 186 "inoremap ( ()<Left> 187 "inoremap ) <c-r>=ClosePair(')')<CR> 188 "inoremap { {}<Left> 189 "inoremap } <c-r>=ClosePair('}')<CR> 190 "inoremap [ []<Left> 191 "inoremap ] <c-r>=ClosePair(']')<CR> 192 "inoremap <CR> <c-r>=Line('}')<CR> 193 "inoremap " <c-r>=Pair('"')<CR> 194 "inoremap ' <c-r>=Pair("\'")<CR> 195 function! Line(char) 196 if getline('.')[col('.')-1] == a:char 197 return "\<CR>\<CR>\<Up>\t" 198 else 199 return "\<CR>" 200 endif 201 endfunction 202 function! Pair(char) 203 if getline('.')[col('.')-1] == a:char 204 return "\<Right>" 205 else 206 let s=a:char.a:char."\<Left>" 207 return s 208 endif 209 endfunction 210 function! ClosePair(char) 211 if getline('.')[col('.') - 1] == a:char 212 return "\<Right>" 213 else 214 return a:char 215 endif 216 endfunction 217 filetype plugin indent on 218 "打开文件类型检测, 加了这句才可以用智能补全 219 set completeopt=longest,menu 220 """"""""""""""""""""""""'"" 221 222 " 显示相关 223 " """"""""""""""""""" 224 set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示 225 winpos -4 -4 " 设定窗口位置 226 set lines=40 columns=170 " 设定窗口大小 227 " "set nu " 显示行号 228 " set go= " 不要图形按钮 229 colorscheme desert " 设置背景主题 230 set guifont=Consolas:h14:cANSI " 设置字体 231 " "syntax on " 语法高亮 232 " autocmd InsertLeave * se nocul " 用浅色高亮当前行 233 "autocmd InsertEnter * se cul " 用浅色高亮当前行 234 " "set ruler " 显示标尺 235 " set showcmd " 输入的命令显示出来,看的清楚些 236 set cmdheight=1 " 命令行(在状态行下)的高度,设置为1 237 "set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) 238 set scrolloff=10 " 光标移动到buffer的顶部和底部时保持3行距离 239 "set novisualbell " 不要闪烁(不明白) 240 " set statusline=%F%m%r%h%w\ [FORMAT=%{ 241 " &ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{ 242 " strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 243 " set laststatus=1 " 启动显示状态行(1),总是显示状态行(2) 244 " set foldenable " 允许折叠 245 " set foldmethod=manual " 手动折叠 246 "set background=dark "背景使用黑色 247 " set nocompat 248 " 249 250 " 解决菜单乱码 251 "----------------------------------- 252 set langmenu=zh_CN 253 let $LANG = 'zh_CN.UTF-8' 254 source $VIMRUNTIME/delmenu.vim 255 source $VIMRUNTIME/menu.vim 256 257 "source $VIMRUNTIME/vimrc_example.vim 258 "source $VIMRUNTIME/mswin.vim 259 behave mswin 260 "----------------------------------- 261 262 "//////////////////////////////////////////////////////////////////////////////////////// 263 "vim 提示信息乱码解决方法 264 "language messages zh_CN.UTF-8 265 if has("win32") 266 set termencoding=chinese 267 language message zh_CN.UTF-8 268 endif 269 270 271 "taglist 272 let Tlist_Show_One_File=1 273 let Tlist_Exit_OnlyWindow=1 274 "winmanager 275 let g:winManagerWindowLayout='FileExplorer|TagList' 276 nmap wm :WMToggle<cr>