vim编辑器(vimrc)的配置
来源:互联网 发布:软件开发工程师职责 编辑:程序博客网 时间:2024/06/07 10:27
关于vim的编辑器的配置文件
vim编辑器的配置文件为vimrc的文件, 在/etc/vim/vimrc 或用户目录~/.vimrc(以点开头的隐藏文件,当ls -a时,才会显示出所有隐藏的文件), 如果在用户目录下没有的话可以将/etc/vim/vimrc下的复制到用户目录~/ ,用户目录下vimrc配置文件的优先级更高. 但是在当前用户下配置的.vimrc仅对当前用户有效.在.vimrc文件中我们可以自定义多种初始化设置,每次打开vim会读取该配置文件.
Linux系统下,Tab键默认为8个字符,要修改为4个字符的方式, 和其他的设置, 在.vimrc配置文件中添加:
- set tabstop=4
tabstop 表示一个 tab 显示出来是4个空格,默认 8。 - set shiftwidth=4
shiftwidth 表示每一级缩进的空格数为4 - set autoindent
设置自动缩进:即每行的缩进值与上一行相等;使用 noautoindent 取消设置: - set cindent
使用 C/C++ 语言的自动缩进方式 - set number或set nu
显示行号 - set hlsearch
高亮搜索结果 - syntax on
语法高亮 - set showmatch, set sm
括号匹配高亮显示 - set ic
忽略字符大小写
vim中自动添加文件的作者、时间信息等.
按F2在文件头部自动添加
因为初学vim,简单配置了自己的vimrc,贴出来供大家参考下:
” 为注释行
" All system-wide defaults are set in $VIMRUNTIME/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)set tabstop=4 set shiftwidth=4set autoindentset cindentset number" Source a global configuration file if availableif filereadable("/etc/vim/vimrc.local") source /etc/vim/vimrc.localendif"SET Comment START (Addtitles也就是添加标题)"表示遇到这些文件类型自动创建 autocmd BufNewFile *.php,*.js,*.cpp,*.c exec ":call SetComment()" |normal 10Go"map <F2> :call SetComment()<CR>:10<CR>omap <F2> :call SetComment()<cr>'s func SetComment() if expand("%:e")=='php' call setline(1,"<?php") elseif expand("%:e")=='js' call setline(1,'//JavaScript file') elseif expand("%:e")=='cpp' call setline(1,'//C++ file') elseif expand("%:e")=='c' call setline(1,'//C file') endif call append(1,'/******************************************************') call append(2,'*') call append(3,'* Filename : '.expand("%:t")) call append(4,'* Author : Liuamin') call append(5,'* Email : 502935795@qq.com') call append(6,'* Create :'.strftime("%Y-%m-%d %H:%M:%S")) call append(7,'* Last modified :'.strftime("%Y-%m-%d %H:%M:%S")) call append(8,'* Description :') call append(9,'* ****************************************************/') echohl WarningMsg | echo "Successful in adding the copyright." | echohl Noneendfunc"SET Comment END"Updata Last modified and Filename(更新最近修改时间和文件名)function UpdataTitle() normal m' execute '/# *Last modified:/s@:.*$@\=strftime(":\t%Y-%m-%d %H:%M:%S")@' normal '' execute '/# *Filename:/s@:.*$@\=":\t\t".expand("%:t")@' execute "noh" normal 'k echohl WaringMsg | echo "Successful in updating the copy right."| echohl Noneendfunction"判断前10行代码中,是否有Last modified这个单词"如果没有的话,代表没有添加过Title,需要新添加,此处屏蔽掉Setcomment(),没有不需要添加"如果有的话,只需要更新即可function UpdataTitle2() len n=1 while n<7 len line=getline(n) if line =~'^\s*\*\s*\S*Last\s*modified\s*:\s*\S*.*$' call UpdataTitle() return endif len n=n+1 endwhile call SetComment()endfunction"autocmd FileWritePre,BufWritePre *.php,*.js,*.cpp,*c ks|call UpdataTitle2() |'s
阅读全文
0 0
- vim编辑器(vimrc)的配置
- VIM 的配置 .vimrc
- 我的vim配置.vimrc
- vim中vimrc的配置
- 我的VIM -- vimrc配置
- Linux编辑器-Vim的.vimrc文件
- vim编辑器配置文件 .vimrc
- 配置Linux下vim编辑器(.vimrc文件)
- vim的配置文件.vimrc常规配置
- .vimrc Vim的配置文件及配置方法
- vim 安装与vimrc的配置问题
- vim终极配置!!!(vimrc)
- vim配置vimrc
- vim配置vimrc详解
- vim配置(~/.vimrc)
- Vim常用配置(~/.vimrc)
- VIM配置 .vimrc
- Vim配置备份.vimrc
- Opencv图像处理之滤波降噪
- 在js中实现list<Map>
- mysql实现类似于oracle dblink的功能/开启Federated引擎
- android学习---使用Litepal操作数据库2
- scripts/kconfig/lxdialog/dialog.h:38:20: fatal error: curses.h: No such file or directory
- vim编辑器(vimrc)的配置
- linux学习书籍推荐汇总 附带下载地址
- 没网时候设置开启网络
- Swift基础 自动引用计数和析构器
- Maven官方文档之POM Reference
- 教你如何学会Yii的自动加载!!
- 《深入探索C++对象模型》读书笔记——第二章 构造函数语意学
- 电子商务复习笔记三:网络营销
- 新型式下的IT互联网行业发展要素