I have a file like this:

INSERT INTO `example`
(`name`, `location`, `height`)
('A', '', ''),
('B', '', ''),
('C', '', '');

I want to fill in the middle set of quote marks (the ones under location) so that I end up with

INSERT INTO `example`
(`name`, `location`, `height`)
('A', 'one',   ''),
('B', 'two',   ''),
('C', 'three', '');

What's a good way to do that? Aligning the third column of quotes isn't necessary, but preferred.

  • 1
    Where's the 'one,two,three' coming from? Are you typing it, pasting it, from another file, etc? – kenny Aug 21 '12 at 17:10
  • @KennyYounger: Typing it. I'm trying to avoid having to navigate character-by-character to align my cursor with the middle column of quotes. – Snowball Aug 21 '12 at 17:15

I would suggest a similar approach to rush, but remaining more in insert mode:

/''/e lands you in between the quotes.

i one

Ctrl-o 2n


Ctrl-o 2n



As for aligning the columns I would suggest using Dr. Chip's Align plugin, then a simple :'<,'>Align , would put the columns right.

  • What's /e in the first command? (Or, even better, where can I find the documentation for it?) – Snowball Aug 21 '12 at 21:53
  • e means set cursor at the end of the match. This is the offset specification, you can go back, forward, up, and down. It's documented as search-offset. – Thor Aug 21 '12 at 22:50
  • Comes in very handy when using the search as a motion for an operator, e.g. delete until pattern: d/pattern/-1. Or delete until pattern + 2 lines: d/pattern/2. – Thor Aug 22 '12 at 11:19

gg # will jump to the first string

/'',Enter # will jump to the first '' occurence

a one Esc # will add one into '' into second column

W i Tab Esc # will jump to the third column and add Tab if necessary. optional step

n #this will move you to line 2

  • The n should be doubled or 2n. – Thor Aug 21 '12 at 20:09
  • nope. As you can mention, the search pattern includes comma at the end. And it will match only the second column. Therefore I need only one n. – rush Aug 21 '12 at 20:17
  • Ah I see, you're right. – Thor Aug 21 '12 at 20:18

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.