vimrc style guide

English

Table of Content

augroup & autocmd

You should use autocmd with augroup and make sure to reset autocmd to make relodable vimrc

Bad

autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

Good

augroup MyVimrc
    autocmd!
    autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END

該当ヘルプ

map & noremap

You should differenciate map and noremap. {rhs} defined with :map will be remapped but not with :noremap command.

Bad

imap <C-f> <Left>

Good

inoremap <C-f> <Left>

該当ヘルプ


日本語

augroup & autocmd の使い方

autocmd は augroup と一緒に使い, 定義するときは autocmd! で定義されたものを一旦リセットしましょう.

Bad

autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif

Good

augroup MyVimrc
    autocmd!
    autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
augroup END

該当ヘルプ

map & noremap

mapnoremap は区別して使用するべきです. :mapで定義された {rhs} は再帰的にマップが適用され, :noremap ではされません。

Bad

imap <C-f> <Left>

Good

inoremap <C-f> <Left>

該当ヘルプ