久しぶりに tmux, nvim, VSCode の設定やショートカットキーなどを整理したり、思い出したりしたいと思います。 Windows11 で WSL2 の ArchLinux を使っています。
tmux
設定内容
キーバインドのメモ
Ctrl+s H(J, K, L)で pane リサイズShift+left(up, down, right)で pane リサイズCtrl+s left(up, down, right)で pane 入替Ctrl+h(j, k, l)でアクティブな pane を移動
コピー&ペースト
Ctrl+yでコピーモードに入る- vim と同様の操作でコピー対象を選択して、
yでコピー。
nvim
設定内容
とりあえず、基本っぽいやつまで忘れましたので、思い出します。色々プラグイン設定してもどんどん忘れていくので、なるべく標準的機能でできるようにしようと思いました。。
キーバインドのメモ
vim-easymotion
<Space>s (探したい文字)で検索できる
vim-surround
ds(で囲っている()を削除できるcs([で囲っている()を[]に変更できるysw(で単語を()で囲えるwは motionyswt + h2で<h2>タグで囲えるtは html タグ
- Visual mode のときに
S(で()で囲える
参考: vim-surround
参考: vim-surround で vimmer への道を極めよう
複数行の一括編集
Ctrl+vで 1 文字を Visual mode で選択して、そのままjを押せば下の行の同じ場所の文字も選択できるIで挿入モードになる。- 各行の行末に挿入するというのも簡単にできる。
Ctrl+v>3j>$>Aで各行末への挿入モードになる。
選択範囲をヤンクした文字列と置換
- Visual mode で置換したい文字列を選択して、
pを押すと、ヤンクした文字列と置換される。
VSCode
下記設定内容で自分的にはかなり便利になりました。vim のキーバインドで VSCode のどんなコマンドでも実行できるので、工夫次第でさらに便利にできるかもなあと思いました。
設定内容
//VIM
"vim.vimrc.enable": true,
"vim.enableNeovim": true,
"vim.autoSwitchInputMethod.enable": true,
"vim.camelCaseMotion.enable": true,
"vim.changeWordIncludesWhitespace": true,
"vim.commandLineModeKeyBindings": [],
"vim.easymotion": true,
"vim.highlightedyank.enable": true,
"vim.hlsearch": true,
"vim.normalModeKeyBindings": [
{
"before": ["s", "s"],
"commands": [":split"]
},
{
"before": ["s", "v"],
"commands": [":vsplit"]
},
{
"before": ["s", "q"],
"commands": [":q"]
},
{
"before": ["f"],
"after": ["<Leader>", "<Leader>", "s"]
},
{
"before": ["<Leader>", "a"],
"commands": [{ "command": "bookmarks.listFromAllFiles" }]
},
{
"before": ["<Leader>", "b"],
"commands": [{ "command": "bookmarks.toggle" }]
},
{
"before": ["<Leader>", "d"],
"commands": [{ "command": "editor.action.revealDefinition" }]
},
{
"before": ["<Leader>", "e"],
"commands": [{ "command": "workbench.view.explorer" }]
},
{
"before": ["<Leader>", "f"],
"commands": [{ "command": "editor.action.formatDocument" }]
},
{
"before": ["<Leader>", "g"],
"commands": [{ "command": "workbench.view.scm" }]
},
{
"before": ["<Leader>", "h"],
"commands": [{ "command": "editor.action.marker.nextInFiles" }]
},
{
"before": ["<Leader>", "<Leader>", "g"],
"commands": [{ "command": "git-graph.view" }]
},
{
"before": ["<Leader>", "r"],
"commands": [{ "command": "workbench.view.search" }]
},
{
"before": ["<Leader>", "s"],
"commands": [{ "command": "workbench.action.toggleSidebarVisibility" }]
},
{
"before": ["<Leader>", ";"],
"commands": [{ "command": "workbench.action.showCommands" }]
},
],
"vim.visualModeKeyBindings": [
{
"before": ["<Leader>", "t"],
"commands": [{ "command": "translates.translates" }]
},
],
"vim.replaceWithRegister": true,
"vim.scroll": 5,
"vim.foldfix": true,
"vim.gdefault": true,
"vim.neovimUseConfigFile": true,
"vim.showMarksInGutter": true,
"vim.targets.enable": true,
"vim.visualstar": true,
"vim.history": 100,
"vim.statusBarColorControl": true,
"vim.useSystemClipboard": true,
"vim.vimrc.path": "$HOME/.vimrc",
"vim.leader": "<Space>",
"vim.statusBarColors.commandlineinprogress": "#090",
"vim.statusBarColors.insert": "#09c",
"vim.statusBarColors.normal": "#609",
"vim.statusBarColors.replace": "#f90",
"vim.statusBarColors.searchinprogressmode": "#070",
"vim.statusBarColors.surroundinputmode": "#990",
"vim.statusBarColors.visual": "#940",
"vim.statusBarColors.visualblock": "#930",
"vim.statusBarColors.visualline": "#950",
"""""""""""""""""""""""""""""" " Keymap設定 """""""""""""""""""""""""""""" nnoremap ; : nnoremap : ; nnoremap j gj nnoremap k gk nnoremap gj j nnoremap gk k nnoremap <Space>h ^ nnoremap <Space>l $ cnoremap <Space>j $<CR> nnoremap <Space>w :w<CR> nnoremap <Space>q :q<CR> nnoremap <Esc><Esc> :nohlsearch<CR> inoremap jj <Esc> nnoremap ZZ <Nop> nnoremap ZQ <Nop> nnoremap Q <Nop> """""""""""""""""""""""""""""" " 画面分割・タブページの設定 """""""""""""""""""""""""""""" noremap s <Nop> nnoremap sj <C-w>j nnoremap sk <C-w>k nnoremap sl <C-w>l nnoremap sh <C-w>h nnoremap sJ <C-w>J nnoremap sK <C-w>K nnoremap sL <C-w>L nnoremap sH <C-w>H nnoremap sn gt nnoremap sp gT nnoremap sr <C-w>r nnoremap s= <C-w>= nnoremap sw <C-w>w nnoremap so <C-w>_<C-w>| nnoremap sO <C-w>= nnoremap sN :<C-u>bn<CR> nnoremap sP :<C-u>bp<CR> nnoremap st :<C-u>tabnew<CR> nnoremap sT :<C-u>Unite tab<CR> nnoremap ss :<C-u>sp<CR> nnoremap sv :<C-u>vs<CR> nnoremap sq :<C-u>q<CR> nnoremap sQ :<C-u>bd<CR> nnoremap sb :<C-u>Unite buffer_tab -buffer-name=file<CR> nnoremap sB :<C-u>Unite buffer -buffer-name=file<CR>
キーバインドのメモ
ターミナルの表示・非表示・拡大表示
Ctrl+iでターミナルが拡大表示される。Ctrl+tでターミナルの表示・非表示がトグルされる。
ターミナルの分割・移動
tmux を使います。
Ctrl+s s,Ctrl+s vで分割します。Ctrl+j,Ctrl+h,Ctrl+lを使って移動します。上下はCtrl+jを使います。
vim-easymotion
f (探したい文字)で検索できる
引数を 1 つ削除
daaで delete a argument ということで、引数を 1 つ削除できる。
コピー&ペースト
これ true にしたら、VSCode の Vim 操作でヤンクしたらクリップボードで使えた。うれしい。
"vim.useSystemClipboard": true
画面分割
ssで水平分割, svで垂直分割
別画面で開く
ディレクトリツリー(Explorer)から別画面で開くには、Ctrl+Enter
ディレクトリツリーでディレクトリ・ファイルの作成・削除
下記を追加した。aでファイル追加。fでディレクトリ追加。rでリネーム。dで削除。
{
"key": "a",
"command": "explorer.newFile",
"when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
},
{
"key": "f",
"command": "explorer.newFolder",
"when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
},
{
"key": "r",
"command": "renameFile",
"when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
},
{
"key": "d",
"command": "deleteFile",
"when": "explorerViewletFocus && explorerViewletVisible && !inputFocus"
}
サイドバーの表示・非表示トグル
Ctrl+sでサイドバーの表示・非表示のトグル<Space>eでディレクトリツリー(Explorer)の表示<Space>gで Source Control(git 操作)の表示<Space>rで検索・置換の表示
エディタのタブの移動
snで右のタブに移動,spで左のタブに移動Ctrl+Tabだとタブの一覧が表示されて選べる
ノーマルモードに戻るときに IME をオフにする
- zenhanというのを使うとよいらしい。
- ただ、wsl2 の場合、下記が setting.json に書いても動かなかった。
"vim.autoSwitchInputMethod.defaultIM": "0", "vim.autoSwitchInputMethod.obtainIMCmd": "C:\\users\\foo\\bin\\zenhan.exe", "vim.autoSwitchInputMethod.switchIMCmd": "C:\\users\\foo\\bin\\zenhan.exe 0",
そこで、vimmer-ahkというのを使って自動で OFF になるようにしました。
フォーマット
<Space>f
エラー・警告の表示
ghでポップアップ表示<Space>hで詳しく表示
お気に入り
- vscode-bookmarksを入れています。
<Space>bで Bookmark を toggle。<Space>aで全ファイルの Bookmarks 一覧を表示。
翻訳
- Google Translateというのを入れています。
Ctrl+Shift+tで選択中の文字列を翻訳して、左下とステータスバーに表示します。<Space>tでも翻訳できます。- ※コメントの場合や複数行の場合うまく動かないかも。
コマンドパレット
<Space>;Ctrl+Shift+p
補完の競合の解消
とりあえず Tabnine を無効化してみよう
画面サイズ調整
これはどうもマウスでやる必要がありそう。。