Quantcast
Channel: Active questions tagged user-commands - Vi and Vim Stack Exchange
Viewing all articles
Browse latest Browse all 60

Passing visual range to a :command as its argument

$
0
0

I have a command:

command! -nargs=1 TmuxSession !tmux.session "<args>"

and I want to run it in visual mode so that selected text will be passed as argument.
By selected text I mean selected in visual mode in vim.

How can I achieve that?

I tried running

command -nargs=1 -range -register TmuxSession !tmux.session "<args>"

but it keeps saying E471: Argument required

Edit:
I know about using <C-r>" to paste an argument and that is how I use the upper command at the moment, but I don't want to copy selection and paste it every time to the command, because this can be done faster using range.

Edit2:

Following solution does not work:

function! PrintRange() range    echo getline(a:firstline, a:lastline)endfunctioncommand! -range PassRange <line1>,<line2>call PrintRange()

because when I want to select second and third word from line containing one two three - I get the whole line (obviously).

I need to pass only the selected part of the text.

Thanks


Viewing all articles
Browse latest Browse all 60

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>