I’m able to get the cursor position with getpos(), but I want to retrieve the selected text within a line, that is '<,'>. How’s this done?
UPDATE
I think I edited out the part where I explained that I want to get this text from a Vim script…
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m not totally sure about the context here, because
getpos()can indeed accept marks (like'<and'>) as arguments.However, to take a stab at what you might be asking for, there’s also
v, which is like'<except it’s always updated (i.e. while the user is still in visual mode). This can be used in combination with., the current cursor position, which will then represent the end of the visual selection.Edit: I found these in
:help line(); several functions includingline()andgetpos()have the same set of possible arguments.Edit: I guess you’re probably simply asking how to get the text between two arbitrary marks, not going line-by-line… (i.e. this doesn’t specifically pertain to visual mode). I don’t think there actually is a way. Yes, this seems like a pretty glaring omission. You should be able to fake it by finding the marks with
getpos(), getting all the lines withgetline(), then chopping off on the first and last according to the column position (with casework depending on whether or not it’s multi-line). Sorry it’s not a real answer, but at least you can wrap it up in a function and forget about it.