mhinz / neovim-remote

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

Any way to get value from NeoVim? #184

Open TamaMcGlinn opened 2 years ago

TamaMcGlinn commented 2 years ago

In order to configure a linter, I'm trying to read a global from the currently active NeoVim instance (the one that spawned the linter, in this case). Basically, I am trying to get something like this to work:

nvr +echo\ g:fugitive_conflict_x

(for the example I just picked an arbitrary global everyone likely has defined; it is either 0 or 1)

It works if I throw it, but this is just disgusting; can we get a print option in nvr or something?

nvr +throw\ g:fugitive_conflict_x 2>&1 | grep NvimError | sed 's/pynvim.api.common.NvimError: //'

I would have expected writing to stdout the same way as in vim to work (described here), but it doesn't seem to.

joshbode commented 8 months ago

Very late response, but you should be able to use --remote-expr to get this working, e.g.

$ nvr --remote-expr "g:lua_version"
5

Note: you'll get an error if the variable doesn't exist, e.g.

$ nvr --remote-expr "g:fugitive_conflict_x"

No valid expression: g:fugitive_conflict_x
Test it in Neovim: :echo eval('...')
If you want to execute a command, use -c or -cc instead.

$ echo $?
0

although the exit-code will still be zero.