1

From the following text:

variable1 = 'example'
foo = 'foo'
barett = 'ver'

I would like to yank (or visually select, if possible) the content of each line until the = sign:

variable1
foo
barett

That is: "yank/visually select the contents of the following lines, stopping the yanking/selection in each line as soon as an = character is found"

If I were dealing with a single line it would be simple> from the beginning of the line: yt=

But I have no clue how to do this with multiple lines (and visual block won't help since I don't want the same number of characters from each line).

3

I'm not sure this is what you want, but you could try this mapping:

xno my y'>pV']:s/=.*//<cr>gvd

To use it, you would visually select your lines, then hit my. It should write the text before the = character on each line of your selection, inside the unnamed register.

Here's what it does:

  • y yanks the selection
  • '> moves the cursor to the last line of the selection
  • p puts the unnamed register, where currently the last yanked text is
  • V goes into visual line mode
  • '] moves the end of the selection down to the last line of the last text on which you performed an operation (here the yanking)
  • :s/=.*//<cr> removes everything after the = character, on each line of the selection
  • gv reselects the last selection
  • d deletes it
  • 1
    I'm giving it a go. Maybe instead of the last yu I could use d? Otherwise the uundoes the :s/=.*//<cr>, not the pasting. – user2891462 Jun 27 '17 at 12:44
  • @user2891462 Indeed, you're right, d should work too, and it's shorter. – user547381 Jun 27 '17 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.