记录下我的Linux系统中vim⽂件的配置---(.vimrc⽂件配置模
板)
vimrc⽂件是vim的环境设置⽂件。整体的vim的设置是在 /etc/vim/vimrc ⽂件中。如果想设置所有⽤户的配置,在⾥⾯设置就可以了,配置和.vimrc是⼀样的,在最后⾯添加下⾯中的语句。
不建议修改/etc/vimrc ⽂件,每个⽤户可以在⽤户home⽬录中设置vim,新建.vimrc。命令如下:
vim ~/.vimrc
.vimrc配置⽂件中写⼊内容如下,保存后再重启VIM即可;
"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
" 智能补全
set completeopt=longest,menu
" 载⼊⽂件类型插件
filetype plugin on
" 为特定⽂件类型载⼊相关缩进⽂件
filetype indent on
" 保存全局变量
set viminfo+=!
" 带有如下符号的单词不要被换⾏分割
set iskeyword+=_,$,@,%,#,-
" 语法⾼亮
syntax enable
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:$
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
linux系统vim编辑器" 如果只有⼀个buffer,kill窗⼝也kill掉buffer
let Tlist_Exist_OnlyWindow = 1
" 不要关闭其他⽂件的tags
let Tlist_File_Fold_Auto_Close = 0
" 不要显⽰折叠树
let Tlist_Enable_Fold_Column = 0 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""新⽂件标题"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""定义函数SetTitle,⾃动插⼊⽂件头
func SetTitle()
"如果⽂件类型为.sh⽂件
if &filetype == 'sh'
call setline(1, ">>>>>>>>>>>>>>####")
call append(line("."), "# File Name: ".expand("%"))
call append(line(".")+1, "# Author: kadoop")
call append(line(".")+2, "# mail: kadoop@163")
call append(line(".")+3, "# Created Time: ".strftime("%c"))
call append(line(".")+4, ">>>>>>>>>>>>>>###")
call append(line(".")+5, "#!/bin/zsh")
call append(line(".")+6, "PATH=/home/edison/bin:/home/edison/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/sna call append(line(".")+7, "export PATH")
call append(line(".")+8, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: kadoop")
call append(line(".")+2, " > Mail: kadoop@163")
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<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
" if &filetype == 'java'
" call append(line(".")+6,"public class ".expand("%"))
" call append(line(".")+7,"")
" endif
"新建⽂件后,⾃动定位到⽂件末尾
autocmd BufNewFile * normal G
endfunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 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
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>
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
" 配⾊⽅案
colorscheme desert
" Taglist 配置
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
" winmanager 配置
map wm :WMToggle<cr>
let g:winManagerWindowLayout='FileExplorer|TagList'
"cscope 配置
if has("cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" cscope 快捷键
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
Linux——基础命令用法(上)
下一篇 »
发表评论