takashi kono's blog

コーヒーとキーボードと共に何かを記録していくブログ

my vimrc

my vimrc

I want to recording my vimrc here.
I don't want to add comments.

I would like to update my vimrc!

" Configuration file for vim
set modelines=0     " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible    " Use Vim defaults instead of 100% vi compatibility
set backspace=2     " more powerful backspacing

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup nobackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup nobackup

" Basic settings

" タイトルをバッファ名に変更しない
set notitle
set shortmess+=I

" Too fast connect to the tarminal
set ttyfast

" Use 256 colors at the tarminal
set t_Co=256

if has ("viminfo")
  " フォールド設定(未使用)
  " set foldmethod=indent
  set foldmethod=manual
  " set foldopen=all
  " set foldclose=all
endif

" 複数ファイルの編集を可能にする
set hidden

" 内容が変更されたら自動的に再読み込み
set autoread

" Swapを作るまでの時間ms
set updatetime=0

" Unicodeで行末が変になる問題を解決
set ambiwidth=double

" カーソルを常に画面の中央に。
set scrolloff=1000

" C-vの矩形選択で行末より後ろもカーソルを置ける
set virtualedit=block

" コマンド、検索パターンを50まで保存
set history=100

" ------ SEARCH -------
" インクリメンタルサーチを有効に
set incsearch

" 大文字小文字を区別しない
set ignorecase

" 大文字で検索されたら対象を大文字限定にする
set smartcase

" 行末まで検索したら行頭に戻る
set wrapscan

" ----- Format -----
" 自動インデントを有効に
set smartindent
set autoindent

" フォーマット揃えをコメント以外有効にする
set formatoptions-=c

" 括弧の対応をハイライト
set showmatch

" ターミナルの上から貼り付けを許可
" set paste

set shiftwidth=4
set softtabstop=4
set expandtab
set autoindent
set smartindent

augroup fileTypeIndent
  autocmd!
  autocmd BufNewFile,BufRead *.py setlocal tabstop=4 softtabstop=4 shiftwidth=4
  autocmd BufNewFile,BufRead *.html setlocal tabstop=4 softtabstop=4 shiftwidth=4
  autocmd BufNewFile,BufRead *.rb setlocal tabstop=2 softtabstop=2 shiftwidth=2
  autocmd BufNewFile,BufRead *.erb setlocal tabstop=2 softtabstop=2 shiftwidth=2
augroup END

" ----- Look&Feel -----
" TAB可視化
set list
set listchars=tab:>_,trail:-,eol:$
" extends:>>,precedes:<<,nb:%,

" 検索結果をハイライト
set hlsearch

" ルーラー、番号
set ruler
set number

" コマンドラインの高さ
set cmdheight=2

" カーソルラインを表示する
"set cursorline

" ウインドウタイトルを設定する
set title

"自動文字数カウント
augroup WordCount
    autocmd!
    autocmd BufWinEnter,InsertLeave,CursorHold * call WordCount('char')
augroup END
let s:WordCountStr = ''
let s:WordCountDict = {'word': 2, 'char': 3, 'byte': 4}
function! WordCount(...)
    if a:0 == 0
        return s:WordCountStr
    endif
    let cidx = 3
    silent! let cidx = s:WordCountDict[a:1]
    let s:WordCountStr = ''
    let s:saved_status = v:statusmsg
    exec "silent normal! g\<c-g>"
    if v:statusmsg !~ '^--'
        let str = ''
        silent! let str = split(v:statusmsg, ';')[cidx]
        let cur = str2nr(matchstr(str, '\d\+'))
        let end = str2nr(matchstr(str, '\d\+\s*$'))
        if a:1 == 'char'
            " ここで(改行コード数*改行コードサイズ)を'g<C-g>'の文字数から引く
            let cr = &ff == 'dos' ? 2 : 1
            let cur -= cr * (line('.') - 1)
            let end -= cr * line('$')
        endif
        let s:WordCountStr = printf('%d/%d', cur, end)
    endif
    let v:statusmsg = s:saved_status
    return s:WordCountStr
endfunction


" ステータスラインにコマンドを表示
set showcmd
" ステータスラインを常に表示
set laststatus=2
" ファイルナンバー表示
set statusline=[%n]
" ホスト名表示
set statusline+=%{matchstr(hostname(),'__w__+')}@
" ファイル名表示
set statusline+=%<%F
" 変更チェックの表示
set statusline+=%m
" 読み込み専用かどうか表示
set statusline+=%r
" ヘルプページなら[HELP]と表示
set statusline+=%h
" プレビューウィンドウなら[Preview]と表示
set statusline+=%w
" ファイルフォーマット表示
set statusline+=[%{&fileformat}]
" 文字コード表示
set statusline+=[%{has('multi_byte')&&\&fileencoding!=''?&fileencoding:&encoding}]
" ファイルタイプ表示
set statusline+=%y
" ここからツールバー右側
set statusline+=%=
" skk.vimの状態
set statusline+=%{exists('*SkkGetModeStr')?SkkGetModeStr():''}
" 文字バイト数/カラム番号
set statusline+=[%{col('.')-1}=ASCII=%B,HEX=%c
" 現在文字列/全体列表示
set statusline+=[C=%c/%{col('$')-1}]
" 現在文字行/全体文字行
set statusline+=[L=%l/%L]
" 現在のファイルの文字数をカウント
set statusline+=[WC=%{exists('*WordCount')?WordCount():[]}]
" 現在行が全体行の何%目か表示
set statusline+=[%p%%]

"-------エンコード------
"エンコード設定
if has('unix')
    set fileformat=unix
    set fileformats=unix,dos,mac
    set fileencoding=utf-8
    set fileencodings=utf-8,iso-2022-jp,cp932,euc-jp
    set termencoding=
elseif has('win32')
    set fileformat=dos
    set fileformats=dos,unix,mac
    set fileencoding=utf-8
    set fileencodings=iso-2022-jp,utf-8,euc-jp,cp932
    set termencoding=
endif

"ファイルタイプに応じて挙動,色を変える
syntax on
filetype plugin on
filetype indent on

" ----- key setting -----
" nmap <UP> k
" nmap <DOWN> j
" vmap <UP> k
" vmap <DOWN> j

" ほかのvimにviminfoを送る
" http://nanasi.jp/articles/howto/editing/rviminfo.html
nmap ,vw :vw<CR>
nmap ,vr :vr<CR>

" 保存
" map jj :w<CR>

" ESC
inoremap jj <ESC>

" 括弧を補完
inoremap ( ()<left>
inoremap [ []<left>
inoremap { {}<left>
inoremap < <><left>

" 挿入モードでのカーソル移動
inoremap <C-j> <Down>
inoremap <C-k> <UP>
inoremap <C-h> <Left>
inoremap <C-l> <Right>

" シングルコーテーション補完
inoremap ' '' <left>

" yanktmpの設定
" vim to vim でコピペ出きるようになる。
" map <silent> sy :call YanktmpYank()<CR>
" map <silent> sp :call YanktmpPaste_p()<CR>
" map <silent> sP :call YanktmpPaste_P()<CR>
" if has("win32")
"       let g:yanktmp_file = TEMP. '/vimyanktmp'
" end