Function that return visually selected text

I know this question have already been asked everywhere but I’ve tried everything and nothing seem to work fine for me. I’d like to have a function that when is called returns the string value of the text visually selected. Is there a way to make that in lua? Thanks for your time (:

1 Like

It seem to work, but either the line returned isn’t the one I selected or I have this error bad argument #1 to 'sub' (string expected got nil) (the error is on this line : lines[1] = string.sub(lines[1], s_start[3], -1)).
Thanks for your answer

EDIT: I did some debug and this just had to do with the way I was calling the function. Thank you this works really well! Have a nice day (:

1 Like

I’m seeing the same error, what’s the correct way to call it?

If you are calling it from the mapping ,make sure to prefix it with <C-u>. Here’s an example neovim-config/search.lua at master · kristijanhusak/neovim-config · GitHub

The link provided by @kristijanhusak is no longer available and I’m seeing the same error. @vzytoi could you provide some details on what you did to get this working? Thanks!

Here’s the updated link