あなたが希望textwidthを設定するCursorMoved
とCursorMovedI
オートコマンドを使用することができます行に基づいて(またはその他の設定)カーソルが現在オンである:ネストされた自動コマンドは、それはかなりファンキーに見えるようものの、let &l:textwidth = line('.') == 1 ? 50 : 72
:
augroup gitsetup
autocmd!
" Only set these commands up for git commits
autocmd FileType gitcommit
\ autocmd CursorMoved,CursorMovedI *
\ let &l:textwidth = line('.') == 1 ? 50 : 72
augroup end
基本的なロジックは単純です。スクリプトローカル関数(fun! s:setup_git()
)にその一部を抽出して、それを呼び出すこともできます。
setlocal
の構文はsetlocal
と同じですが(ただし、setlocal
では右側のような式は使用できません)、単純な文字列のみです。
いくつかの関連質問:
デフォルトgitcommit.vim
構文ファイルが既に50個の文字の後の最初の行をハイライト表示を停止していることに注意してください。 /usr/share/vim/vim80/syntax/gitcommit.vim
から:それ何のハイライトが適用されていない後
syn match gitcommitSummary "^.\{0,50\}" contained containedin=gitcommitFirstLine nextgroup=gitcommitOverflow [email protected]
[..]
hi def link gitcommitSummary Keyword
のみ最初の50行は、「キーワード」(私のカラースキームでライトブラウン)として強調されます。
は、Ifもあります。それは少しも独断だためか、コメントアウトされます
syn match gitcommitOverflow ".*" contained [email protected]
[..]
"hi def link gitcommitOverflow Error
お知らせ方法。あなたは簡単にかかわらず、あなたのvimrcにこれを追加することができます:50の文字は(あなたがしたい場合は、また別のハイライトグループを選択することで、目立たない色を使用することができます)、エラーとして表示した後、すべてを行います
augroup gitsetup
autocmd!
" Only set these commands up for git commits
autocmd FileType gitcommit
\ hi def link gitcommitOverflow Error
\| autocmd CursorMoved,CursorMovedI *
\ let &l:textwidth = line('.') == 1 ? 50 : 72
augroup end
を。
偉大な答え、私は前に '&l:'トリックを見たことがない、それは役に立つだろう! – nickspoon