Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
Verilogで学ぶCPU自作入門.pdf
uyuki234
8
3.5k
難しいけど、読めた。- OSSの入口に立った話。
sts11142
0
120
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
200
個人開発基盤をまるごとCloudflareに引っ越して爆速で総合的体験を向上させた話
tinykitten
0
210
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
270
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
140
Webの地図
yosuke_furukawa
PRO
6
4.8k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
330
アクセシビリティから考える情報設計
high_g_engineer
0
410
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
580
Streamlitで実現する自然言語データアプリ開発
ayumu_yamaguchi
1
320
wkhtmltopdfの次どうするか問題2026
willnet
2
1.8k
Featured
See All Featured
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
68
58k
Producing Creativity
orderedlist
PRO
348
41k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Designing Experiences People Love
moore
143
24k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
Product Roadmaps are Hard
iamctodd
55
13k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
420
WENDY [Excerpt]
tessaabrams
14
39k
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を真面目に設定する