Skip to content

Commit 0259655

Browse files
authored
Merge pull request #2543 from h-east/update-channel
Update channel.{txt,jax}
2 parents 1c403fd + a041c47 commit 0259655

2 files changed

Lines changed: 118 additions & 2 deletions

File tree

doc/channel.jax

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*channel.txt* For Vim バージョン 9.2. Last change: 2026 Feb 25
1+
*channel.txt* For Vim バージョン 9.2. Last change: 2026 Mar 13
22

33

44
VIM リファレンスマニュアル by Bram Moolenaar
@@ -113,6 +113,32 @@ send を呼ぶたびに毎回コールバックを指定する代わりに、チ
113113
call ch_logfile('channellog', 'w')
114114
|ch_logfile()| 参照.
115115

116+
|ch_listen()| を使用すれば、Vim をサーバーとして動作させることもできる。この場
117+
合、外部のサーバープログラムは必要ない。
118+
119+
*channel-listen-demo*
120+
Vimを起動し、リスニングチャネルを作成する: >
121+
func OnAccept(channel, clientaddr)
122+
" 接続をログする
123+
echomsg "Accepted connection from " .. a:clientaddr
124+
125+
" 現在時刻を取得してクライアントに送信する
126+
let current_time = strftime("%Y-%m-%d %H:%M:%S")
127+
call ch_sendraw(a:channel, "Vim Server Time: " .. current_time .. "\n")
128+
129+
" オプション: 時間だけを表示したい場合は、すぐに閉じる
130+
call ch_close(a:channel)
131+
endfunc
132+
133+
" ポート 8765 でリッスンを開始する
134+
let server = ch_listen('localhost:8765', {"callback": "OnAccept"})
135+
136+
別の Vim インスタンス (または任意のプログラム) から接続できる: >
137+
let channel = ch_open('localhost:8765')
138+
139+
完了したら、サーバーチャネルを閉じる: >
140+
call ch_close(server)
141+
116142
==============================================================================
117143
3. チャネルを開く *channel-open*
118144

@@ -637,6 +663,37 @@ ch_info({handle}) *ch_info()*
637663
<
638664
戻り値の型: dict<any>
639665

666+
ch_listen({address} [, {options}]) *E1573* *E1574* *ch_listen()*
667+
着信チャネル接続を {address} で待機する。
668+
これは、既存のサーバーに接続する |ch_open()| とは異なり、サー
669+
バー側のチャネルを作成する。
670+
671+
チャネルを返す。|ch_status()| を使用して、失敗したかどうかを確
672+
認すること。
673+
674+
{address} は文字列である。使用可能な形式については、
675+
|channel-address|を参照。Note: IPv6 はまだサポートされていな
676+
い。
677+
678+
{options} が指定されている場合は、|Dictionary| である必要があ
679+
る。
680+
|channel-open-options| を参照
681+
{options} の "callback" は、新しい接続が受け入れられたときに呼
682+
び出される。このコールバックは、新しいチャネルとクライアントア
683+
ドレス (文字列形式、例: "127.0.0.1:12345") の 2 つの引数を受け
684+
取る。
685+
686+
既存のサーバーに接続するには、代わりに |ch_open()| を使用する。
687+
688+
例については、|channel-listen-demo| を参照。
689+
690+
|method| としても使用できる: >
691+
GetAddress()->ch_listen()
692+
<
693+
{Vim が |+channel| 機能付きでコンパイルされたときのみ有効}
694+
695+
戻り値の型: channel
696+
640697
ch_log({msg} [, {handle}]) *ch_log()*
641698
|ch_logfile()| によってログファイルが開かれている場合はチャネ
642699
ルのログファイルに文字列 {msg} を書き込む。
@@ -693,6 +750,9 @@ ch_open({address} [, {options}]) *ch_open()*
693750
{options} が与えられる場合は辞書でなければならない。
694751
|channel-open-options| を参照。
695752

753+
代わりに、入ってくる接続を待ち受けるには |ch_listen()| を使用
754+
する。
755+
696756
|method| としても使用できる: >
697757
GetAddress()->ch_open()
698758
<

en/channel.txt

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*channel.txt* For Vim version 9.2. Last change: 2026 Feb 25
1+
*channel.txt* For Vim version 9.2. Last change: 2026 Mar 13
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -114,6 +114,32 @@ Vim to write lines in log file: >
114114
call ch_logfile('channellog', 'w')
115115
See |ch_logfile()|.
116116

117+
You can also make Vim act as a server using |ch_listen()|. This does not
118+
require an external server program.
119+
120+
*channel-listen-demo*
121+
Start Vim and create a listening channel: >
122+
func OnAccept(channel, clientaddr)
123+
" Log the connection
124+
echomsg "Accepted connection from " .. a:clientaddr
125+
126+
" Get current time and send it to the client
127+
let current_time = strftime("%Y-%m-%d %H:%M:%S")
128+
call ch_sendraw(a:channel, "Vim Server Time: " .. current_time .. "\n")
129+
130+
" Optional: close immediately if you only want to provide the time
131+
call ch_close(a:channel)
132+
endfunc
133+
134+
" Start listening on port 8765
135+
let server = ch_listen('localhost:8765', {"callback": "OnAccept"})
136+
137+
From another Vim instance (or any program) you can connect to it: >
138+
let channel = ch_open('localhost:8765')
139+
140+
When done, close the server channel: >
141+
call ch_close(server)
142+
117143
==============================================================================
118144
3. Opening a channel *channel-open*
119145

@@ -641,6 +667,33 @@ ch_info({handle}) *ch_info()*
641667
<
642668
Return type: dict<any>
643669

670+
ch_listen({address} [, {options}]) *E1573* *E1574* *ch_listen()*
671+
Listen on {address} for incoming channel connections.
672+
This creates a server-side channel, unlike |ch_open()|
673+
which connects to an existing server.
674+
Returns a Channel. Use |ch_status()| to check for failure.
675+
676+
{address} is a String, see |channel-address| for the possible
677+
accepted forms. Note: IPv6 is not yet supported.
678+
679+
If {options} is given it must be a |Dictionary|.
680+
See |channel-open-options|.
681+
The "callback" in {options} is invoked when a new
682+
connection is accepted. It receives two arguments: the
683+
new Channel and the client address as a String (e.g.
684+
"127.0.0.1:12345").
685+
686+
Use |ch_open()| to connect to an existing server instead.
687+
688+
See |channel-listen-demo| for an example.
689+
690+
Can also be used as a |method|: >
691+
GetAddress()->ch_listen()
692+
<
693+
{only available when compiled with the |+channel| feature}
694+
695+
Return type: channel
696+
644697
ch_log({msg} [, {handle}]) *ch_log()*
645698
Write String {msg} in the channel log file, if it was opened
646699
with |ch_logfile()|.
@@ -695,6 +748,9 @@ ch_open({address} [, {options}]) *ch_open()*
695748
If {options} is given it must be a |Dictionary|.
696749
See |channel-open-options|.
697750

751+
Use |ch_listen()| to listen for incoming connections
752+
instead.
753+
698754
Can also be used as a |method|: >
699755
GetAddress()->ch_open()
700756
<

0 commit comments

Comments
 (0)