Using Vim for Tricky Regular Expressions
So, I was trying to convert an orgmode file to html. There is an orgmode-export-as-html function, but it was choking on something, so I needed to do the conversion by hand. I tried many, many times to convert the file with emacs regular expressions, but was unsuccessful. The difficulty was the orgmode headlines, which look like this:
*** Use the sort function
I wanted to simply transform this into
<h3>Use the sort function</h3>
I was finally able to match the headline in vim with the following regular expression:
Vim Substitution Expression
Testing Matching String
Its easy to test a regular expression in vim. While in command mode (hit Esc if you are in input mode), type a / and then type your regular expression and then press "return", like so:
Your matches will be highlighted. Click 'n' to jump to the next match.
Getting back to previous substitution
Vim has a cool, intuitive way to explore your command history. In command mode, type ":" as for typing an ex command, and then press the up arrow to scroll up to through your command history. This is really handy for using previous, complex regular expressions.