vimrc配置文件

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 <space> @=((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""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章