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
Everything will be SERVERLESS — 信じて運用した10年の経験値 / Everything Will be Serverless — Lessons Learned from 10 Years of Operational Experience
seike460
PRO
1
1.1k
dotNET_vulnclicker_intro.pdf
deka_morita
0
140
Event is what happens
moro
2
780
JIS keyboard support in Omarchy
lef237
0
110
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
180
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
3.6k
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
contenteditable と日本語入力に向き合う
colorful12
0
200
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.7k
Featured
See All Featured
Raft: Consensus for Rubyists
vanstee
142
7.8k
技術選定の審美眼(2025年版) / Understanding the Spiral of Technologies 2025 edition
twada
PRO
120
120k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.7k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
1
280
It's Worth the Effort
3n
188
29k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
Site-Speed That Sticks
csswizardry
13
1.6k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
360
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
My Coaching Mixtape
mlcsv
0
360
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.9k
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を真面目に設定する