I have a file with about 1000 lines. All lines begin with a seven-digit number except for the occasional line. I need to catch these lines and actually join them with the previous line.
I've managed to be able to match any line that begins with a seven-digit number by using the following regex pattern:
^\d\{7}
I can't seem to get it to match any line that does not match this pattern though, which is really what I'm after.
As a second question that I'll embed into this one. Is it possible to have any lines that match (or do not match to stay consistent with what I'm trying to do) to join themselves to the previous line (as opposed to the J command that brings the next line up to the current one)?
Thanks
In normal mode, press / to start a search, then type the pattern ( \<i\> ), then press Enter. If you have an example of the word you want to find on screen, you do not need to enter a search pattern. Simply move the cursor anywhere within the word, then press * to search for the next occurrence of that whole word.
Basic Search To go back to normal mode from any other mode, just press the Esc key. Vim allows you to quickly find text using the / (forward slash) and ? (question mark) commands. It is important to note that the search command looks for the pattern as a string, not a whole word.
Vim has several regex modes, one of which is very magic that's very similar to traditional regex. Just put \v in the front and you won't have to escape as much.
^\(\d\{7}\)\@!
This is vim's regex syntax for a negative lookahead.
If you're doing this as a mass :
command, you should be able to just do
:v/^\d\{7}/-1j
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With