I want to create a user command that can get the visual-selected text (may across multiple lines) from users when the command is calling upon the v-selected range. (so the cursor columns of both the start&end of the visual region matter) Currently, I can only get the rows info of the selected region from line1, line2 in the callback/handler by setting range=true in the option of nvim_create_user_command, but how about the columns?

I also found this great old answer on the Vim side but it only mentioned about getting the starting and ending rows, but I also need the columns info to get the exact selected text.

  • 1
    User commands are typically linewise. If you want something invoked from visual mode, use xnoremap. But: try getting the column information out of the '< and '> marks.
    – D. Ben Knoble
    Commented Apr 7, 2023 at 14:42
  • @D.BenKnoble Thanks for the hint. Commented Apr 7, 2023 at 15:26


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.