I'm using the most recent version of nvim on arch.

I have sentences in my text like this

brown fox

I wish to use this format
to replace all lines starting
\nlowercase letter + rest of line with
lowercase letter + rest of line

ie shift the line starting lowercase up to be joined to the line above it, like using the "J" key.

Result should be like this

The brown fox

Want to do this for all sentences globally.

How can I do this in Vim?


I'm pretty sure a very similar question was already asked here. Anyway, here's a simple trick:


That is, for every line starting with lowercase letter join it with the previous one.

  • thanks, that is indeed a neat solution
    – Kes
    Dec 19 '20 at 12:47

This solution worked

:%s/\n\([a-z]\)/ \1/g

I am familiar with the %s///g format but had previously struggled, for whatever reason with putting regex into vim's search and replace command.
Don't know why becasue as I now see it's as easy as any other regex substitution.

  • 1
    Nice one! A few simplifications are possible: :%s/\n\ze\l/ /. I usually like to use \zs and \ze to mark start and end of match, I find them to be a lot more convenient than using groups and backreferences...
    – filbranden
    Dec 19 '20 at 16:15

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.