Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for a solution about a "paste" problem on vi/vim .

How to join specific lines in a text file? I have a file like this:

15/10/2011 Revolution day
16/10/2011 About Rome
 - differents newspapers
  blogs an feeds
 :) hp
17/10/2011 Yep, another day

and I want to paste everyline that does not start with a number. I've tried something like this... but does not work :-/

:[!^[0-9]]!paste -d ' ' -s

Can somebody help me?

thanks gb

share|improve this question

If you want a space or something between, add it between \1 and \2.

share|improve this answer
ah, I was having problems doing it in a single command. thanks. :) – Tim Kennedy Oct 28 '11 at 14:32
GREAT! Thank you – gogolb Oct 28 '11 at 14:46

you can do it in two steps in VIM, if that's acceptable:

First, join all lines into a single line.

with the file open in VIM, issue the following keystroke: VGJ

  • V = Visual Mode (linewise, rather than character-wise (v))
  • G = highlight all lines
  • J = Join all lines

Second, split your lines on the date format the resulting lines start with.

with the file open in VIM, issue the following command:


This will search the single joined line for any string that matches NN/NN/N, where N = 0-9, which matches the date format that your lines start with, and will split on that match.

share|improve this answer

Use the v with join.


Broken down:

  • :v select any lines that do not match regular expression
  • /^[0-9]/ any line starting with a digit
  • -1, the previous line to the current line
  • join combine the lines selected, separated by whitespace
share|improve this answer

I'm talking about vim, this will not run in vi. Be aware of that.

What about


to delete all lines in buffer , which start with a number.


to highlight all lines

    :w ! paste -d ' ' -s

and after that


to go back to the starting point

share|improve this answer
It does not seems to work. Morevorer, I have stated an incorrect question. I want to join every line not starting by a number to the previous line starting with a number. – gogolb Oct 28 '11 at 13:34

please try:


and ignore error message E16: Invalid range

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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