.vimrc
"
" filename : ~/.vimrc
" filetype : config
" gisturl : https://gist.githubusercontent.com/nullpot/49aed5c1d58515802799/raw
"
" vimのvi互換モードを無効にする
set nocompatible
" 行番号を表示
set number
" 自動インデント
" set autoindent
" バックスペースキーの挙動を有効に
set backspace=indent,eol,start
" C言語の構文を読み取って自動インデント
" set smartindent
" タブ幅をスペース4つ分に
set tabstop=4
" 自動インデントの幅
set shiftwidth=4
" コードの色分け
syntax on
" 構文強調
syntax enable
" 閉括弧が入力された時、対応する括弧を強調する
set showmatch
" 検索時に最後まで行ったら最初に戻る
set wrapscan
" 閉括弧が入力された時、対応する括弧を強調する
set showmatch
" 検索結果のハイライトをEsc連打でクリアする
nnoremap <ESC><ESC> :nohlsearch<CR>
" 全角スペース・行末のスペース・タブの可視化
if has("syntax")
syntax on
" PODバグ対策
syn sync fromstart
function! ActivateInvisibleIndicator()
" 下の行の" "は全角スペース
syntax match InvisibleJISX0208Space " " display containedin=ALL
highlight InvisibleJISX0208Space term=underline ctermbg=Blue guibg=darkgray gui=underline
"syntax match InvisibleTrailedSpace "[ \t]$" display containedin=ALL
"highlight InvisibleTrailedSpace term=underline ctermbg=Red guibg=NONE gui=undercurl guisp=darkorange
"syntax match InvisibleTab "\t" display containedin=ALL
"highlight InvisibleTab term=underline ctermbg=white gui=undercurl guisp=darkslategray
endfunction
augroup invisible
autocmd! invisible
autocmd BufNew,BufRead * call ActivateInvisibleIndicator()
augroup END
endif
" 文字コードの自動認識
if &encoding !=# 'utf-8'
set encoding=japan
set fileencoding=japan
endif
if has('iconv')
let s:enc_euc = 'euc-jp'
let s:enc_jis = 'iso-2022-jp'
" iconvがeucJP-msに対応しているかをチェック
if iconv("\x87\x64\x87\x6a", 'cp932', 'eucjp-ms') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'eucjp-ms'
let s:enc_jis = 'iso-2022-jp-3'
" iconvがJISX0213に対応しているかをチェック
elseif iconv("\x87\x64\x87\x6a", 'cp932', 'euc-jisx0213') ==# "\xad\xc5\xad\xcb"
let s:enc_euc = 'euc-jisx0213'
let s:enc_jis = 'iso-2022-jp-3'
endif
" fileencodingsを構築
if &encoding ==# 'utf-8'
let s:fileencodings_default = &fileencodings
let &fileencodings = s:enc_jis .','. s:enc_euc .',cp932'
let &fileencodings = &fileencodings .','. s:fileencodings_default
unlet s:fileencodings_default
else
let &fileencodings = &fileencodings .','. s:enc_jis
set fileencodings+=utf-8,ucs-2le,ucs-2
if &encoding =~# '^\(euc-jp\|euc-jisx0213\|eucjp-ms\)$'
set fileencodings+=cp932
set fileencodings-=euc-jp
set fileencodings-=euc-jisx0213
set fileencodings-=eucjp-ms
let &encoding = s:enc_euc
let &fileencoding = s:enc_euc
else
let &fileencodings = &fileencodings .','. s:enc_euc
endif
endif
" 定数を処分
unlet s:enc_euc
unlet s:enc_jis
endif
" 改行コードの自動認識
set fileformats=unix,dos,mac
" □とか○の文字があってもカーソル位置がずれないようにする
if exists('&ambiwidth')
set ambiwidth=double
endif