set ts=4 "autocmd BufNewFile *.py 0r ~/.vim/template/simple.py "autocmd BufNewFile *.sh 0r ~/.vim/template/simple.sh "autocmd BufNewFile *.html 0r ~/.vim/template/simple.html "filetype plugin indent off " 开启/关闭插件 filetype plugin on syntax on " 自动语法高亮 "colorscheme evening " 设定配色方案 "colorscheme molokai " 设定配色方案 set autoindent set autoindent set showmode set fileformat=unix "设置vim编辑器打开文件时强制转换成unix风格 set filetype=conf "调置vim默认打开文件为conf配置文件 set ignorecase smartcase " 搜索时忽略大小写,但在有连续一个大写母以上时仍保持持对大小写敏感 set nocompatible " 设置vim不为兼容vi模式(支持更多的功能) set fileencodings=utf8,gbk,ucs-bom,cp936 "设置vim 支持多字符集 set number " 显示行号 set cursorline " 突出显示当前行 set hlsearch " 搜索时高亮显示被找到的文本 set shiftwidth=4 " 设定shift+< 和 shift+> 命令移动时的宽度为4 set softtabstop=4 " 设置退格键时可以一次删掉4个空格 set tabstop=4 " 设置tab键时跳4个空格间隔 set expandtab " 设置tab用空格代替 set ruler " 打开状态标尺 set nobackup " 设置复盖文件时不备份 set backupcopy=yes " 设置备份时的行为为覆盖 "set autochdir " 自动切换当前目录为当前文件所在的目录 set nowrapscan " 禁止在搜索完全文后再重新搜索 set incsearch " 输入搜索内容时就同步显示搜索结果 set noerrorbells " 关闭错误信息响铃 set novisualbell " 关闭使用可视响铃代替呼叫 set t_vb= " 置空错误铃声的终端代码 set showmatch " 插入括号时,短暂地跳转到匹配的对应括号 set matchtime=1 " 短暂跳转到匹配括号的时间 set magic " 设置魔术 "set hidden " 允许在有未保存的修改时切换缓冲区,此时的修改由 vim 负责保存 "set guioptions-=T " 隐藏工具栏 "set guioptions-=m " 隐藏菜单栏 set smartindent " 开启新行时使用智能自动缩进 set backspace=indent,eol,start " 禁用在插入状态无法用退格键和 Delete 键删除回车符 set cmdheight=1 " 设定命令行的行数为 1 set laststatus=2 " 显示状态栏 (默认值为 1, 无法显示状态栏) set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\ " 设置在状态行显示的信息 "set foldenable " 开始折叠 "set foldmethod=indent " 设置折叠方式为marker(更多的缩进表示更高级别的折叠) "set foldmethod=marker " 设置折叠方式为marker(对文中的标志折叠) "set foldmethod=syntax " 设置语法折叠syntax(用语法高亮来定义折叠) "set foldcolumn=3 " 设置折叠区域的宽度 "setlocal foldlevel=1 " 设置默认打开的折叠层数 "set foldclose=all " 设置为自动关闭折叠 nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR> " 用空格键来开关折叠 set autoread "文件更新时自动重新读取文件 let NERDSpaceDelims=1 " 让注释符与语句之间留一个空格 let NERDCompactSexyComs=1 " 多行注释时样子更好看 set pastetoggle=<F2> " 防止在ctrl+v的时候代码缩进导致格式混乱, 粘贴代码时取消自动缩进 " 让vim每次打开文件时直接跳到上次退出时的光标位置 autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif " Disable 'Press ENTER or type command to continue' silent ! "command! -nargs=1 Silent "\ | execute ':silent !' "\ | execute ':redraw!' " 设置字体以及中文支持 if has("win32") set guifont=Inconsolata:h12:cANSI endif " 配置多语言环境 if has("multi_byte") "UTF-8 编码 set encoding=utf-8 set langmenu=zh_CN.UTF-8 language message zh_CN.UTF-8 set termencoding=utf-8 set formatoptions+=mM set fencs=utf-8,gbk set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1 if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)' set ambiwidth=double endif if has("win32") source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim language messages zh_CN.utf-8 endif else echoerr "sorry, this version of (g)vim was not compiled with +multi_byte" endif "一些不错的映射转换语法(如果在一个文件中混合了不同语言时有用) nnoremap <leader>1 :set filetype=vim<CR> nnoremap <leader>2 :set filetype=conf<CR> nnoremap <leader>3 :set filetype=xhtml<CR> nnoremap <leader>4 :set filetype=css<CR> nnoremap <leader>5 :set filetype=javascript<CR> nnoremap <leader>6 :set filetype=php<CR> nnoremap <leader>7 :set filetype=perl<CR> nnoremap <leader>8 :set filetype=python<CR> nnoremap <leader>9 :set filetype=java<CR> nnoremap <leader>10 :set filetype=xml<CR> nnoremap <leader>11 :set filetype=html<CR> nnoremap <leader>12 :set filetype=htm<CR> nnoremap <leader>13 :set filetype=phtm<CR> " Python 文件的一般设置,比如不要 tab 等 autocmd FileType python set tabstop=4 shiftwidth=4 expandtab autocmd FileType python map <F12> :!python %<CR> let b:javascript_fold=1 " 打开javascript折叠 let javascript_enable_domhtmlcss=1 " 打开javascript对dom、html和css的支持 " 设置字典 ~/.vim/dict/文件的路径 autocmd filetype javascript set dictionary=$VIMFILES/dict/javascript.dict autocmd filetype css set dictionary=$VIMFILES/dict/css.dict autocmd filetype php set dictionary=$VIMFILES/dict/php.dict set fileformats=unix,dos,mac " 设置文件格式为 "nmap <leader>fd :set fileformat=dos<CR> "nmap <leader>fu :set fileformat=unix<CR> """"""""""""""" vim c compiler. "按F5 编译当前文件 map <F5> :call Compile()<CR> func! Compile() if &filetype == 'c' exec "w" exec "! clear; \ echo 正在编译: ./% ...; \ echo ; \ gcc % -g -lm -o %<.o; \ echo ; \ echo 编译完成;" endif endfunc "按Ctrl-F5 调试当前文件 map <C-F5> :call Debug()<CR> func! Debug() if &filetype == 'c' exec "w" exec "! clear; \ echo 正在编译: ./% ...; \ echo ; \ gcc % -g -o %<.o; \ echo ; \ echo 编译完成,开始调试; \ gdb %<.o;" endif endfunc "按F6 执行 map <F6> :call Run()<CR> func! Run() if &filetype == 'c' exec "! clear; \ ./%<.o;" endif endfunc "插入指定文件 "map <F7> :call InsertFile()<CR> "func! InsertFile() "exec "r your_file_path;" "endfunc "进行版权声明的设置 "添加或更新头 map <F1> gg:call read !date<cr> map <F4> :call TitleDet()<cr>'s function AddTitle() call append(0,"/*=============================================================================") call append(1,"#") call append(2,"# Author: Life - xyx818zh@yahoo.com.cn") call append(3,"# Last modified: ".strftime("%Y-%m-%d %H:%M")) call append(4,"# Filename: ".expand("%:t")) call append(5,"# Description: ") call append(6,"=============================================================================*/") echohl WarningMsg | echo "Successful in adding the copyright." | echohl None endf "更新最近修改时间和文件名 function UpdateTitle() normal m' execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M")@' normal '' normal mk execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@' execute "noh" normal 'k echohl WarningMsg | echo "Successful in updating the copy right." | echohl None endfunction "判断前10行代码里面,是否有Last modified这个单词, "如果没有的话,代表没有添加过作者信息,需要新添加; "如果有的话,那么只需要更新即可 function TitleDet() let n=1 "默认为添加 while n < 10 let line = getline(n) if line =~ '^\#\s*\S*Last\smodified:\S*.*$' call UpdateTitle() return endif let n = n + 1 endwhile call AddTitle() endfunction set helplang=cn set paste "不映射上下左右键 "noremap <Up> <Nop> "noremap <Down> <Nop> "noremap <Left> <Nop> "noremap <Right> <Nop> "practicalvim page 61 set wildmenu set wildmode=full "practicalvim page 63 保存1000条记录 set history=1000 cnoremap <C-p> <Up> cnoremap <C-n> <Down>
vim 配置
最新推荐文章于 2024-04-03 17:22:21 发布