In Vim, I want to visually select some lines and then paste a copy of the commented-out selection either above or below the original selection, depending upon whether the visual selection was created upwards or downwards. So if I start visual mode on line 100 and move the cursor up 10 lines, that would be an upward visual selection, whereas if I start at line 100 and move the cursor down 10 lines it would be a downward selection. line("'<") and line("'>") are identical in both cases so it looks like Vim always chooses the lesser number as the selection start. Is there a way to determine if the visual selection was upward or downward?
In Vim, I want to visually select some lines and then paste a copy
Share
When (in your mapping / command) you first exit visual mode via
<Esc>, you can compare the position / line of the cursor (line('.')) with the'<and'>marks. Then just use the marks (they keep their values even when visual mode is left), or re-select via:normal! gv.