花了很长时间整理的,感觉用起来很方便,共享一下。
我的vim配置主要有以下优点:
1.按F9可以直接编译并执行C、C++、java代码以及执行shell脚本,按“F8”可进行C、C++代码的调试
2.自动插入文件头 ,新建C、C++源文件时自动插入表头:包括文件名、作者、联系方式、建立时间等,读者可根据需求自行更改
3.映射“Ctrl + A”为全选并复制快捷键,方便复制代码
4.按“F2”可以直接消除代码中的空行
5.“F3”可列出当前目录文件,打开树状文件目录
6. 支持鼠标选择、方向键移动
7. 代码高亮,自动缩进,显示行号,显示状态行
8.按“Ctrl + P”可自动补全
9.[]、{}、()、""、' '等都自动补全
10.其他功能读者可以研究以下文件
vim本来就是很强大,很方便的编辑器,加上这些代码后肯定会如虎添翼,或许读者使用其他编程语言,可以根据自己的需要进行修改,配置文件里面已经加上注释。
读者感兴趣的话直接复制下面的代码到文本文件,然后把文件改名为“ .vimrc” (不要忘记前面的“.”),然后把文件放到用户文件夹的根目录下面即可。重新打开vim即可看到效果。
下面是精简的,没有插件的vim配置文件,保存到自己的.vimrc文件就能使用。
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime" you can find below. If you wish to change any of those settings, you should" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten" everytime an upgrade of the vim packages is performed. It is recommended to" make changes after sourcing debian.vim since it alters the value of the" 'compatible' option." This line should not be removed as it ensures that various options are" properly set to work with the Vim-related packages available in Debian.runtime! debian.vim" Uncomment the next line to make Vim more Vi-compatible" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous" options, so any other options should be set AFTER setting 'compatible'."set compatible" Vim5 and later versions support syntax highlighting. Uncommenting the next" line enables syntax highlighting by default.if has("syntax") syntax onendif" If using a dark background within the editing area and syntax highlighting" turn on this option as well"set background=dark" Uncomment the following to have Vim jump to the last position when" reopening a file"if has("autocmd")" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif"endif" Uncomment the following to have Vim load indentation rules and plugins" according to the detected filetype."if has("autocmd")" filetype plugin indent on"endif" The following are commented out as they cause vim to behave a lot" differently from regular Vi. They are highly recommended though."set showcmd " Show (partial) command in status line."set showmatch " Show matching brackets."set ignorecase " Do case insensitive matching"set smartcase " Do smart case matching"set incsearch " Incremental search"set autowrite " Automatically save before commands like :next and :make"set hidden " Hide buffers when they are abandoned"set mouse=a " Enable mouse usage (all modes)" Source a global configuration file if availableif filereadable("/etc/vim/vimrc.local") source /etc/vim/vimrc.localendif"此处以上为默认设置"此处以下为自己添加设置""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 显示相关 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示 "winpos 5 5 " 设定窗口位置 "set lines=40 columns=155 " 设定窗口大小 "set nu " 显示行号 set go= " 不要图形按钮 "color asmanian2 " 设置背景主题 set guifont=Courier_New:h10:cANSI " 设置字体 "syntax on " 语法高亮 autocmd InsertLeave * se nocul " 用浅色高亮当前行 autocmd InsertEnter * se cul " 用浅色高亮当前行 "set ruler " 显示标尺 set showcmd " 输入的命令显示出来,看的清楚些 "set cmdheight=1 " 命令行(在状态行下)的高度,设置为1 "set whichwrap+=<,>,h,l " 允许backspace和光标键跨越行边界(不建议) "set scrolloff=3 " 光标移动到buffer的顶部和底部时保持3行距离 set novisualbell " 不要闪烁(不明白) set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "状态行显示的内容 set laststatus=1 " 启动显示状态行(1),总是显示状态行(2) set foldenable " 允许折叠 set foldmethod=manual " 手动折叠 "set background=dark "背景使用黑色 set nocompatible "去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限 " 显示中文帮助if version >= 603 set helplang=cn set encoding=utf-8endif" 设置配色方案"colorscheme murphy"字体 "if (has("gui_running")) " set guifont=Bitstream\ Vera\ Sans\ Mono\ 10 "endif set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936set termencoding=utf-8set encoding=utf-8set fileencodings=ucs-bom,utf-8,cp936set fileencoding=utf-8""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""新文件标题"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""新建.c,.h,.sh,.java文件,自动插入文件头 autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()" ""定义函数SetTitle,自动插入文件头 func SetTitle() "如果文件类型为.sh文件 if &filetype == 'sh' call setline(1,"\#########################################################################") call append(line("."), "\# File Name: ".expand("%")) call append(line(".")+1, "\# Author: Chierush") call append(line(".")+2, "\# mail: qinxiaojie1@gmail.com") call append(line(".")+3, "\# Created Time: ".strftime("%c")) call append(line(".")+4, "\#########################################################################") call append(line(".")+5, "\#!/bin/bash") call append(line(".")+6, "") else call setline(1, "/*************************************************************************") call append(line("."), " > File Name: ".expand("%")) call append(line(".")+1, " > Author: Chierush") call append(line(".")+2, " > Mail: qinxiaojie1@gmail.com ") call append(line(".")+3, " > Created Time: ".strftime("%c")) call append(line(".")+4, " ************************************************************************/") call append(line(".")+5, "") endif if &filetype == 'cpp' call append(line(".")+6, "#include") call append(line(".")+7, "#include ") call append(line(".")+8, "#include ") call append(line(".")+9, "#include ") call append(line(".")+10, "#include ") call append(line(".")+11, "#include ") call append(line(".")+12, "#include ") call append(line(".")+13, "#include