cat ~/.vimrc  #从网上搜集来的,最后部分包括自动头部,自动更新时间

 

""""""""""设定默认解码"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936

set termencoding=utf-8

set encoding=utf-8

set fileencodings=ucs-bom,utf-8,cp936

set history=1000

 

""""""""""" tab相关变更 """""""""""""""""""""""

" 设置Tab键的宽度 [等同的空格个数]

set tabstop=4

" 每一次缩进对应的空格数

set shiftwidth=4

" 按退格键时可以一次删掉 4 个空格

set softtabstop=4

 

" 不要闪烁

set novisualbell

" 语法高亮

syntax on

" """"高亮显示关键字""""""

" syntax keyword xxxxxx xxx

highlight link gtkType Type

" 在处理未保存或只读文件的时候,弹出确认

set confirm

" windows共享剪贴板

set clipboard+=unnamed

" 检测文件类型

filetype on

" 针对不同的文件类型采用不同的缩进格式

" filetype indent on

" 允许插件

filetype plugin on

" 启动自动补全

filetype plugin indent on

" 文件修改之后自动载入

set autoread

" 突出显示当前列

set cursorcolumn

" 突出显示当前行

set cursorline

" 保存全局变量

" set viminfo+=!

" 带有如下符号的单词不要被换行分割

set iskeyword+=_,$,@,%,#,-

 

" 设置 退出vim后,内容显示在终端屏幕, 可以用于查看和复制, 不需要可以去掉

" 好处:误删什么的,如果以前屏幕打开,可以找回

set t_ti= t_te=

" 在被分割的窗口间显示空白,便于阅读

set fillchars=vert:\ ,stl:\ ,stlnc:\

 

" change the terminal's title

" set title

" 左下角显示当前vim模式

set showmode

 

" 光标移动到buffer的顶部和底部时保持3行距

set scrolloff=5

" set winwidth=79

""""""""""底部状态栏""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"Format the statusline

" Always show the status line - use 2 lines for the status bar

set laststatus=2

" 命令行(在状态行下)的高度,默认为1,这里是2

set cmdheight=2

" 高亮字符,让其不受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

 

" Nice statusbar

" This is the one I use:

set statusline=

set statusline+=%7*\[%n] "buffernr

set statusline+=%1*\ %<%F\ "File+path

set statusline+=%2*\ %y\ "FileType

set statusline+=%3*\ %{''.(&fenc!=''?&fenc:&enc).''} "Encoding

set statusline+=%3*\ %{(&bomb?\",BOM\":\"\")}\ "Encoding2

set statusline+=%4*\ %{&ff}\ "FileFormat (dos/unix..)

set statusline+=%5*\ %{&spelllang}\%{HighlightSearch()}\ "Spellanguage & Highlight on?

set statusline+=%8*\ %=\ row:%l/%L\ (%03p%%)\ "Rownumber/total (%)

set statusline+=%9*\ col:%03c\ "Colnr

set statusline+=%0*\ \ %m%r%w\ %P\ \ "Modified? Readonly? Top/bot.

" set statusline+=%F%m%r%h%w

" set statusline+=[%{strftime(\"%Y-%m-%d\ %H:%M\")}] " time

 

" Highlight on? function:

function! HighlightSearch()

if &hls

return 'H'

else

return ''

endif

endfunction

 

" Colors (adapted from ligh2011.vim):

hi User1 guifg=#ffdad8 guibg=#880c0e

hi User2 guifg=#000000 guibg=#F4905C

hi User3 guifg=#292b00 guibg=#f4f597

hi User4 guifg=#112605 guibg=#aefe7B

hi User5 guifg=#051d00 guibg=#7dcc7d

hi User7 guifg=#ffffff guibg=#880c0e gui=bold

hi User8 guifg=#ffffff guibg=#5b7fbb

hi User9 guifg=#ffffff guibg=#810085

hi User0 guifg=#ffffff guibg=#094afe

""""""""""其他""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 使回格键(backspace)正常处理indent, eol, start

set backspace=2

" 允许backspace和光标键跨越行边界

set whichwrap+=<,>,h,l

 

" 显示行号

" set number

" 取消换行

set nowrap

" 括号配对情况, 跳转并高亮一下匹配的括号

set showmatch

" 匹配括号高亮的时间(单位是十分之一秒)

set matchtime=5

" 输入:set list命令是应该显示些啥?

set listchars=tab:\|\ ,trail:.,extends:>,precedes:<,eol:$

 

" 文件设置

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

" 不要备份文件(根据自己需要取舍)

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%%%)

 

" 设置文内智能搜索提示

" 高亮search命中的文本

set hlsearch

" 打开增量搜索模式,随着键入即时搜索

set incsearch

" 搜索时忽略大小写

set ignorecase

" 有一个或以上大写字母时仍大小写敏感

set smartcase

" 高亮显示匹配的括号

set showmatch

" 代码折叠

set foldenable

" 折叠方法

" manual 手工折叠

" indent 使用缩进表示折叠

" expr 使用表达式定义折叠

" syntax 使用语法定义折叠

" diff 对没有更改的文本进行折叠

" marker 使用标记进行折叠, 默认标记是 {{{ }}}

"set foldmethod=manual

set foldmethod=syntax

set foldlevel=100

" 用空格键来开关折叠

nnoremap @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>

 

 

" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)

" set mouse=a

" set selection=exclusive

" set selectmode=mouse,key

 

" 通过使用: commands命令,告诉我们文件的哪一行被改变过

set report=0

" 不让vim发出讨厌的滴滴声

set noerrorbells

 

" 缩进配置

" Smart indent

" set smartindent

" 打开自动缩进

" 继承前一行的缩进方式,特别适用于多行注释

" set autoindent

 

"自动命令,每次写入.vimrc后,都会执行这个自动命令,source一次~/.vimrc

autocmd! bufwritepost .vimrc source ~/.vimrc

 

"""""""""自动头部文件,自动更新时间"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()"

"新建.py,.cc,.java,.sh,

"定义函数SetTitle,自动插入文件头

func SetTitle()

"如果文件类型为.sh文件

if &filetype == 'sh'

call setline(1, "\#!/bin/bash")

call setline(2, "\# ")

call setline(3, "\# Author: PengRuifang && qq383326308")

call setline(4, "\# Created Time : ".strftime("%c"))

call setline(5, "\# Last Modified:")

call setline(6, "\# File Name: ".expand("%"))

call setline(7, "\# Description:")

call setline(8, "")

normal G

endif

if &filetype == 'python'

call setline(1, "\#!/usr/bin/env python")

call setline(2, "\# coding=utf8")

call setline(3, "\# Author: PengRuifang && qq383326308")

call setline(4, "\# Created Time : ".strftime("%c"))

call setline(5, "\# Last Modified:")

call setline(6, "\# File Name: ".expand("%"))

call setline(7, "\# Description:")

call setline(8, "")

call setline(9, "")

normal G

endif

if &filetype == 'java'

call setline(1, "//coding=utf8")

call setline(2, "/*************************************************************************")

call setline(3, "\ @Author: PengRuifang && qq383326308")

call setline(4, "\ @Created Time : ".strftime("%c"))

call setline(5, "") @Last Modified:

call setline(6, "\ @File Name: ".expand("%"))

call setline(7, "\ @Description:")

call setline(8, "")

call setline(9, " ************************************************************************/")

call setline(10,"")

normal G

endif

endfunc

 

" modify the last modified time of a file

function SetLastModifiedTime(lineno)

let modif_time = strftime("%c")

if a:lineno == "-1"

let line = getline(6)

else

let line = getline(a:lineno)

endif

if line =~ '^////\sLast Modified'

let line = substitute( line,':\s\+.*\d\{4\}', ':'.modif_time, "" )

else

let line = '# Last Modified: '.modif_time

endif

if a:lineno == "-1"

call setline(5, line)

else

call append(a:lineno, line)

endif

endfunction

 

" map the SetLastModifiedTime command automatically

au BufWrite *.py,*.java,*.sh call SetLastModifiedTime(-1)

""""""""""end""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""