Tuesday, 14 November 2017

vimrc - Vim: execute command with range silently


According to the vim documentation, the :silent command can be used to avoid the hit-enter prompt.


The problem is that I want to silent a command that accepts a range as input, and this does not work because the range is passed to :silent instead of to the command itself.




Example


To open the urls in the current file or selection, I use the following mapping in my .vimrc:


noremap u :w !urlview

where :w !urlview pipes the current file or selection to urlview standard input.


Now, trying to avoid the hit-enter prompt, I added:


noremap u :silent w !urlview

that, when invoked with a selection, rightfully responds with:


E481: No range allowed



Any clues on how to circumvent this issue?



Answer



You can modify the mapping to insert the :silent after the initial typing of the :w command, just like you would probably do when typing this interactively:


:noremap u :wsilent  !urlview

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...