0

Suppose i have several lines of text:

line1 line1
line2 line2
line3 line3

I want to create a vimscript function that has the following result:

<itemizedlist>
<listitem><para>line1 line1</para></listitem>
<listitem><para>line2 line2</para></listitem>
<listitem><para>line3 line3</para></listitem>
</itemizedlist>

How do i use '< and '> to move to the beginning and end of multiline visual selection inside a vimscript function? vim writes me "Not an editor command: '<"

1

Simply?

normal! '<

However, I would highly recommend seeing if there is a way to accomplish what you want via simpler (Ex) commands. If you need to do some work over a range, Ex commands are good at it.

For example, visually select the lines (e.g., Vap), then :'<,'>normal! Isome text and :'<,'>normal! Asome text. Then you should be able to get the lines above and below via the '< and '> registers and put the remaining text.

1
  • Aside: functions defined without [range] called with a range will be run once on each line, so you could have a function to do the surround on each line, and then separately to handle the above and below.
    – D. Ben Knoble
    May 28 '19 at 13:56

This site is temporarily in read only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .