Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
terminal-api について
Search
tennashi
May 15, 2019
Programming
2
1.7k
terminal-api について
tennashi
May 15, 2019
Tweet
Share
More Decks by tennashi
See All by tennashi
続 terminal-api について
tennashi
2
690
Other Decks in Programming
See All in Programming
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
3
430
Nuxt Server Components
wattanx
0
150
見せてもらおうか、 OpenSearchの性能とやらを!
shunta27
1
150
コードレビューをしない選択 #でぃーぷらすトウキョウ
kajitack
3
1.2k
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1.3k
S3ストレージクラスの「見える」「ある」「使える」は全部違う ─ 体験から見た、仕様の深淵を覗く
ya_ma23
0
1.2k
PHP でエミュレータを自作して Ubuntu を動かそう
m3m0r7
PRO
2
150
Rethinking API Platform Filters
vinceamstoutz
0
2.3k
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
240
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
480
Claude Code Skill入門
mayahoney
0
440
ファインチューニングせずメインコンペを解く方法
pokutuna
0
210
Featured
See All Featured
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
10k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
Rails Girls Zürich Keynote
gr2m
96
14k
The agentic SEO stack - context over prompts
schlessera
0
720
Everyday Curiosity
cassininazir
0
180
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Designing for humans not robots
tammielis
254
26k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
160
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
490
Designing for Performance
lara
611
70k
Agile that works and the tools we love
rasmusluckow
331
21k
Transcript
terminal-api について Gollira.vim #4
自己紹介 職業プログラマ歴: 半年強 Vim歴: 6年くらい 普段は Go/TypeScript(Angular) を書いている その前はネットワークエンジニアをしていた GitHub:
@tennashi Twitter: @tnnsh1
今日のお話
terminal mode Vim 8.0 から追加された Vim から terminal を使える mode
VS Code とかでもターミナルが使えますが同じようなことが vim でも できると思っていただければ Neovim でも使える(実装されたのは neovim が先)が使い勝手が微妙に 異なるので注意が必要 参考: reply.vim
terminal mode の不便な点 terminal mode をメインの環境にしたいと思うと必ず(?)以下のような問 題にぶつかります terminal mode の中で
vim を叩くと vim がネストされてしまう!!!
vim-in-vim 問題 URL
vim-in-vim 問題 これは vim の場合以下のように回避できる +clientserver で build された vim
で vim --remote を使う 今日の本題である terminal-api を利用する また、neovim の場合は --remote が無いので以下を利用し回避できる mhinz/neovim-remote を使用して vim --remote を再現する Vim の clientserver 機能、neovim-remote を使った回避方法は Vim/Neovim の terminal mode の中で Vim/Neovim を実行するときに 便利そうなやつを作った で紹介しています
Tapi(terminal-api) について 特殊なエスケープシーケンスを使用して :terminal で動いているジョブ (プロセス)から Vim へ JSON を送信することができる機能(Vim
のみ) たとえば <Esc>]51;["drop", "README.md"]<07> という形で ["drop", "README.md"] という JSON を送信できる 注) <Esc> , <07> はそのままの文字列のことではなく文字コード 0x1b , 0x07 のこと 現在、命令は drop と call の 2つだけしかない
drop URL
drop :drop コマンドと同じように指定したファイルを開く命令 先の例では echo -e "\x1b]51;[\"drop\", \"hoge\"]\x07" で hoge
というファイルを親の vim 側で開かせた 挙動としては、同名のファイルがすでに開かれている場合はそのウィン ドウを開き、そうでない場合は新しいウィンドウを開く
call ユーザ定義関数を呼び出すことができる命令 ["call", "Tapi_Impression", ["play", 14]] という JSON を送信すると、 Vim
側で Tapi_Impression() という関数を呼び出してくれる 当然 Tapi_Impression() も定義されている必要があるので例えば以下の ように定義しておく function! Tapi_Impression(bufnum, arglist) if len(a:arglist) == 2 echomsg "impression " . a:arglist[0] echomsg "count " . a:arglist[1] endif endfunction
call 呼び出される関数は terminal-api 用に書かれたものでは無い可能性もあ るため Tapi_ で始まるものしか呼べないようになっている また第一引数は :terminal のバッファ番号、第二引数には
call で渡さ れた引数が入る(先の例では ["play", 14] )
terminal-api を使って vim-in-vim 問題 を回避する 単純に vim-in-vim 問題を回避するためには drop を用いれば回避できる
しかし、ファイルの開き方にはそれぞれ好みがあると思われる :vsplit :split :edit :tabnew これらに対応した Tapi_ 関数を書く
termopen.vim (未リリース!!)
termopen.vim 単純に、引数で "開き方" と "ファイル名" を受け取り、指定された開き 方でファイルを開く function! Tapi_open(bufnr, args)
if len(args) < 1 return endif call s:open(a:args[0], a:args[1:]) endfunction
termopen.vim function s:open(cmd, files) for f in a:files execute a:cmd
.. ' ' .. f endfor endfunction
termopen.vim これを使えば自分の好きな開き方で terminal mode から親の vim でフ ァイルを開ける!!!
terminal-api を使った plugin の注意点 現実的には... echo -e "\x1b]51;... なんて毎回打ってられないので、それ用の外部コ マンドもセットで提供する必要がある
参考資料 :h terminal :terminal に関する小さい Tips Vim のレジスタに :terminal のシェル上からアクセスする
EDITOR in :terminalを真面目に設定する