How to create a new line without creating an extra space?

30 views
Skip to first unread message

Jessie A. Young

unread,
Feb 14, 2013, 6:02:40 PM2/14/13
to vi...@googlegroups.com
Hi all - I've been running into Vim issue all day and it's starting to get to me, so I thought I'd ask my fave vimthusiasts.

I've been splitting up long lists of arguments into multiple lines. Example:

I have this: 

blah(a: "a", b: "b", c: "c", d: "d")

I want it to look like this:

blah (
  a: "a"
  b: "b"
  c: "c"
  d: "d"
)

Right now, this is what I am doing (in vim) to change each line:

- use w to skip to next word
- press i to enter insert mode
- press h to go one space to the left
- press enter to move word to the next line

If I do not do the "h" step, an extra white space is added to the end of the original line. 

This seems like WAY too many steps to do something this simple. What Would a Vim Enthusiast Do?


Adarsh Pandit

unread,
Feb 14, 2013, 6:10:20 PM2/14/13
to vi...@googlegroups.com
I did this a while ago so starred this page:

Answer is to do a normal %s search/replace, but use '\r' to represent the newline, so:

:%s/,/\r/g 

Voila.

a


--
You received this message because you are subscribed to the Google Groups "VimSF" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vimsf+un...@googlegroups.com.
To post to this group, send email to vi...@googlegroups.com.
Visit this group at http://groups.google.com/group/vimsf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
@adarshp
developer for thoughtbot, inc
313.454.1515 (m)

Scheduling with me? See bit.ly/adarshcalendar

Sean Sorrell

unread,
Feb 14, 2013, 6:21:07 PM2/14/13
to vi...@googlegroups.com
`%s` is for cheaters ;)

Here's what I would probably do: `f,a<CR>;.;.`

I think you generally have the right idea, but because you're going into insert mode at the beginning of the next word (ie. using `w`) you get that extra space. I think if you switched `w` for `e` and `a` for `i`, you'd get a better result.
Reply all
Reply to author
Forward
0 new messages