mhinz / neovim-remote

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

Passing in a command using '+' gives me E481: No range allowed error #115

Closed beelzebielsk closed 5 years ago

beelzebielsk commented 5 years ago

I'm running a command straight from the help description

nvr --remote-tab-wait +'set bufhidden=delete' file

With file changed to something that exists on my computer. My nvr version is 2.2.0, and my nvim version is 0.3.8. I get the error E481: No range allowed. The exact stacktrace I get back from nvr is:

EDIT: My python version is 3.7.4

Traceback (most recent call last):
  File "/usr/bin/nvr", line 11, in <module>
    load_entry_point('neovim-remote==2.2.0', 'console_scripts', 'nvr')()
  File "/usr/lib/python3.7/site-packages/nvr/nvr.py", line 434, in main
    nvr.execute(options.remote_tab_wait + arguments, 'tabedit', wait=True)
  File "/usr/lib/python3.7/site-packages/nvr/nvr.py", line 149, in execute
    self.server.command(cmd if cmd else '$')
  File "/usr/lib/python3.7/site-packages/pynvim/api/nvim.py", line 287, in command
    return self.request('nvim_command', string, **kwargs)
  File "/usr/lib/python3.7/site-packages/pynvim/api/nvim.py", line 182, in request
    res = self._session.request(name, *args, **kwargs)
  File "/usr/lib/python3.7/site-packages/pynvim/msgpack_rpc/session.py", line 102, in request
    raise self.error_wrapper(err)
pynvim.api.nvim.NvimError: b'Vim(set):E481: No range allowed'

And the command isn't run.

jan0sch commented 5 years ago

I can confirm this bug. Recently I updated my neovim-remote (after a long time) and instantly got this error.

The file is openend in neovim but the command is not run as stated above.

beelzebielsk commented 5 years ago

I started looking at the source myself. It seems the problem is that the commands being passed in keep the + at the start. For instance, for the command:

nvr --remote-tab-wait +'set bufhidden=delete' file

This command +'set bufhidden=delete' would be executed in line 149 of nvr.py, and the actual text of the command is '+set bufhidden=delete' with the + at the start.

If I write exactly this as an ex command in vim

:+set bufhidden=delete

I get a no range allowed error.

If I change line 149 to

self.server.command(cmd[1:] if cmd else '$')

To lop off the leading '+', then everything works correctly.

I can fix this myself, though I'm curious as to how it should be done. I feel like this should have been noticed ages ago because all commands passed in using '+' should have caused this error; I'm just wondering if there's actually something more subtle going on, somehow.

I could leave this little fix at line 149 which seems hacky, or I can fix it at line 348 inside of split_cmds_from_files.

For now, I'm going to make a fork and submit a pull request with a change, let me know if there's anything I should do differently.