QfixHowmを使いたい
-
VIMとVSCodeを行ったり来たり移動する
を書いてから早半年、やっぱりVSCodeからQfixHowmを使いたい
- よくよく考えると、QfixHowmルールで新規メモが作りたい
- 調べるとVS CodeでShell実行できる
- qfixhowmのソースを見ると、call qfixmemo#EditNew()を呼べばよさげ
ツール
検証
- vim起動Optionでqfixhowmを叩く
vim -c "call qfixmemo#EditNew()"
VIM側
- いけそうなので、前回記事を使いまわし「保存->閉じる->VSCODEオープン」をするVimScript準備
- (qfixhowmで開いたあと、保存することでVIMを閉じたいだけです。)
"open vscode"{{{
if has('win32')
nnoremap <silent> <leader>v :<c-u>call <SID>OpenVSCode()<CR>
function! s:OpenVSCode()
" target file
let l:targetfile = expand("%:p")
let l:lastfolderid = strridx(targetfile,"/")
let l:targetfolder = l:targetfile[0:l:lastfolderid]
" command line
"let l:cmd = '!code ' . l:targetfolder
let l:cmd = '!code ' . l:targetfile
silent execute 'write'
silent execute 'quit'
silent execute l:cmd
endfunction
command! -nargs=0 OpenVS call s:OpenVSCode()
endif
"}}}
VS Code側
- 参考:Visual Studio Codeでキーボードショートカットに外部コマンドを割り当てる
- Ctrl+Shift+p -> Task:Configure Task ->tasks.json -> Other
- VIM起動optionは複数記載可能なので、それを利用してScript側のOpenVSまでを呼び出す
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "qfixNewMemo",
"type": "shell",
"command": "vim",
"args": ["-c call qfixmemo#EditNew()","-c w","-c OpenVS"]
}
]
}
VS Codeショートカット
- 作成したTaskをショートカット登録
// Place your key bindings in this file to override the defaults
[
{
"key": "Ctrl+n",
"command": "workbench.action.tasks.runTask",
"args": "qfixNewMemo",
}
]