1

I got some output code that has random backslashes, followed by a new line. For example:

( 1-z+z^11-z^12+z^22-z^23+z^33-z^34+z^37-z^38+z^40-z^41+z^43-
z^45+2*z^46-2*z^47+z^49-z^50+z^52-z^53+2*z^55-2*z^56+z^57\
-z^59+z^61-z^62+z^64-z^65+z^66-z^67+z^68-z^69+z^74-z^76+2*z^77-2*z^78+z^79-z^82+z^83-z^84+2*z^86-2*z^87+z^88-z^91+2*z^\
92-2*z^93+z^95-z^96+z^97-z^100+2*z^101-2*z^102+z^103-z^105+z^107-z^109+2*z^110-z^111+z^114-2*z^115+2*z^116-z^117-z^118\
+2*z^119-z^120+z^123-2*z^124+2*z^125-z^126-z^131+2*z^132-2*z^133+z^134-z^137+2*z^138-z^139-z^140+2*z^141-2*z^142+z^143\
-z^146+2*z^147-z^148+z^150-z^152+z^154-2*z^155+2*z^156-z^157+z^160

I want to remove all the backslashes and newlines so that it's all on one continuous line. I was thinking the way to do this would be to move the cursor to before each backslash occurrence, and then hit delete twice. Is there a way to automate this on Vim so it searches the entire document and does it for all cases? Thanks!

2

You can substitute nothing for backslash-followed-by-newline throughout your buffer:

%s/\\\n//g

See :help :substitute.

  • When I try using this, it says that there is no \\\n – Zach Jan 24 '17 at 15:14
  • Are you using Vi as opposed to Vim? If not, are you opening the file with the correct encoding? – jjaderberg Jan 24 '17 at 20:36
  • If you have trailing spaces use %s/\\\s*\n//g – laktak Jan 25 '17 at 20:32

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.