What is the correct way get the column of the cursor after a visual selection was made?
As a simple example, consider the following command. It takes a range and I am trying to obtain the column to eventually pass both to a filter:
command! -range CursorColumn echo col('.')
and this buffer:
abc
def
ghi
If the cursor is on c
and a visual line-wise selection is started and extended downwards to the third line, the cursor is on i
. Switching to command-line mode and executing the command above, it echos 1
. If the selection is started at i
and extended upwards to c
, then the command echos 3
, which I would expect in both cases.
How do I get the column of the cursor independently of how the selection was made?
My use case is that I want to pass the selected lines to a filter. At the same time I would like to pass the column the cursor was on as an argument:
command! -range MyFilter exe <line1>.",".<line2>."!myfilter ".col('.')
Edit: Making the selection in visual mode, instead of linewise-visual, shows the behavior I want: I get the column the cursor was on when I execute the command no matter how I made the selection.