1
- *channel.txt* For Vim version 8.0 . Last change: 2016 Dec 02
1
+ *channel.txt* For Vim version 8.1 . Last change: 2018 Apr 18
2
2
3
3
4
4
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -22,6 +22,7 @@ The Netbeans interface also uses a channel. |netbeans|
22
22
9. Starting a job without a channel | job-start-nochannel |
23
23
10. Job options | job-options |
24
24
11. Controlling a job | job-control |
25
+ 12. Using a prompt buffer | prompt-buffer |
25
26
26
27
{Vi does not have any of these features}
27
28
{only when compiled with the | +channel | feature for channel stuff}
@@ -55,7 +56,7 @@ JS JavaScript style JSON-like encoding |js_encode()|
55
56
Common combination are:
56
57
- Using a job connected through pipes in NL mode. E.g., to run a style
57
58
checker and receive errors and warnings.
58
- - Using a deamon , connecting over a socket in JSON mode. E.g. to lookup
59
+ - Using a daemon , connecting over a socket in JSON mode. E.g. to lookup
59
60
cross-references in a database.
60
61
61
62
==============================================================================
@@ -427,8 +428,8 @@ When no message was available then the result is v:none for a JSON or JS mode
427
428
channels, an empty string for a RAW or NL channel. You can use | ch_canread() |
428
429
to check if there is something to read.
429
430
430
- Note that when there is no callback message are dropped. To avoid that add a
431
- close callback to the channel.
431
+ Note that when there is no callback, messages are dropped. To avoid that add
432
+ a close callback to the channel.
432
433
433
434
To read all output from a RAW channel that is available: >
434
435
let output = ch_readraw(channel)
@@ -489,6 +490,11 @@ If you want to handle both stderr and stdout with one handler use the
489
490
"callback" option: >
490
491
let job = job_start(command, {"callback": "MyHandler"})
491
492
493
+ Depending on the system, starting a job can put Vim in the background, the
494
+ started job gets the focus. To avoid that, use the `foreground ()` function.
495
+ This might not always work when called early, put in the callback handler or
496
+ use a timer to call it after the job has started.
497
+
492
498
You can send a message to the command with ch_evalraw(). If the channel is in
493
499
JSON or JS mode you can use ch_evalexpr().
494
500
@@ -513,7 +519,7 @@ By default this reads the whole buffer. This can be changed with the "in_top"
513
519
and "in_bot" options.
514
520
515
521
A special mode is when "in_top" is set to zero and "in_bot" is not set: Every
516
- time a line is added to the buffer, the last-but-one line will be send to the
522
+ time a line is added to the buffer, the last-but-one line will be sent to the
517
523
job stdin. This allows for editing the last line and sending it when pressing
518
524
Enter.
519
525
*channel-close-in*
@@ -606,7 +612,7 @@ See |job_setoptions()| and |ch_setoptions()|.
606
612
"close_cb": handler Callback for when the channel is closed. Same as
607
613
"close_cb" on | ch_open() | , see | close_cb | .
608
614
*job-drop*
609
- "drop" Specifies when to drop messages. Same as "drop" on
615
+ "drop": when Specifies when to drop messages. Same as "drop" on
610
616
| ch_open() | , see | channel-drop | . For "auto" the
611
617
exit_cb is not considered.
612
618
*job-exit_cb*
@@ -619,12 +625,12 @@ See |job_setoptions()| and |ch_setoptions()|.
619
625
Note that data can be buffered, callbacks may still be
620
626
called after the process ends.
621
627
*job-timeout*
622
- "timeout" The time to wait for a request when blocking, E.g.
628
+ "timeout": time The time to wait for a request when blocking, E.g.
623
629
when using ch_evalexpr(). In milliseconds. The
624
630
default is 2000 (2 seconds).
625
631
*out_timeout* *err_timeout*
626
- "out_timeout" Timeout for stdout. Only when using pipes.
627
- "err_timeout" Timeout for stderr. Only when using pipes.
632
+ "out_timeout": time Timeout for stdout. Only when using pipes.
633
+ "err_timeout": time Timeout for stderr. Only when using pipes.
628
634
Note: when setting "timeout" the part specific mode is
629
635
overwritten. Therefore set "timeout" first and the
630
636
part specific mode later.
@@ -636,8 +642,9 @@ See |job_setoptions()| and |ch_setoptions()|.
636
642
The default is "term".
637
643
638
644
*job-term*
639
- "term": "open" Start a terminal and connect the job
640
- stdin/stdout/stderr to it.
645
+ "term": "open" Start a terminal in a new window and connect the job
646
+ stdin/stdout/stderr to it. Similar to using
647
+ `:terminal ` .
641
648
NOTE: Not implemented yet!
642
649
643
650
"channel": {channel} Use an existing channel instead of creating a new one.
@@ -647,6 +654,11 @@ See |job_setoptions()| and |ch_setoptions()|.
647
654
cause I/O errors.
648
655
Existing callbacks and other settings remain.
649
656
657
+ "pty": 1 Use a pty (pseudo-tty) instead of a pipe when
658
+ possible. This is most useful in combination with a
659
+ terminal window, see | terminal | .
660
+ {only on Unix and Unix-like systems}
661
+
650
662
*job-in_io* *in_top* *in_bot* *in_name* *in_buf*
651
663
"in_io": "null" disconnect stdin (read from /dev/null)
652
664
"in_io": "pipe" stdin is connected to the channel (default)
@@ -685,6 +697,10 @@ See |job_setoptions()| and |ch_setoptions()|.
685
697
"block_write": number only for testing: pretend every other write to stdin
686
698
will block
687
699
700
+ "env": dict environment variables for the new process
701
+ "cwd": "/path/to/dir" current working directory for the new process;
702
+ if the directory does not exist an error is given
703
+
688
704
689
705
Writing to a buffer ~
690
706
*out_io-buffer*
@@ -720,10 +736,6 @@ The "out_msg" option can be used to specify whether a new buffer will have the
720
736
first line set to "Reading from channel output...". The default is to add the
721
737
message. "err_msg" does the same for channel error.
722
738
723
- 'modifiable' option off, or write to a buffer that has 'modifiable' off. That
724
- means that lines will be appended to the buffer, but the user can't easily
725
- change the buffer.
726
-
727
739
When an existing buffer is to be written where 'modifiable' is off and the
728
740
"out_modifiable" or "err_modifiable" options is not zero, an error is given
729
741
and the buffer will not be written to.
@@ -759,5 +771,49 @@ signals. E.g. to force a job to stop, "kill it": >
759
771
760
772
For more options see | job_stop() | .
761
773
774
+ ==============================================================================
775
+ 12. Using a prompt buffer *prompt-buffer*
776
+
777
+ If you want to type input for the job in a Vim window you have a few options:
778
+ - Use a normal buffer and handle all possible commands yourself.
779
+ This will be complicated, since there are so many possible commands.
780
+ - Use a terminal window. This works well if what you type goes directly to
781
+ the job and the job output is directly displayed in the window.
782
+ See | terminal-window | .
783
+ - Use a prompt window. This works well when entering a line for the job in Vim
784
+ while displaying (possibly filtered) output from the job.
785
+
786
+ A prompt buffer is created by setting 'buftype' to "prompt". You would
787
+ normally only do that in a newly created buffer.
788
+
789
+ The user can edit and enter one line of text at the very last line of the
790
+ buffer. When pressing Enter in the prompt line the callback set with
791
+ | prompt_setcallback() | is invoked. It would normally send the line to a job.
792
+ Another callback would receive the output from the job and display it in the
793
+ buffer, below the prompt (and above the next prompt).
794
+
795
+ Only the text in the last line, after the prompt, is editable. The rest of the
796
+ buffer is not modifiable with Normal mode commands. It can be modified by
797
+ calling functions, such as | append() | . Using other commands may mess up the
798
+ buffer.
799
+
800
+ After setting 'buftype' to "prompt" Vim does not automatically start Insert
801
+ mode, use `:startinsert ` if you want to enter Insert mode, so that the user
802
+ can start typing a line.
803
+
804
+ The text of the prompt can be set with the | prompt_setprompt() | function.
805
+
806
+ The user can go to Normal mode and navigate through the buffer. This can be
807
+ useful see older output or copy text.
808
+
809
+ The CTRL-W key can be used to start a window command, such as CTRL-W w to
810
+ switch to the next window. This also works in Insert mode (use Shift-CTRL-W
811
+ to delete a word). When leaving the window Insert mode will be stopped. When
812
+ coming back to the prompt window Insert mode will be restored.
813
+
814
+ Any command that starts Insert mode, such as "a", "i", "A" and "I", will move
815
+ the cursor to the last line. "A" will move to the end of the line, "I" to the
816
+ start of the line.
817
+
762
818
763
- vim:tw=78:ts=8:ft=help:norl:
819
+ vim:tw=78:ts=8:noet: ft=help:norl:
0 commit comments