5
6

More than 5 years have passed since last update.

Togglable な option を便利にする

Last updated at Posted at 2014-04-19

本記事は Vim Advent Calendar 2013 の 135 日目です。
134 日目は @tyru さんによる、Vimでコマンドライン履歴を消す方法 でした。

解説

Vim の一部のオプションは bang することで toggle できるようになっています。

" ! (bang) で toggle。
" これだけ vimrc に書いても役に立ちません。
setl number!
setl wrap!

これを

" ? は現在の option 設定の表示。
" toggle 後の設定を表示する。
setl number! number?
setl wrap! wrap?

こうして

command! Numbertoggle setl number! number?
command! Wraptoggle setl wrap! wrap?

コマンド化したり

nnoremap <F2> :<C-u>Numbertoggle<CR>
nnoremap <F3> :<C-u>Wraptoggle<CR>

map しておくと便利です。F キーの F は不浄の Fです。

以上

Vim Advent Calendar 2013 135 日目の記事でした、次回 136 日目は @manga_osyo さんのVim script で関数のデフォルト引数を設定したいでした。

5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6