| 1 | " .vimrc by Tobias Schlitt <toby@php.net>. |
|---|
| 2 | " No copyright, feel free to use this, as you like, as long as you keep some |
|---|
| 3 | " credits. |
|---|
| 4 | " |
|---|
| 5 | " General VIM settings file. Optimized for coding PHP can be found in |
|---|
| 6 | " ~/vim/ftdetect/php.vim. |
|---|
| 7 | " |
|---|
| 8 | " v1.1pl1 |
|---|
| 9 | " |
|---|
| 10 | " Changelog: |
|---|
| 11 | " |
|---|
| 12 | " v1.1: |
|---|
| 13 | " -------------- |
|---|
| 14 | " - Added versioning and changelog |
|---|
| 15 | " - Added auto-completion using <TAB> |
|---|
| 16 | " - Added auto-reload command, when .vimrc changes |
|---|
| 17 | " - Deactivated <CTRL>-p => "pear package" in favor of |
|---|
| 18 | " - Mapped <CTRL>-p => "run through CLI" |
|---|
| 19 | " - Added fold markers for better overview |
|---|
| 20 | " - Added for mapping for wrapping visual selections into chars (like '/(/...) |
|---|
| 21 | " - Added scrolljump=5 and scrolloff=3 for better moving around with folds |
|---|
| 22 | " - Added mapping <CTRL>-h to search for the word under the cursor (should be |
|---|
| 23 | " a funcion) using phpm |
|---|
| 24 | " - Replaced map/imap with noremap/inoremap for clearer mappings |
|---|
| 25 | " |
|---|
| 26 | " v1.1pl1: |
|---|
| 27 | " -------------- |
|---|
| 28 | " - Fixed issue with <CTRL>-p for running PHP CLI (missing <cr>) |
|---|
| 29 | " - Remapped PHP compile check to ; (in command mode only) |
|---|
| 30 | " |
|---|
| 31 | " v1.2: |
|---|
| 32 | " ----- |
|---|
| 33 | " - Remapped PHP compile check to . (in command mode only) |
|---|
| 34 | " - Mapped ; to (add ; at the end of line, when missing - command mode only) |
|---|
| 35 | " - Added make facilities (:make, jump to error). |
|---|
| 36 | " - Added setting for not highlighting every search result (nohlsearch). |
|---|
| 37 | " - Added laststatus=2 (tipp by Derick) |
|---|
| 38 | " - Tip by Jakob (UG): Visual, <z>, <f> == foldmarkers for area |
|---|
| 39 | " - Moved PHP specific settings to .vim/ftdetect/php.vim |
|---|
| 40 | " - Activated sourcing of ftplugins |
|---|
| 41 | " - Added file type setting for .phps files |
|---|
| 42 | " - Created PDV (phpDocumentor for VIM) and added mapping (ATTENTION! BC |
|---|
| 43 | " break!) |
|---|
| 44 | " - Fixed bug with cover char mapping of "" in visual mode |
|---|
| 45 | " - Added possible alternatives for other coding standards |
|---|
| 46 | " |
|---|
| 47 | " - Replace grepprg to remove SVN results |
|---|
| 48 | " - Add mapping for VIM7 spell checks to <F5> |
|---|
| 49 | " - Added autocommand to highlight the current line in insert mode. |
|---|
| 50 | " - Added skeleton file to be read for new PHP files. |
|---|
| 51 | |
|---|
| 52 | " Source local settings |
|---|
| 53 | "source ~/.vimlocalrc |
|---|
| 54 | |
|---|
| 55 | " Colorschema |
|---|
| 56 | colorscheme inkpot |
|---|
| 57 | |
|---|
| 58 | " Set new grep command, which ignores SVN! |
|---|
| 59 | " TODO: Add this to SVN |
|---|
| 60 | set grepprg=/usr/bin/vimgrep\ $*\ /dev/null |
|---|
| 61 | |
|---|
| 62 | " Map <F5> to turn spelling on (VIM 7.0+) |
|---|
| 63 | map <F5> :setlocal spell! spelllang=en_us<cr> |
|---|
| 64 | |
|---|
| 65 | " Highlight current line in insert mode. |
|---|
| 66 | "autocmd InsertLeave * se nocul |
|---|
| 67 | "autocmd InsertEnter * se cul |
|---|
| 68 | |
|---|
| 69 | " Reads the skeleton php file |
|---|
| 70 | " Note: The normal command afterwards deletes an ugly pending line and moves |
|---|
| 71 | " the cursor to the middle of the file. |
|---|
| 72 | autocmd BufNewFile *.php 0r ~/.vim/skeleton.php | normal Gdd |
|---|
| 73 | |
|---|
| 74 | " ChangeLog |
|---|
| 75 | let g:changelog_dateformat = "%Y-%m-%d" |
|---|
| 76 | let g:changelog_username = "<Tomohiro Mitsumune>" |
|---|
| 77 | |
|---|
| 78 | " {{{ .phps files handled like .php |
|---|
| 79 | |
|---|
| 80 | au BufRead,BufNewFile *.phps set filetype=php |
|---|
| 81 | |
|---|
| 82 | " }}} |
|---|
| 83 | |
|---|
| 84 | " {{{ Settings |
|---|
| 85 | |
|---|
| 86 | if has("autocmd") && exists("+omnifunc") |
|---|
| 87 | autocmd FileType php :set omnifunc=phpcomplete#CompletePHP |
|---|
| 88 | autocmd FileType html :set omnifunc=htmlcomplete#CompleteTags |
|---|
| 89 | autocmd FileType python :set omnifunc=pythoncomplete#Complete |
|---|
| 90 | autocmd FileType javascript :set omnifunc=javascriptcomplete#CompleteJS |
|---|
| 91 | autocmd FileType xml :set omnifunc=xmlcomplete#CompleteTags |
|---|
| 92 | autocmd FileType css :set omnifunc=csscomplete#CompleteCSS |
|---|
| 93 | autocmd FileType c :set omnifunc=ccomplete#Complete |
|---|
| 94 | autocmd Filetype * |
|---|
| 95 | \ if &omnifunc == "" | |
|---|
| 96 | \ setlocal omnifunc=syntaxcomplete#Complete | |
|---|
| 97 | \ endif |
|---|
| 98 | endif |
|---|
| 99 | |
|---|
| 100 | " Use filetype plugins, e.g. for PHP |
|---|
| 101 | syntax on |
|---|
| 102 | filetype plugin on |
|---|
| 103 | |
|---|
| 104 | " Show nice info in ruler |
|---|
| 105 | set ruler |
|---|
| 106 | set laststatus=2 |
|---|
| 107 | |
|---|
| 108 | " Set standard setting for PEAR coding standards |
|---|
| 109 | set expandtab |
|---|
| 110 | set tabstop=4 |
|---|
| 111 | set softtabstop=4 |
|---|
| 112 | set shiftwidth=4 |
|---|
| 113 | |
|---|
| 114 | " Show line numbers by default |
|---|
| 115 | set nonumber |
|---|
| 116 | |
|---|
| 117 | " Enable folding by fold markers |
|---|
| 118 | set foldmethod=marker |
|---|
| 119 | |
|---|
| 120 | " Autoclose folds, when moving out of them |
|---|
| 121 | set foldclose=all |
|---|
| 122 | |
|---|
| 123 | " don`t Use incremental searching |
|---|
| 124 | "検索文字列入力時に順次対象文字列にヒットさせない |
|---|
| 125 | set noincsearch |
|---|
| 126 | |
|---|
| 127 | " Do not highlight search results |
|---|
| 128 | "検索結果文字列のハイライトを有効にしない |
|---|
| 129 | set nohlsearch |
|---|
| 130 | |
|---|
| 131 | " Jump 5 lines when running out of the screen |
|---|
| 132 | set scrolljump=5 |
|---|
| 133 | |
|---|
| 134 | " Indicate jump out of the screen when 3 lines before end of the screen |
|---|
| 135 | set scrolloff=3 |
|---|
| 136 | |
|---|
| 137 | " Repair wired terminal/vim settings |
|---|
| 138 | set backspace=start,eol,indent |
|---|
| 139 | |
|---|
| 140 | " Allow file inline modelines to provide settings |
|---|
| 141 | set modeline |
|---|
| 142 | |
|---|
| 143 | " minibufexplの設定 |
|---|
| 144 | let g:miniBufExplMapWindowNavVim = 1 |
|---|
| 145 | let g:miniBufExplSplitBelow=0 " Put new window above |
|---|
| 146 | let g:miniBufExplMapWindowNavArrows = 1 |
|---|
| 147 | let g:miniBufExplMapCTabSwitchBufs = 1 |
|---|
| 148 | let g:miniBufExplModSelTarget = 1 |
|---|
| 149 | let g:miniBufExplSplitToEdge=1 |
|---|
| 150 | |
|---|
| 151 | " Use Vim defaults instead of 100% vi compatibility |
|---|
| 152 | set nocompatible |
|---|
| 153 | |
|---|
| 154 | "スマートインデント |
|---|
| 155 | set smartindent |
|---|
| 156 | |
|---|
| 157 | "検索文字列に大文字が含まれている場合は区別して検索する |
|---|
| 158 | set smartcase |
|---|
| 159 | |
|---|
| 160 | "検索時に最後まで行ったら最初に戻る |
|---|
| 161 | set wrapscan |
|---|
| 162 | |
|---|
| 163 | "タブの左側にカーソル表示 |
|---|
| 164 | "set listchars=tab:\\ |
|---|
| 165 | set nolist |
|---|
| 166 | |
|---|
| 167 | "入力中のコマンドをステータスに表示 |
|---|
| 168 | set showcmd |
|---|
| 169 | |
|---|
| 170 | "括弧入力時の対応する括弧を表示 |
|---|
| 171 | set showmatch |
|---|
| 172 | |
|---|
| 173 | function! GetB() |
|---|
| 174 | let c = matchstr(getline('.'), '.', col('.') - 1) |
|---|
| 175 | let c = iconv(c, &enc, &fenc) |
|---|
| 176 | return String2Hex(c) |
|---|
| 177 | endfunction |
|---|
| 178 | " :help eval-examples |
|---|
| 179 | " The function Nr2Hex() returns the Hex string of a number. |
|---|
| 180 | func! Nr2Hex(nr) |
|---|
| 181 | let n = a:nr |
|---|
| 182 | let r = "" |
|---|
| 183 | while n |
|---|
| 184 | let r = '0123456789ABCDEF'[n % 16] . r |
|---|
| 185 | let n = n / 16 |
|---|
| 186 | endwhile |
|---|
| 187 | return r |
|---|
| 188 | endfunc |
|---|
| 189 | " The function String2Hex() converts each character in a string to a two |
|---|
| 190 | " character Hex string. |
|---|
| 191 | func! String2Hex(str) |
|---|
| 192 | let out = '' |
|---|
| 193 | let ix = 0 |
|---|
| 194 | while ix < strlen(a:str) |
|---|
| 195 | let out = out . Nr2Hex(char2nr(a:str[ix])) |
|---|
| 196 | let ix = ix + 1 |
|---|
| 197 | endwhile |
|---|
| 198 | return out |
|---|
| 199 | endfunc |
|---|
| 200 | |
|---|
| 201 | "ステータスラインに文字コードと改行文字を表示する |
|---|
| 202 | " set statusline=%<[%n]%m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).':'.&ff.']['.&ft.']'}\ %F%=%l,%c%V%8P |
|---|
| 203 | if winwidth(0) >= 120 |
|---|
| 204 | set statusline=%<[%n]%m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).':'.&ff.']'}%y\ %F%=[%{GetB()}]\ %l,%c%V%8P |
|---|
| 205 | else |
|---|
| 206 | set statusline=%<[%n]%m%r%h%w%{'['.(&fenc!=''?&fenc:&enc).':'.&ff.']'}%y\ %f%=[%{GetB()}]\ %l,%c%V%8P |
|---|
| 207 | endif |
|---|
| 208 | "set statusline=%{GetB()} |
|---|
| 209 | |
|---|
| 210 | "code2html |
|---|
| 211 | let html_use_css = 1 |
|---|
| 212 | |
|---|
| 213 | " コマンドライン補完するときに強化されたものを使う(参照 :help wildmenu) |
|---|
| 214 | " set wildmenu |
|---|
| 215 | " コマンドライン補間をシェルっぽく |
|---|
| 216 | set wildmode=list:longest |
|---|
| 217 | " バッファが編集中でもその他のファイルを開けるように |
|---|
| 218 | set hidden |
|---|
| 219 | " 外部のエディタで編集中のファイルが変更されたら自動で読み直す |
|---|
| 220 | set autoread |
|---|
| 221 | |
|---|
| 222 | ""set termencoding=utf-8 |
|---|
| 223 | ""set encoding=utf-8 |
|---|
| 224 | ""set fileencoding=utf-8 |
|---|
| 225 | ""set fileencodings=utf-8,cp932 |
|---|
| 226 | |
|---|
| 227 | " 文字コードの自動認識 |
|---|
| 228 | if &encoding !=# 'utf-8' |
|---|
| 229 | set encoding=japan |
|---|
| 230 | set fileencoding=japan |
|---|
| 231 | endif |
|---|
| 232 | if has('iconv') |
|---|
| 233 | let s:enc_euc = 'euc-jp' |
|---|
| 234 | let s:enc_jis = 'iso-2022-jp' |
|---|
| 235 | " iconvがeucJP-msに対応しているかをチェック |
|---|
| 236 | if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb" |
|---|
| 237 | let s:enc_euc = 'eucjp-ms' |
|---|
| 238 | let s:enc_jis = 'iso-2022-jp-3' |
|---|
| 239 | " iconvがJISX0213に対応しているかをチェック |
|---|
| 240 | elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb" |
|---|
| 241 | let s:enc_euc = 'euc-jisx0213' |
|---|
| 242 | let s:enc_jis = 'iso-2022-jp-3' |
|---|
| 243 | endif |
|---|
| 244 | " fileencodingsを構築 |
|---|
| 245 | if &encoding ==# 'utf-8' |
|---|
| 246 | let s:fileencodings_default = &fileencodings |
|---|
| 247 | if has('unix') |
|---|
| 248 | let &fileencodings = s:enc_jis .','. s:enc_euc |
|---|
| 249 | let &fileencodings = &fileencodings .','. s:fileencodings_default |
|---|
| 250 | else |
|---|
| 251 | let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932' |
|---|
| 252 | let &fileencodings = &fileencodings .','. s:fileencodings_default |
|---|
| 253 | endif |
|---|
| 254 | unlet s:fileencodings_default |
|---|
| 255 | else |
|---|
| 256 | let &fileencodings = &fileencodings .','. s:enc_jis |
|---|
| 257 | set fileencodings+=utf-8,ucs-2le,ucs-2 |
|---|
| 258 | if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$' |
|---|
| 259 | set fileencodings+=cp932 |
|---|
| 260 | set fileencodings-=euc-jp |
|---|
| 261 | set fileencodings-=euc-jisx0213 |
|---|
| 262 | set fileencodings-=eucjp-ms |
|---|
| 263 | let &encoding = s:enc_euc |
|---|
| 264 | let &fileencoding = s:enc_euc |
|---|
| 265 | else |
|---|
| 266 | let &fileencodings = &fileencodings .','. s:enc_euc |
|---|
| 267 | endif |
|---|
| 268 | endif |
|---|
| 269 | " 定数を処分 |
|---|
| 270 | unlet s:enc_euc |
|---|
| 271 | unlet s:enc_jis |
|---|
| 272 | endif |
|---|
| 273 | " 日本語を含まない場合は fileencoding に encoding を使うようにする |
|---|
| 274 | if has('autocmd') |
|---|
| 275 | function! AU_ReCheck_FENC() |
|---|
| 276 | if &fileencoding =~# 'iso-2022-jp' && search("[^\x01-\x7e]", 'n') == 0 |
|---|
| 277 | let &fileencoding=&encoding |
|---|
| 278 | endif |
|---|
| 279 | endfunction |
|---|
| 280 | autocmd BufReadPost * call AU_ReCheck_FENC() |
|---|
| 281 | endif |
|---|
| 282 | " 改行コードの自動認識 |
|---|
| 283 | set fileformats=unix,dos,mac |
|---|
| 284 | " □とか○の文字があってもカーソル位置がずれないようにする |
|---|
| 285 | if exists('&ambiwidth') |
|---|
| 286 | set ambiwidth=double |
|---|
| 287 | endif |
|---|
| 288 | |
|---|
| 289 | |
|---|
| 290 | " cvs,svnの時は文字コードをutf-8に設定 |
|---|
| 291 | autocmd FileType cvs :set fileencoding=utf-8 |
|---|
| 292 | autocmd FileType svn :set fileencoding=utf-8 |
|---|
| 293 | |
|---|
| 294 | " set tags |
|---|
| 295 | if has("autochdir") |
|---|
| 296 | set autochdir |
|---|
| 297 | set tags=tags |
|---|
| 298 | else |
|---|
| 299 | set tags=./tags,./../tags,./*/tags,./../../tags,./../../../tags,./../../../../tags,./../../../../../tags |
|---|
| 300 | endif |
|---|
| 301 | nnoremap <silent> <F8> :TlistToggle<CR> |
|---|
| 302 | set tags+=~/.vim/systags |
|---|
| 303 | set tags+=~/.vim/symfony.tags |
|---|
| 304 | set tags+=~/.vim/jquery.tags |
|---|
| 305 | |
|---|
| 306 | " command mode 時 tcsh風のキーバインドに |
|---|
| 307 | cmap <C-A> <Home> |
|---|
| 308 | cmap <C-F> <Right> |
|---|
| 309 | cmap <C-B> <Left> |
|---|
| 310 | cmap <C-D> <Delete> |
|---|
| 311 | cmap <Esc>b <S-Left> |
|---|
| 312 | cmap <Esc>f <S-Right> |
|---|
| 313 | |
|---|
| 314 | " cedit |
|---|
| 315 | set cedit=<C-O> |
|---|
| 316 | |
|---|
| 317 | "表示行単位で行移動する |
|---|
| 318 | nmap j gj |
|---|
| 319 | nmap k gk |
|---|
| 320 | vmap j gj |
|---|
| 321 | vmap k gk |
|---|
| 322 | |
|---|
| 323 | " 前回終了したカーソル行に移動 |
|---|
| 324 | autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g`\"" | endif |
|---|
| 325 | |
|---|
| 326 | ",e でそのコマンドを実行 |
|---|
| 327 | nmap ,e :execute '!' &ft ' %'<CR> |
|---|
| 328 | |
|---|
| 329 | " SeeTab |
|---|
| 330 | let g:SeeTabCtermFG="black" |
|---|
| 331 | let g:SeeTabCtermBG="red" |
|---|
| 332 | |
|---|
| 333 | " netrw-ftp |
|---|
| 334 | let g:netrw_ftp_cmd="netkit-ftp" |
|---|
| 335 | |
|---|
| 336 | " netrw-http |
|---|
| 337 | let g:netrw_http_cmd="wget -q -O" |
|---|
| 338 | |
|---|
| 339 | " YankRing.vim |
|---|
| 340 | nmap ,y :YRShow<CR> |
|---|
| 341 | |
|---|
| 342 | " html escape function |
|---|
| 343 | :function HtmlEscape() |
|---|
| 344 | silent s/&/\&/eg |
|---|
| 345 | silent s/</\</eg |
|---|
| 346 | silent s/>/\>/eg |
|---|
| 347 | :endfunction |
|---|
| 348 | |
|---|
| 349 | :function HtmlUnEscape() |
|---|
| 350 | silent s/</</eg |
|---|
| 351 | silent s/>/>/eg |
|---|
| 352 | silent s/&/\&/eg |
|---|
| 353 | :endfunction |
|---|
| 354 | |
|---|
| 355 | " 補完候補の色づけ for vim7 |
|---|
| 356 | hi Pmenu ctermbg=8 |
|---|
| 357 | hi PmenuSel ctermbg=12 |
|---|
| 358 | hi PmenuSbar ctermbg=10 |
|---|
| 359 | |
|---|
| 360 | " 256色 |
|---|
| 361 | set t_Co=256 |
|---|
| 362 | set t_Sf=[3%dm |
|---|
| 363 | set t_Sb=[4%dm |
|---|
| 364 | |
|---|
| 365 | " encoding |
|---|
| 366 | nmap ,U :set encoding=utf-8<CR> |
|---|
| 367 | nmap ,E :set encoding=euc-jp<CR> |
|---|
| 368 | nmap ,S :set encoding=cp932<CR> |
|---|
| 369 | |
|---|
| 370 | " closetag |
|---|
| 371 | "autocmd FileType html,xml,xsl,php :source ~/.vim/scripts/closetag.vim |
|---|
| 372 | |
|---|
| 373 | "Omni補完のキー割り当て変更 |
|---|
| 374 | inoremap <C-F> <C-X><C-O> |
|---|
| 375 | |
|---|
| 376 | " paste/nopaste |
|---|
| 377 | nmap ep :set paste<CR> |
|---|
| 378 | nmap enp :set nopaste<CR> |
|---|
| 379 | |
|---|
| 380 | " fuzzyfinder |
|---|
| 381 | nmap <silent> eff :FuzzyFinderFile<CR> |
|---|
| 382 | nmap <silent> efv :FuzzyFinderFavFile<CR> |
|---|
| 383 | nmap <silent> efm :FuzzyFinderMruFile<CR> |
|---|
| 384 | nmap <silent> efc :FuzzyFinderMruCmd<CR> |
|---|
| 385 | nmap <silent> efd :FuzzyFinderDir<CR> |
|---|
| 386 | nmap <silent> efa :FuzzyFinderAddFavFile<CR> |
|---|
| 387 | nmap <silent> eft :FuzzyFinderTag<CR> |
|---|
| 388 | nmap <silent> efb :FuzzyFinderBuffer<CR> |
|---|
| 389 | |
|---|
| 390 | " }}} |
|---|
| 391 | |
|---|