Skip to content

Instantly share code, notes, and snippets.

@AaronBPaden
Last active August 29, 2015 14:24
Show Gist options
  • Save AaronBPaden/e52047b63b5339ebf835 to your computer and use it in GitHub Desktop.
Save AaronBPaden/e52047b63b5339ebf835 to your computer and use it in GitHub Desktop.
Run a command in the running neovim session.
#!/usr/bin/python2
from __future__ import print_function
from docopt import docopt
from neovim import attach
from neovim.api import NvimError
import os
import sys
__doc__ = """nvim-command - Run a command in the running neovim session.
Usage:
nvim-command <command>..."""
if __name__ == "__main__":
nvim = None
try:
nvim = attach("socket", path=os.environ["NVIM_LISTEN_ADDRESS"])
except KeyError:
print("No neovim session found.", file=sys.stderr)
sys.exit(1)
try:
nvim.command(" ".join(docopt(__doc__)["<command>"]))
except NvimError as e:
print(e, file=sys.stderr)
sys.exit(1)
@critiqjo
Copy link

critiqjo commented Jul 7, 2015

I had tried to make the command handling "smarter": nvimex.py
(The result may be dumber!)

@AaronBPaden
Copy link
Author

@critiqjo Sure, I did see that one. It's probably more useful for interactive use–my goal here was least surprise for scripts. You could install both, and any new features added to nvimex wont break any scripts you've written.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment