OverleafでVimiumとVimキーバインドが衝突して使えない問題
はじめに
数時間前にOverleafでVimキーバインドが使えることを知った。 基本的に日本語編集とVimのキーバインドの相性は良くないが、コピーとか矩形選択は便利なので使おうとするもノーマルモードに戻れない。 調べてみるとChromeの拡張機能Vimiumと衝突してるみたい。
VimiumをOverleaf上で使用できなくして、キーバインドの設定を行ったら快適になったのでメモ。
Overleaf上でVimiumを無効化
- サイトを訪れる
- Vimiumアイコンをクリックし、以下の画像の状態で保存
以上。 これでOverleaf上のプロジェクトで正常にVimキーバインドが使用できる。
.vimrc的な設定
普段から使っているキーバインドはそのまま利用したい。例えばjjでEscとか。
tampermonkyという拡張機能を利用する。
// ==UserScript== // @name Overleaf Editor Custom VIM Keybindings // @namespace http://tampermonkey.net/ // @version 0.1 // @match https://www.overleaf.com/project/* // @grant none // ==/UserScript== (function() { 'use strict'; // poll until editor is loaded const retry = setInterval(() => { if (window._debug_editors === undefined) return clearInterval(retry) // get current editor instance const editor = window._debug_editors[window._debug_editors.length -1] // vim keyboard plugin const vimKeyboard = window.ace.require("ace/keyboard/vim") // add custom keybindings - insert mode applies on insert vimKeyboard.Vim.map("jj", "<Esc>l", "insert") // set the modified keyboard handler for editor editor.setKeyboardHandler(vimKeyboard.handler) console.log("Custom key bindings applied") }, 100) })();
Tampermonkyが正常に動作すれば、上記のコードがOverleafを開いた際に自動で実行されjjでEscができるようになる。