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?

vimで今編集しているファイルを1キーで実行する

0
Posted at

表題の通りだ

pythonとかjs/ts使ってて、それを実行したいがために下記のようにするのが面倒という事だ。

!python %

これの問題点は、タイプするのが面倒なうえに、そのログも残らないことだ。そこでこういうのがある。

term python %

これで新しいターミナルをvim上で開いて実行してくれる。故に、ログも残るし良い感じ。しかし、ここでよろしくない事がある。それは結局キーストロークが多くて怠い事だ。

酷い事だ、頭の震えがとまらない。

キーストロークを減らそう

だって面倒くさいし。

let s:filedict = {'R': 'Rscript', 'typescript': 'deno run'}

function s:terminal(word)
  call execute((has('nvim')?'term ':'term ++curwin').a:word)
  set nonumber
endfunction

function s:run()
    echomsg 'running '.expand('%')
    if s:filedict->has_key(&filetype)
        call s:terminal(s:filedict[&filetype].' %')
    else
        call s:terminal(&filetype.' %')
    endif
    call timer_start(100, {->execute('norm G')})
endfunction
command! Run :call s:run()
nnoremap <F12> :Run<CR>

これでF12を押すと別バッファで実行してくれるぞ!
キーバインドとかの設定は…まぁ、適当にするといいと思います。

細かい事

  • ここで、timer_startをしているのはターミナルの最後をおいかけてほしいからです。
  • s:terminalをしている理由はvimとneovimで同じ挙動をしてほしいからです。
  • なんならmakeを呼ぶとかのキーを設定してもいいとおもう。
  • 例えば処理がおわった時に「処理がおわったのだ」って言わせる事もいいと思う。

感想

QOLは上った

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?