4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Vim]基本操作負担軽減のための最低限Leader設定

Posted at

はじめに

  • 普段利用しているエディタとは別に、日または月に数回程度vimを利用することがあります。
  • そのため、以下のような状態でも問題ありませんでした。
    • 利用は基本操作(移動・保存・終了)のみ。
    • そのため、数行あるいは空白の.vimrc
    • 複雑な操作は手入力かコピペ。
  • 今回は、そのような基本操作の更なる指負担軽減を図るため、VimのLeader機能の設定を記載します。

結果

  • 結果の.vimrcの記述を示します。
  • 以下のような設定で、基本操作(移動・保存・終了)が「Space + 各種キー」でも利用できるようになります。
" leaderをスペースへ設定
let mapleader = "\<Space>"

" 「Spaceキー + 各種キー」のようなキー操作マッピング
inoremap <Leader>jj <Esc>                         " ESCキー 
nnoremap <Leader>w :w<CR>                         " 保存
nnoremap <Leader>q :q<CR>                         " 終了
noremap <Leader>a myggVG$                         " 全選択(ノーマル)
inoremap <Leader>a <Esc>myggVG$                   " 全選択(インサート)
nnoremap <silent> <Leader>vr :new ~/.vimrc<CR>    " .vimrcを開く
nnoremap <silent> <Leader>r :source ~/.vimrc<CR>  " .vimrcの読み込み
noremap <Leader><Leader> <C-w>w                   " windowの移動
map <leader>n :call RenameFile()<cr>              " 編集中ファイルのリネーム

" リネーム関数定義
function! RenameCurrentFile()
  let old = expand('%')
  let new = input('新規ファイル名: ', old , 'file')
  if new != '' && new != old
    exec ':saveas ' . new
    exec ':silent !rm ' . old
    redraw!
  endif
endfunction

内容

Leaderとは

  • Leaderとは、複数キー操作の割り当てが可能な特別な文字列および設定のことです。
  • つまり、Vim上で独自のキーマッピング(ショートカット)を作成できます。

設定

  • 設定の際には、以下を意識しました。

    • spaceキーを起点に。
      • 「,」等、様々なキーを試して自分に最適なものを選択。
    • 高頻度のみの設定
      • 利用の上で頻度の高い操作を洗い出す。
    • 必要以上には設定しない
      • 数を増やしすぎると、キーの衝突が起きるため避ける。
      • 短い標準操作は基本設定しない。
  • 上記の結果で設定した主な内容は以下。(※基本操作に焦点を当てて設定)

    • spaceキー + jj : ESCキー
    • spaceキー + w : 保存
    • spaceキー + q : 終了
    • spaceキー + a : 全選択
    • spaceキー + n : 編集中ファイルのリネーム

参考

4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?