mhinz / neovim-remote

:ok_hand: Support for --remote and friends.
MIT License
1.73k stars 83 forks source link

How to get output of a command? #162

Closed tejasvi closed 3 years ago

tejasvi commented 3 years ago

nvr -c 'echo "test"' prints nothing to stdout. More specifically I was trying to get buffer contents using nvr -c "py3 print(vim.current.buffer[0])".

mhinz commented 3 years ago

Yes, usually nvr is used the other way around: controlling another process and sending it input, not evaluating something there and getting the result back.

But you can still do that with --remote-expr, which like the name suggests, takes an Vim expression, not a command.

So, to get the first line like in your example:

$ nvr --servername ... --remote-expr 'getline(1)'

If you really want to use Python3 for that, use this:

$ nvr --servername ... --remote-expr 'py3eval("vim.current.buffer[0]")'