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
1.8k
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
terminal-api について
tennashi
May 15, 2019
More Decks by tennashi
See All by tennashi
続 terminal-api について
tennashi
2
710
Other Decks in Programming
See All in Programming
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
240
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
530
Claude Team Plan導入・ガイド
tk3fftk
0
220
才能?センス?知らん、 続けたもん勝ちだ。-- 結婚・出産・癌を越えてなお、私がプロダクトを創り続ける理由
16bitidol
2
900
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
430
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
130
5分で問診!Composer セキュリティ健康診断
codmoninc
0
580
【やさしく解説 設計編 #0】DDDのコード、読めるのに分からない人へ
panda728
PRO
2
280
GitHubCopilotCLIのスラッシュコマンドを自作してみる
htkym
0
100
AIエージェントで 変わるAndroid開発環境
takahirom
2
710
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
なぜ関数型プログラミングで「型」と「証明」が語られるのか #fp_matsuri
kajitack
3
1k
Featured
See All Featured
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
970
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.1k
How to train your dragon (web standard)
notwaldorf
97
6.7k
Unsuck your backbone
ammeep
672
58k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
640
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
330
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
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を真面目に設定する