vimの便利機能

2013-04-10#vim

入力補完

バッファ

nnoremap <Tab> :bnext<CR>
nnoremap <S-Tab> :bprevious<CR>
nnoremap <Leader>d :bdelete<CR>

タブ

nnoremap <Leader>t :tabnew<CR>
nnoremap <Leader>n :tabnext<CR>
nnoremap <Leader>p :tabprev<CR>

コマンド定義

command! Indent2 :setlocal tabstop=2 shiftwidth=2
command! Indent4 :setlocal tabstop=4 shiftwidth=4
command! ToSjis :e ++enc=sjis<CR>

abbreviate

abbreviate #i #include
abbreviate #b / ****************************
" abbreviate <誤> <正>
abbreviate abbriviate abbreviate
abbreviate recieve receive
" .vim/abbreviate.vim
abbreviate abbriviate abbreviate
abbreviate recieve receive

" .vimrc
source ~/.vim/abbreviate.vim

filetype毎の設定ファイル

.vim
|- ftdetect
    |- filetype.vim
|- ftplugin
    |- javascript.vim
    |- make.vim
    |- ruby.vim
.vimrc
" .vim/ftplugin/make.vim
setlocal noexpandtab
setlocal tabstop=8
setlocal shiftwidth=8

filetypeの指定

.vim
|- ftdetect
    |- filetype.vim
.vimrc
" .vim/ftdetect/filetype.vim

autocmd BufRead,BufNewFile Gemfile setfiletype ruby
autocmd BufRead,BufNewFile Guardfile setfiletype ruby
autocmd BufRead,BufNewFile *.rabl setfiletype ruby
autocmd BufRead,BufNewFile *.jbuilder setfiletype ruby
autocmd BufRead,BufNewFile *.ru setfiletype ruby

以上の設定はすべて僕のdotfilesに書いてあるので参考にしてみてください。

読み返してみると、その筋の方に怒られそうな気がしてきた…(´・ω・`)