VI的配置
来源:互联网 发布:mac应用程序没图标 编辑:程序博客网 时间:2024/06/05 08:23
********************************************
说明书< 一>
*******************************************
一:.vimrc 复制到家目录下 (putty下支持鼠标复制)
二:修改vim配置 /etc/vim/vimrc
set nocompatible 不使用vi默认键盘布局,如果不配置,在编辑模式下按方向键会输入字符。
set mouse = a (支持鼠标)
set showmatch 括号匹配模式
set ruler 显示状态行
set tabstop=4 tab键为4个空格
set shiftwidth=4
set softtabstop=4
syntax on 语法高亮
set nu 显示行号
set cindent C语言格式对齐
set autoindent 自动对齐
set smartindent 智能对齐
********************************************
说明书<二>
*******************************************
"去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限
set nocompatible
"use mouse everywhere
set mouse=a
"显示行号
"set nu
"检测文件的类型
filetype on
"记录历史的行数
set history=1000
"背景使用黑色
set background=dark
"语法高亮度显示
syntax on
"下面两行在进行编写代码时,在格式对起上很有用;
"第一行,vim使用自动对起,也就是把当前行的对起格式应用到下一行;
"第二行,依据上面的对起格式,智能的选择对起方式,对于类似C语言编
"写上很有用
set autoindent
set smartindent
"支持C/C++的缩进
set cin
"方便使用taglist
nmap <F8> : Tlist <CR>
"第一行设置tab键为4个空格,第二行设置当行之间交错时使用4个空格
set tabstop=2
set shiftwidth=2
"设置匹配模式,类似当输入一个左括号时会匹配相应的那个右括号
set showmatch
"去除vim的GUI版本中的toolbar
set guioptions-=T
"当vim进行编辑时,如果命令错误,会发出一个响声,该设置去掉响声
set vb t_vb=
"在编辑过程中,在右下角显示光标位置的状态行
set ruler
"寻找匹配是高亮度显示的
set hls
"<F2>关闭高亮
map <F2> : nohlsearch <CR>
"查询时非常方便,如要查找book单词,当输入到/b时,会自动找到第一
"个b开头的单词,当输入到/bo时,会自动找到第一个bo开头的单词,依
"次类推,进行查找时,使用此设置会快速找到答案,当你找要匹配的单词
"时,别忘记回车
set incsearch
"修改一个文件后,自动进行备份,备份的文件名为原文件名加“~“后缀
set backup
********************************************
说明书<三>
*******************************************
在~下新建文件.vimrc
.vimrc内容如下:
set autoindent
set tabstop=4
set shiftwidth=4
filetype plugin indent on
set sm
set nu
inoremap ( ()<LEFT>
inoremap { {}<LEFT>
inoremap [ []<LEFT>
我简单来解释一下,上面这几个是我觉得编程所常用的配置,那些语法加亮之类的,一般来说,不用配置就直接存在了。
第一行:set aotuindent设置自动缩进,如你写函数按回车,会自动缩进,让代码漂亮清晰,打反括号一类的,会自动缩回
第二行:set tabstop=4 设置<Tab>键在vim中移动量为4,默认一般是8
第三行:set shiftwidth=4 设置自动缩进量为4,这个可以和tab不一样,不过一样最好
第四行:filetype plugin indent on 自动识别vim打开的文件类型,由后缀名决定,如c,cpp,pl,并且启用相关插件和模式,如相关缩进,括号匹配,高亮显示等等,由文件格式自动识别使用
后面,set sm 其中sm是showmatch的简写,vim中有很多简写,打开showmatch,当你输入后括号,如}]),他会自动跳到相匹配的前括号处,闪动2下,不影响你继续输入,时间也可以自己设置
set nu 为显示行号
对于UNIX/linux初学者来说,在用VI来写程序的时候,总是发现不如WINDOWS下面的那些专业的文本编辑器那样高亮关键字, 自动对齐等等...其实我们只要对VI进行一些简单的配置,即可实现很多美妙的功能,通过下面的配置,你就会发现,VI的灵活性几乎超乎于你的想象... 一般来说,我们可以在当前用户的根目录下创建一个.vimrc的隐藏文件(当然,也可以不隐藏,看个人的习惯),方法如下:$ touch ~/.vimrc 符号~(可能很多人知道这个符号什么意思,却不会读,这个符号叫鄂化符号)在这里指当前用户的根目录,在创建新用户的时候会在/etc/passwd文件 中的第六个字段说明主目录(如果你创建用户的时候没有指定根目录,默认为:/home/usrname),下面我们具体来看看.vimrc的配置...$ vi ~/.vimrc你可以依自己的爱好选择如下内容copy到.vimrc中:[只是为了方便写C程序,提供自动格式化,使用C风格的自动缩进,tab设置为4个space...]
set fenc=utf-8 "设定默认解码
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
set nocp "或者 set nocompatible 用于关闭VI的兼容模式
set number "显示行号
set ai "或者 set autoindent vim使用自动对齐,也就是把当前行的对齐格式应用到下一行
set si "或者 set smartindent 依据上面的对齐格式,智能的选择对齐方式
set tabstop=4 "设置tab键为4个空格
set sw=4 "或者 set shiftwidth 设置当行之间交错时使用4个空格
set ruler "设置在编辑过程中,于右下角显示光标位置的状态行
set incsearch "设置增量搜索,这样的查询比较smart
set showmatch "高亮显示匹配的括号
set matchtime=5 "匹配括号高亮时间(单位为 1/10 s) set ignorecase "在搜索的时候忽略大小写
syntax on "高亮语法
[下面是网上比较流行的一些.vimrc] """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 一般设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 设定默认解码
set fenc=utf-8
set fencs=utf-8,usc-bom,euc-jp,gb18030,gbk,gb2312,cp936
" 不要使用vi的键盘模式,而是vim自己的
set nocompatible
" history文件中需要记录的行数
set history=100
" 在处理未保存或只读文件的时候,弹出确认
set confirm
" 与windows共享剪贴板
set clipboard+=unnamed
" 侦测文件类型
filetype on
" 载入文件类型插件
filetype plugin on
" 为特定文件类型载入相关缩进文件
filetype indent on
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换行分割
set iskeyword+=_,$,@,%,#,-
" 语法高亮
syntax on
" 高亮字符,让其不受100列限制
:highlight OverLength ctermbg=red ctermfg=white guibg=red guifg=white
:match OverLength '\%101v.*'
" 状态行颜色
highlight StatusLine guifg=SlateBlue guibg=Yellow
highlight StatusLineNC guifg=Gray guibg=White
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文件设置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 不要备份文件(根据自己需要取舍)
set nobackup
" 不要生成swap文件,当buffer被丢弃的时候隐藏它
setlocal noswapfile
set bufhidden=hide
" 字符间插入的像素行数目
set linespace=0
" 增强模式中的命令行自动完成操作
set wildmenu
" 在状态行上显示光标所在位置的行号和列号
set ruler
set rulerformat=%20(%2*%<%f%=\ %m%r\ %3l\ %c\ %p%%%)
" 命令行(在状态行下)的高度,默认为1,这里是2
set cmdheight=2
" 使回格键(backspace)正常处理indent, eol, start等
set backspace=2
" 允许backspace和光标键跨越行边界
set whichwrap+=<,>,h,l
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
" 不让vim发出讨厌的滴滴声
set noerrorbells
" 在被分割的窗口间显示空白,便于阅读
set fillchars=vert:\ ,stl:\ ,stlnc:\
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 搜索和匹配
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 高亮显示匹配的括号
set showmatch
" 匹配括号高亮的时间(单位是十分之一秒)
set matchtime=5
" 在搜索的时候忽略大小写
set ignorecase
" 不要高亮被搜索的句子(phrases)
set nohlsearch
" 在搜索时,输入的词句的逐字符高亮(类似firefox的搜索)
set incsearch
" 输入:set list命令是应该显示些啥?
set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$
" 光标移动到buffer的顶部和底部时保持3行距离
set scrolloff=3
" 不要闪烁
set novisualbell
" 我的状态行显示的内容(包括文件类型和解码)
set statusline=%F%m%r%h%w\[POS=%l,%v][%p%%]\%{strftime(\"%d/%m/%y\ -\ %H:%M\")}
" 总是显示状态行
set laststatus=2
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 文本格式和排版
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 自动格式化
set formatoptions=tcrqn
" 继承前一行的缩进方式,特别适用于多行注释
set autoindent
" 为C程序提供自动缩进
set smartindent
" 使用C样式的缩进
set cindent
" 制表符为4
set tabstop=4
" 统一缩进为4
set softtabstop=4
set shiftwidth=4
" 不要用空格代替制表符
set noexpandtab
" 不要换行
set nowrap
" 在行和段开始处使用制表符
set smarttab
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags的设定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 按照名称排序
let Tlist_Sort_Type = "name"
" 在右侧显示窗口
let Tlist_Use_Right_Window = 1
" 压缩方式
let Tlist_Compart_Format = 1
" 如果只有一个buffer,kill窗口也kill掉buffer
let Tlist_Exist_OnlyWindow = 1
" 不要关闭其他文件的tags
let Tlist_File_Fold_Auto_Close = 0
" 不要显示折叠树
let Tlist_Enable_Fold_Column = 0
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autocommands
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 只在下列文件类型被侦测到的时候显示行号,普通文本文件不显示
if has("autocmd")
autocmd FileType xml,html,c,cs,java,perl,shell,bash,cpp,python,vim,php,ruby set number
autocmd FileType xml,html vmap <C-o> <ESC>'<i<!--<ESC>o<ESC>'>o-->
autocmd FileType java,c,cpp,cs vmap <C-o> <ESC>'<o/*<ESC>'>o*/
autocmd FileType html,text,php,vim,c,java,xml,bash,shell,perl,python setlocal textwidth=100
autocmd Filetype html,xml,xsl source $VIMRUNTIME/plugin/closetag.vim
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe " normal g`\"" |
\ endif
endif "has("autocmd")
" F5编译和运行C程序,F6编译和运行C++程序
" 请注意,下述代码在windows下使用会报错
" 需要去掉./这两个字符
" C的编译和运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc
" C++的编译和运行
map <F6> :call CompileRunGpp()<CR>
func! CompileRunGpp()
exec "w"
exec "!g++ % -o %<"
exec "! ./%<"
endfunc
" 能够漂亮地显示.NFO文件
set encoding=utf-8
function! SetFileEncodings(encodings)
let b:myfileencodingsbak=&fileencodings
let &fileencodings=a:encodings
endfunction
function! RestoreFileEncodings()
let &fileencodings=b:myfileencodingsbak
unlet b:myfileencodingsbak
endfunction
au BufReadPre *.nfo call SetFileEncodings('cp437')|set ambiwidth=single au BufReadPost *.nfo call RestoreFileEncodings()
" 高亮显示普通txt文件(需要txt.vim脚本)
au BufRead,BufNewFile * setfiletype txt
" 用空格键来开关折叠
set foldenable
set foldmethod=manual
nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc':'zo')<CR>
" minibufexpl插件的一般设置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
**************************************************
源文件
**************************************************
" 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 on
endif
" 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 available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif
set nocompatible
set nu
set autoindent
set showmatch
set ruler
set tabstop=4
set shiftwidth=4
set softtabstop=4
set cindent
syntax on
****************************************
参考文件
****************************************
set nu
set nocp
syntax on
if has('mouse')
set mouse-=a
endif
set ru
set fileencodings=utf-8,gbk,ucs-bom,cp936
*******************************
VI编辑器,我想每次在编程序时,头文件和main函数都不用再写了,有没有什么简单方法?
能不以这样:把同样的内容单独存为一个文件。然后在以后编程序时插入此文件。如此类似方法插入其它内容。
- 提问者评价
对,在末行模式键入“r 文件名 回车” 就可以了
- vi的配置
- 我的vi 配置
- vi编辑器的配置
- VI编辑器的配置
- VI的配置
- VI编辑器的配置
- vi的各项配置
- vi编辑器的配置
- Linux 下的 vi 配置
- 备份我的vi配置
- vi/vim/gvim的配置
- Vi编辑器的简单配置
- linux vi编辑器的配置
- VI 编辑器的一些配置
- 我的VI编辑器配置
- 配置合适的Vi配置文件
- vi配置
- vi配置
- [Euler]Problem 32 - Pandigital products
- 浅谈微信对运营商的冲击
- 给年轻程序员的建议
- Android的Activity的onCreate()多次调用的问题
- 几个开源GIS软件
- VI的配置
- 一个游戏程序员的学习资料
- hdu 2922 Relax! It’s just a game
- 作业
- Selenium python
- 黑马程序员_java内部类之学习笔记
- 分享:sp_get_object_definition查找所有数据库下面哪些对象定义语句中包括想要查找的字符串
- opencv 笔记09Imgproc_Smoothing
- putty登录本地linux虚拟机