VIM: Join Lines

I had a document where I wanted to join every other line.  I tried several approaches on a Windows box using Cygwin but only one worked with a couple variations.  Using the vim editor.  This is a new trick to me, and wanted to jot it down before I forget about.

The file looked something like this.

10.10.10.10
a.com
10.10.10.11
b.com
10.10.10.12
c.com

One approach was to open the file with vim.

Open file in vim vim filename, then execute command :% normal Jj

This command is quit easy to understand:

  • % : for all the lines,
  • normal : execute normal command
  • Jj : execute Join command, then jump to below line

After that, save the file and exit with :wq

A variation to that approach.

Execute the command in shell, vim -c ":% normal Jj" filename, then save the file and exit with :wq.

My approach, a variation to the last one.

Execute the command in shell, vim -c ":% normal Jj" filename -c ":wq"

vim -c ":% normal Jj" filename -c ":wq"

The result

10.10.10.10 a.com
10.10.10.11 b.com
10.10.10.12 c.com

Source(s)
https://stackoverflow.com/questions/9605232/how-to-merge-every-two-lines-into-one-from-the-command-line?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa