|
1 | | -*channel.txt* For Vim version 7.4. Last change: 2016 Jan 28 |
| 1 | +*channel.txt* For Vim version 7.4. Last change: 2016 Jan 31 |
2 | 2 |
|
3 | 3 |
|
4 | 4 | VIM REFERENCE MANUAL by Bram Moolenaar |
@@ -48,10 +48,10 @@ And the response is: |
48 | 48 | The number will increase every time you send a message. |
49 | 49 |
|
50 | 50 | The server can send a command to Vim. Type this on T1 (literally, including |
51 | | -the quotes): > |
52 | | - NOT IMPLEMENTED YET |
53 | | - ["ex","echo 'hi there'"] |
54 | | -And you should see the message in Vim. |
| 51 | +the quotes): |
| 52 | + ["ex","echo 'hi there'"] ~ |
| 53 | +And you should see the message in Vim. You can move the cursor a word forward: |
| 54 | + ["normal","w"] ~ |
55 | 55 |
|
56 | 56 | To handle asynchronous communication a callback needs to be used: > |
57 | 57 | func MyHandler(handle, msg) |
@@ -100,6 +100,14 @@ When {callback} is empty (zero or an empty string) the handler is removed. |
100 | 100 | Once done with the channel, disconnect it like this: > |
101 | 101 | call disconnect(handle) |
102 | 102 |
|
| 103 | +Currently up to 10 channels can be in use at the same time. *E897* |
| 104 | + |
| 105 | +When the channel can't be opened you will get an error message. |
| 106 | +*E898* *E899* *E900* *E901* *E902* |
| 107 | + |
| 108 | +If there is an error reading or writing a channel it will be closed. |
| 109 | +*E896* *E630* *E631* |
| 110 | + |
103 | 111 | ============================================================================== |
104 | 112 | 3. Using a JSON channel *channel-use* |
105 | 113 |
|
@@ -146,36 +154,77 @@ The channel will then be inactive. |
146 | 154 | ============================================================================== |
147 | 155 | 4. Vim commands *channel-commands* |
148 | 156 |
|
149 | | -NOT IMPLEMENTED YET |
| 157 | +PARTLY IMPLEMENTED: only "ex" and "normal" work |
150 | 158 |
|
151 | 159 | With a "json" channel the process can send commands to Vim that will be |
152 | 160 | handled by Vim internally, it does not require a handler for the channel. |
153 | 161 |
|
154 | | -Possible commands are: |
| 162 | +Possible commands are: *E903* *E904* *E905* |
| 163 | + ["redraw" {forced}] |
155 | 164 | ["ex", {Ex command}] |
156 | 165 | ["normal", {Normal mode command}] |
157 | | - ["eval", {number}, {expression}] |
| 166 | + ["eval", {expression}, {number}] |
158 | 167 | ["expr", {expression}] |
159 | 168 |
|
160 | 169 | With all of these: Be careful what these commands do! You can easily |
161 | 170 | interfere with what the user is doing. To avoid trouble use |mode()| to check |
162 | 171 | that the editor is in the expected state. E.g., to send keys that must be |
163 | | -inserted as text, not executed as a command: > |
164 | | - ["ex","if mode() == 'i' | call feedkeys('ClassName') | endif"] |
| 172 | +inserted as text, not executed as a command: |
| 173 | + ["ex","if mode() == 'i' | call feedkeys('ClassName') | endif"] ~ |
| 174 | + |
| 175 | +Errors in these commands are normally not reported to avoid them messing up |
| 176 | +the display. If you do want to see them, set the 'verbose' option to 3 or |
| 177 | +higher. |
| 178 | + |
| 179 | + |
| 180 | +Command "redraw" ~ |
| 181 | + |
| 182 | +The other commands do not update the screen, so that you can send a sequence |
| 183 | +of commands without the cursor moving around. You must end with the "redraw" |
| 184 | +command to show any changed text and show the cursor where it belongs. |
| 185 | + |
| 186 | +The argument is normally an empty string: |
| 187 | + ["redraw", ""] ~ |
| 188 | +To first clear the screen pass "force": |
| 189 | + ["redraw", "force"] ~ |
| 190 | + |
| 191 | + |
| 192 | +Command "ex" ~ |
165 | 193 |
|
166 | 194 | The "ex" command is executed as any Ex command. There is no response for |
167 | | -completion or error. You could use functions in an |autoload| script. |
168 | | -You can also invoke |feedkeys()| to insert anything. |
| 195 | +completion or error. You could use functions in an |autoload| script: |
| 196 | + ["ex","call myscript#MyFunc(arg)"] |
| 197 | + |
| 198 | +You can also use "call |feedkeys()|" to insert any key sequence. |
| 199 | + |
| 200 | + |
| 201 | +Command "normal" ~ |
| 202 | + |
| 203 | +The "normal" command is executed like with |:normal!|, commands are not |
| 204 | +mapped. Example to open the folds under the cursor: |
| 205 | + ["normal" "zO"] |
169 | 206 |
|
170 | | -The "normal" command is executed like with |:normal|. |
171 | 207 |
|
172 | | -The "eval" command will result in sending back the result of the expression: |
| 208 | +Command "eval" ~ |
| 209 | + |
| 210 | +The "eval" command an be used to get the result of an expression. For |
| 211 | +example, to get the number of lines in the current buffer: |
| 212 | + ["eval","line('$')"] ~ |
| 213 | + |
| 214 | +it will send back the result of the expression: |
173 | 215 | [{number}, {result}] |
174 | | -Here {number} is the same as what was in the request. |
| 216 | +Here {number} is the same as what was in the request. Use a negative number |
| 217 | +to avoid confusion with message that Vim sends. |
| 218 | + |
| 219 | +{result} is the result of the evaluation and is JSON encoded. If the |
| 220 | +evaluation fails it is the string "ERROR". |
| 221 | + |
| 222 | + |
| 223 | +Command "expr" ~ |
175 | 224 |
|
176 | | -The "expr" command is similar, but does not send back any response. |
| 225 | +The "expr" command is similar to "eval", but does not send back any response. |
177 | 226 | Example: |
178 | | - ["expr","setline('$', ['one', 'two', 'three'])"] |
| 227 | + ["expr","setline('$', ['one', 'two', 'three'])"] ~ |
179 | 228 |
|
180 | 229 | ============================================================================== |
181 | 230 | 5. Using a raw channel *channel-raw* |
|
0 commit comments