0
0

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.

VSCode+VimバインディングでEsc2度押しキーマップ

Last updated at Posted at 2021-07-06

概要と目的

VSCode+Vimエステンション(vscodevim)で利用しています。

Vimをターミナル利用する際は、検索文字列をハイライト、ESC2度押しでハイライト解除するように設定しています。

.vimrc
set hlsearch
nmap <Esc><Esc> :nohlsearch<CR><Esc>

VSCodeで同じキーマップにする方法がわからず、仕方なくイチイチ :nohl としていたのですが、設定方法がわかったのでメモします。

環境

  • Windows10
  • WSL2
  • Ubuntu 20.04.2 LTS
  • Visual Studio Code 1.57.1
  • vscodevim 1.21.4

設定

Ubuntu上のホームディレクトリへ .vimrc.vscode を下記内容で作成します。

/home/user/.vimrc.vscode
nmap <Esc><Esc> :nohlsearch<CR><Esc>

Ubuntu on WSL上で、Windowsから上記ファイルを参照するためのパスを取得します
最後の \\wsl$\<ubuntuへのパス>\home\user 部分を控えます

$ pwd
/home/user
$ wslpath -w .
\\wsl$\<ubuntuへのパス>\home\user

VSCodeの設定へ下記記述します。
パス部分は バックスラッシュ\ を2重に表記します(エスケープのため。見づらいですが)
パス末尾へ上記設定した .vimrc.vscode を記述し、ファイルを示すパスにします

settings.json
{...
    "vim.vimrc.enable": true,
    "vim.vimrc.path": "\\\\wsl$\\<ubuntuへのパス>\\home\\user\\.vimrc.vscode"
}

以上でESC 2度押しで:nohlsearch が動作します。

アレンジ

ターミナルで利用している .vimrc をそのまま使う

普段ターミナルでvimの設定している人はこれでもいいかもしれません。
私はそれでも動作しています。が、vscodevimの vimrc読み込み機能がどこまで読み込むのか把握しておらず、安全そうな分離する方法を紹介しました。

設定ファイルをWindows管理下のディレクトリへ配置する

WSL使っていない場合は普通のディレクトリへ設定ファイルを配置しても大丈夫です。むしろそっちが普通かもしれません。
c:\\Users\\user\\Desktop\\vimrc とか

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?