Newline Character in Emacs
Just the other day, I found myself in a bit of a pickle. I develop a lot in jsp where I work, and on this particular day I was trying to debug a very large webform. In the webform, all the data was collected and then passed to a HashMap of field name-value pairs. The HashMap was being outputed by the excellent log4j tool into a debug file, and I needed to parse the data quickly to determine what key value pairs were causing issues.
Enter emacs.
I love to use emacs as my normal text editor, as it has many many features not found on lame notepad or wordpad included in Windows default installs. One of my favorites is replace via regexp, among others. As I mentioned before, I needed to parse the output the HashMap from log4j into readable lines so I could quickly skim them to see which fields had no data in them. I start emacs and copy and paste the data I need to inspect into emacs and call up the replace function. After about 10 minutes of hacking away, I could not figure out what emacs was expecting as a newline character. All the documentation I could find states that \n is the correct character. I tried every combination I could think of… \n \\n ‘\n’ “\n” \N \\N and on and on. I finally grew frustrated that this seemingly simple problem was so difficult. I did some searching, and low and behold, I run into another emacs user/blogger with the same problem.
I would like to thank the writer of this blog article for saving me a lot of time and doing the footwork to figure out that Cntrl-q Cntrl-j inputs the newline character into the replace field in emacs. I was about to go insane when I stumbled across it in the sea of google answers. I thought I would mention it in my blog as well, as to further purpetuate the knowledge of this “quirk”. My next mission is to find out why this key combination is the magic one.. any thoughts?