-
Notifications
You must be signed in to change notification settings - Fork 65
Coding Rule
ここの内容は今のところ叩き台レベルであり、今後変更される可能性がある。(TODO 早めに議論して fix できる部分から fix させていく)
Use 2 spaces.
Use the following modeline against all Vim scripts.
" vim: tabstop=2 shiftwidth=2 expandtabvital.vim はライブラリであるため、エラーの通知は例外を投げることで行う。直接 :echo などをしてはいけない。
例外を投げる場合は、vital: {module-name}: と言う prefix を付ける。
以下の機能は、複数の vital がインストールされていた場合に衝突する可能性があるため、基本的に使用してはいけない。
- ユーザー定義コマンドの定義
- キーマッピングの定義
- augroup/autocmd の定義
- グローバル変数の定義/参照
ただし、これらの定義を補助する機能を提供する目的のライブラリなどに関しては例外となる。
Always in English.
折り畳みコメント(" {{{ のようなもの) は基本的に付けない。
コマンド名・オプション名は省略してはいけない。
- Bad example:
fun ...,&tw - Good example:
function ...,&textwidth
関数名、変数名は camelCase ではなく snake_case にする。
- Bad example:
thisIsAPen() - Good example:
this_is_a_pen()
:function コマンドには必ず ! を付ける。
" Bad
function s:hoge() abort
endfunction
" Good
function! s:hoge() abort
endfunction関数には必ず abort フラグを付ける。
" Bad
function! s:hoge()
endfunction
" Good
function! s:hoge() abort
endfunction- 関数定義の間に一行の空行を入れる。
" Bad
function! s:hoge() abort
endfunction
function! s:foo() abort
endfunction
" Good
function! s:hoge() abort
endfunction
" Insert an empty line between functions
function! s:foo() abort
endfunction-
functionの直後、endfunctionの直前に空行を入れない。
" Bad
function! s:hoge() abort
let value = 10
endfunction
" Good
function! s:hoge() abort
let value = 10
endfunctionDon't add l: prefix against local variables.
Exceptions when you must use l: are
- buffer localなoptionの値を参照するとき (Example:
&l:include) -
v:と混同する名前の変数を使用するとき (Example:let l:count = 10)
具体的には以下の5つである。
counterrmsgshell_errorthis_sessionversion
これらの名前の変数は、スコープを明示しない場合は常に v: の変数が参照される。
混乱を避けるため、count などの変数名を参照する場合は必ず l:count か v:count を使用し、count という変数名を直接参照してはいけない。
特に v:count、v:shell_error、v:version は読み込み専用のため、代入するだけでエラーになる。
function! s:func() abort
" Good
" ローカル変数で count を使用する場合は
" l: を付属させる
let l:count = 10
" Bad
" count を参照する場合は v: か l: を付属させる
" この場合は v:count が参照される
echo count
" Good
" l:count を参照する
echo l:count
" Good
" v:count を参照する
echo v:count
endfunction必然性があるときのみ提供し、そうでないときはベタな関数を提供する (どうせ名前空間があるので)。
Use has('win32').
Do not use something like has('win16') || has('win32') || has('win64') || has('win95'), because
- win32 covers win64; when
has('win32') == 1it's guaranteed tohas('win64') == 1. - win16 and win95 no longer exist; they've been removed in the past.