新建文件,自動加入文件頭html
修改文件,保存時,自動更新修改時間字段python
自動匹配括號,引號等ios
vimrc文件以下git
1 "========================================== 2 "General 3 "========================================== 4 5 " history存儲長度。 6 set history=1000 7 set encoding=utf-8 8 set fileencodings=ucs-bom,utf-8,cp936 9 set fileencoding=gb2312 10 set termencoding=utf-8 11 12 "檢測文件類型 13 filetype on 14 " 針對不一樣的文件類型採用不一樣的縮進格式 15 filetype indent on 16 "容許插件 17 filetype plugin on 18 "啓動自動補全 19 filetype plugin indent on 20 21 " 非兼容vi模式。去掉討厭的有關vi一致性模式,避免之前版本的一些bug和侷限 22 set nocompatible 23 set autoread " 文件修改以後自動載入。 24 25 " 取消備份。 26 " Turn backup off, since most stuff is in SVN, git et.c anyway... 27 set nobackup 28 set nowb 29 set noswapfile 30 31 " No annoying sound on errors 32 " 去掉輸入錯誤的提示聲音 33 set noerrorbells 34 set novisualbell 35 set t_vb= 36 set tm=500 37 38 39 "========================================== 40 " show and format 41 "========================================== 42 "顯示行號: 43 set number 44 set nowrap " 取消換行。 45 ""爲方便複製,用<F2>開啓/關閉行號顯示: 46 nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR> 47 48 49 "括號配對狀況 50 set showmatch 51 " How many tenths of a second to blink when matching brackets 52 set mat=2 53 54 "設置文內智能搜索提示 55 " 高亮search命中的文本。 56 set hlsearch 57 " 搜索時忽略大小寫 58 set ignorecase 59 " 隨着鍵入即時搜索 60 set incsearch 61 " 有一個或以上大寫字母時仍大小寫敏感 62 set smartcase 63 64 " 代碼摺疊 65 " set foldenable 66 " 摺疊方法 67 " manual 手工摺疊 68 " indent 使用縮進表示摺疊 69 " expr 使用表達式定義摺疊 70 " syntax 使用語法定義摺疊 71 " diff 對沒有更改的文本進行摺疊 72 " marker 使用標記進行摺疊, 默認標記是 {{{ 和 }}} 73 " set foldmethod=syntax 74 " 在左側顯示摺疊的層次 75 " set foldcolumn=4 76 77 set tabstop=4 " 設置Tab鍵的寬度 [等同的空格個數] 78 set shiftwidth=4 79 set expandtab " 將Tab自動轉化成空格 [須要輸入真正的Tab鍵時,使用 Ctrl+V + Tab] 80 " 按退格鍵時能夠一次刪掉 4 個空格 81 set softtabstop=4 82 83 set ai "Auto indent 84 set si "Smart indent 85 86 "========================================== 87 " status 88 "========================================== 89 "顯示當前的行號列號: 90 set ruler 91 ""在狀態欄顯示正在輸入的命令 92 set showcmd 93 94 " Set 7 lines to the cursor - when moving vertically using j/k 上下滾動,始終在中間 95 set so=7 96 97 "set cursorline " 突出顯示當前行 98 99 " 命令行(在狀態行下)的高度,默認爲1,這裏是2 100 " set cmdheight=2 101 set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} 102 " Always show the status line 103 set laststatus=2 104 105 106 "========================================== 107 "colors and fonts 108 "========================================== 109 "開啓語法高亮 110 syntax enable 111 syntax on 112 113 "配色方案 三種,選一個 114 "colorscheme darkblue " 深藍色配色方案。 115 116 "colorscheme desert " 經典配色方案。 117 "set background=dark 118 119 " Set extra options when running in GUI mode 120 if has("gui_running") 121 set guioptions-=T 122 set guioptions+=e 123 set t_Co=256 124 set guitablabel=%M\ %t 125 endif 126 "set guifont=Monaco:h20 " 字體 && 字號 127 128 "========================================== 129 " file encode 130 "========================================== 131 132 " Use Unix as the standard file type 133 set ffs=unix,dos,mac 134 135 " 如遇Unicode值大於255的文本,沒必要等到空格再折行。 136 set formatoptions+=m 137 " 合併兩行中文時,不在中間加空格: 138 set formatoptions+=B 139 140 141 "========================================== 142 "others 143 "========================================== 144 145 " 自動完成 146 set completeopt=longest,menu 147 " 加強模式中的命令行自動完成操做 148 set wildmenu 149 " Ignore compiled files 150 set wildignore=*.o,*~,*.pyc 151 152 " Python 文件的通常設置,好比不要 tab 等 153 autocmd FileType python set tabstop=4 shiftwidth=4 expandtab 154 "自動補全配置 155 autocmd FileType python set omnifunc=pythoncomplete#Complete 156 157 158 " Return to last edit position when opening files (You want this!) 159 autocmd BufReadPost * 160 \ if line("'\"") > 0 && line("'\"") <= line("$") | 161 \ exe "normal! g`\"" | 162 \ endif 163 164 " A buffer becomes hidden when it is abandoned 165 "set hid 166 167 " For regular expressions turn magic on 168 set magic 169 170 " Configure backspace so it acts as it should act 171 set backspace=eol,start,indent 172 set whichwrap+=<,>,h,l 173 174 175 "新建.c,.h,.sh,.Java文件,自動插入文件頭 176 autocmd BufNewFile *.cpp,*.hpp,*.cc,*.[ch],*.sh,*.Java exec ":call SetTitle()" 177 ""定義函數SetTitle,自動插入文件頭 178 func SetTitle() 179 if &filetype == 'sh' 180 call setline(1,"\#########################################################################") 181 call append(line("."), "\# File Name: ".expand("%")) 182 call append(line(".")+1, "\# Author: carbonyang@shuame.com") 183 call append(line(".")+2, "\# Description: carbonyang@shuame.com") 184 call append(line(".")+3, "\# Created Time: ".strftime("%c")) 185 call append(line(".")+4, "\# Modified Time: ".strftime("%c")) 186 call append(line(".")+5, "\#########################################################################") 187 call append(line(".")+6, "") 188 call append(line(".")+7, "") 189 call append(line(".")+8, "") 190 call append(line(".")+9, "\#!/bin/bash") 191 call append(line(".")+10, "") 192 else 193 call setline(1, "/*************************************************************************") 194 call append(line("."), "\ * File Name: ".expand("%")) 195 call append(line(".")+1, "\ * Author: carbonyang@shuame.com") 196 call append(line(".")+2, "\ * Created Time: ".strftime("%Y-%m-%d %H:%M:%S %Z")) 197 call append(line(".")+3, "\ * Modified Time: ".strftime("%Y-%m-%d %H:%M:%S %Z")) 198 call append(line(".")+4, "\ * Description: ") 199 call append(line(".")+5, "\ * ┏┛ ┻━━━━━┛ ┻┓") 200 call append(line(".")+6, "\ * ┃ ┃") 201 call append(line(".")+7, "\ * ┃ ━ ┃") 202 call append(line(".")+8, "\ * ┃ ┳┛ ┗┳ ┃") 203 call append(line(".")+9, "\ * ┃ ┃") 204 call append(line(".")+10, "\ * ┃ ┻ ┃") 205 call append(line(".")+11, "\ * ┃ ┃") 206 call append(line(".")+12, "\ * ┗━┓ ┏━━━┛") 207 call append(line(".")+13, "\ * ┃ ┃ 神獸保佑") 208 call append(line(".")+14, "\ * ┃ ┃ 代碼無蟲") 209 call append(line(".")+15, "\ * ┃ ┗━━━━━━━━━┓") 210 call append(line(".")+16, "\ * ┃ ┣┓") 211 call append(line(".")+17, "\ * ┃ ┏┛") 212 call append(line(".")+18, "\ * ┗━┓ ┓ ┏━━━┳ ┓ ┏━┛") 213 call append(line(".")+19, "\ * ┃ ┫ ┫ ┃ ┫ ┫") 214 call append(line(".")+20, "\ * ┗━┻━┛ ┗━┻━┛") 215 call append(line(".")+21, "************************************************************************/") 216 call append(line(".")+22, "") 217 call append(line(".")+23, "") 218 call append(line(".")+24, "") 219 endif 220 if &filetype == 'cpp' 221 call append(line(".")+25, "#include<iostream>") 222 call append(line(".")+26, "") 223 call append(line(".")+27, "using namespace std;") 224 call append(line(".")+28, "") 225 call append(line(".")+29, "") 226 endif 227 if &filetype == 'c' 228 call append(line(".")+25, "#include<stdio.h>") 229 call append(line(".")+26, "") 230 call append(line(".")+27, "") 231 endif 232 autocmd BufNewFile * normal G 233 endfunc 234 235 let g:update_time_time_stamp_leader = 'Modified Time: ' 236 let g:update_time_enable = 1 237 let g:update_time_time_format = '%Y-%m-%d %H:%M:%S %Z' 238 map <F4> gg: <Esc>O<Esc>: call SetTitle()<cr> <Esc>G 239 240 " 括號自動補全 241 inoremap ( ()<Esc>i 242 inoremap [ []<Esc>i 243 inoremap { {<CR>}<Esc>O 244 autocmd Syntax html,vim inoremap < <lt>><Esc>i| inoremap > <c-r>=ClosePair('>')<CR> 245 inoremap ) <c-r>=ClosePair(')')<CR> 246 inoremap ] <c-r>=ClosePair(']')<CR> 247 inoremap } <c-r>=CloseBracket()<CR> 248 inoremap " <c-r>=QuoteDelim('"')<CR> 249 inoremap ' <c-r>=QuoteDelim("'")<CR> 250 251 function ClosePair(char) 252 if getline('.')[col('.') - 1] == a:char 253 return "\<Right>" 254 else 255 return a:char 256 endif 257 endf 258 259 function CloseBracket() 260 if match(getline(line('.') + 1), '\s*}') < 0 261 return "\<CR>}" 262 else 263 return "\<Esc>j0f}a" 264 endif 265 endf 266 267 function QuoteDelim(char) 268 let line = getline('.') 269 let col = col('.') 270 if line[col - 2] == "\\" 271 return a:char 272 elseif line[col - 1] == a:char 273 return "\<Right>" 274 else 275 return a:char.a:char."\<Esc>i" 276 endif 277 endf
自動更新修改時間須要用到插件update-time.vimexpress
保存至.vim/plugin/便可自動加載vim
update-time代碼:bash
1 " File: update-time.vim 2 " Author: QianChenglong <qianchenglong2012@gmail.com> 3 " Create Time: 2013-12-04 19:36:21 CST 4 " Last Change: 2013-12-05 12:14:15 CST 5 " Description: Automatic update Last Change time 6 7 " SECTION: Init"{{{ 8 if exists("g:loaded_update_time") 9 finish 10 endif 11 let g:loaded_update_time = 1 12 13 let s:save_cpo = &cpo 14 set cpo&vim 15 "}}} 16 " SECTION: Varible"{{{ 17 if !exists('g:update_time_time_stamp_leader') 18 let s:time_stamp_leader = 'Last Change: ' 19 else 20 let s:time_stamp_leader = g:update_time_time_stamp_leader 21 endif 22 23 if !exists('g:update_time_time_format') 24 let s:time_format = '%Y-%m-%d %H:%M:%S %Z' 25 else 26 let s:time_format = g:update_time_time_format 27 endif 28 29 if !exists("g:update_time_begin_line") 30 let s:begin_line = 0 31 else 32 let s:begin_line = g:update_time_begin_line 33 endif 34 35 if !exists('g:update_time_end_line') 36 let s:end_line = 10 37 else 38 let s:end_line = g:update_time_end_line 39 endif 40 41 if !exists('g:update_time_enable') 42 let s:update_time_enable = 1 43 else 44 let s:update_time_enable = g:update_time_enable 45 endif 46 "}}} 47 " SECTION: Funtions"{{{ 48 fun Update_time_update() 49 if ! &modifiable 50 return 51 endif 52 if ! s:update_time_enable 53 return 54 endif 55 let bufmodified = getbufvar('%', '&mod') 56 if ! bufmodified 57 return 58 endif 59 let pos = line('.').' | normal! '.virtcol('.').'|' 60 exe s:begin_line 61 let line_num = search(s:time_stamp_leader, '', s:end_line) 62 if line_num > 0 63 let line = getline(line_num) 64 let line = substitute(line, s:time_stamp_leader . '\zs.*', strftime(s:time_format), '') 65 call setline(line_num, line) 66 endif 67 exe pos 68 endf 69 fun Update_time_toggle() 70 let s:update_time_enable = !s:update_time_enable 71 endf 72 "}}} 73 " SECTION: Autocommands"{{{ 74 autocmd BufWritePre * call Update_time_update() 75 "}}} 76 " SECTION: Commands"{{{ 77 com! -nargs=0 UpdateTimeToggle call Update_time_toggle() 78 "}}} 79 " SECTION: Clean up"{{{ 80 let &cpo = s:save_cpo 81 unlet s:save_cpo 82 "}}}