2

Currently, I'm using Vim Surround to make quoting easy on

  • Multiple whole-lines
  • Visual blocks
  • Individual words

However, it doesn't seem to make the job easy on columns, for example. Take this question for example, I can get to this from the sample data

'A', owner_from , 12/17/2016 8:57:00  , 12/19/2016 9:01:05 
'B', owner_to   , 12/17/2016 8:57:00  , 12/17/2016 12:03:10
'B', closed     , 12/17/2016 12:03:10             
'C', opened     , 12/18/2016 4:57:36  , 12/18/2016 4:57:36 
'C', owner_to   , 12/18/2016 4:57:36  , 12/18/2016 4:57:36 
'C', owner_from , 12/18/2016 4:57:36  , 12/18/2016 10:20:37
'C', owner_to   , 12/18/2016 10:20:37 , 12/18/2016 12:32:56
'D', owner_from , 12/18/2016 10:20:37 , 12/18/2016 10:36:53
'E', owner_from , 12/18/2016 10:36:53             
'D', owner_to   , 12/18/2016 10:36:53 , 12/20/2016 9:23:34 
'C', closed     , 12/18/2016 12:32:56 , 12/19/2016 4:48:33 
'C', opened     , 12/19/2016 4:48:33  , 12/19/2016 6:55:39 
'C', closed     , 12/19/2016 6:55:39              
'A', opened     , 12/19/2016 9:01:05  , 12/19/2016 9:01:05 
'A', owner_to   , 12/19/2016 9:01:05  , 12/19/2016 9:01:05 
'A', owner_from , 12/19/2016 9:01:05  , 12/19/2016 9:04:58 
'A', closed     , 12/19/2016 9:04:58  , 12/19/2016 9:08:21 

But I can not continue and quote that second column whose first row has owner_from. What I want to do is

  1. select the [o]wnerfrom and change all the inner words from the top to the bottom.
  2. or, select the entire word and have it quote just the word and note white space.

I'd like to know if this can be done using vim-surround first, and if not if there is a better way to do it.

1
  • If you think one of these answers solve your problem. Then accept it by clicking on the checkmark beside it to toggle it from greyed out to fill in. @Evan Carroll
    – Pie
    Jul 28, 2019 at 17:11

2 Answers 2

3

You can use :normal to run a series of normal commands on lines in the buffer.

:%norm Wysiw'

This will skip to the second WORD and then use surround's ys command to surround with ' on the current iw text object. It does this for every line in the buffer, %.

For more help see:

:h :norm
:h :range
1
  • very cool! I'll accept this in a couple of a day if no one has a better idea. this works though. Apr 12, 2017 at 16:29
3

Seems like a great job for macros. Peter Rincker's may be fewer keystrokes, but I feel it's worth mentioning as if you need a more specific range than the whole file, it's a little easier to modify.

With your cursor on the first column of the first line do the following:

  • qq to start a macro
  • Wysiw'+ Uses ys on second WORD (Just like Peter's) and moves to the next line.
  • q to end the macro
  • #@q Replace # with the actual number of lines you want to run the macro on. (@q runs macro 'q')

Alternatively, if you don't have the surround plugin, replace the second line with:

Wi'Escea'Esc+

See :help recording for more info on macros.

1
  • Lets remove that 0 and make this a bit shorter by swapping out j with <cr>/+ (Assuming you start at ^ or 0) e.g qqWysiw'+q999@q Apr 12, 2017 at 21:16

Your Answer

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

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