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 requiredEdit: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
Passing visual range to a :command as its argument
visual mode;range;user commands
See this answer on stackoverflow.The example given is: function! PrintGivenRange() range     echo firstline .a:firstline. lastline .a:lastline      Do some more things endfunction command! -range PassRange <line1>,<line2>call PrintGivenRange()Thus you might want to create a function which would use the range and do the tmux call you want.In your function, to get the text in the range you can use the getline() function which will take a:firstline and a:lastline as parameters and return the text in the buffer between theses lines. You can have a look at :h getline() or :h getbufline().Edit If you want to get the text characterwise and not linewise you'll have to play with the marks. This edit is inspired from this SO answer.So when you call you command with :'<,'>PassRange the marks '< and '> are set. The doc :h '< tells us that these marks are used to describe the last visual selection.Your function would need to look like this:function! PrintGivenRange() range     Get the line and column of the visual selection marks    let [lnum1, col1] = getpos('<)[1:2]    let [lnum2, col2] = getpos('>)[1:2]     Get all the lines represented by this range    let lines = getline(lnum1, lnum2)              The last line might need to be cut if the visual selection didn't end on the last column    let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)]     The first line might need to be trimmed if the visual selection didn't start on the first column    let lines[0] = lines[0][col1 - 1:]     Get the desired text    let selectedText = join(lines, \n)              Do the call to tmux    execute !tmux.session  . selectedText endfunction