I'm trying to write a vim syntax file, one problem I'm dealing with is vim's regex syntax is different from most other languages(I think the one called "perl compatible regex", Python, JavaScript etc. uses mostly the same regex syntax) and so I can't use regex testers like regexpal.
What is the easiest way to try vim regexes ? Ideally what I want is two splits, in one I'll write vim regex, and the other one will have the text, and matched parts should be highlighted.
Thanks in advance.
EDIT: I added a modified version of Ingo Karkat's answer to my .vimrc
:
nnoremap <F5> mryi":let @/ = @"<CR>`r
This version also puts cursor back where it was when pressed F5 with the cost of losing mark r
.
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.
JavaScript RegExp test() The test() method tests for a match in a string. If it finds a match, it returns true, otherwise it returns false.
Do this in Vim. For syntax files, you often deal with start="^begin"
stuff. Yank the regexp via yi"
, then highlight it via:
:let @/ = @"
Of course, if you need this often, bind this to a mapping (and :set hlsearch)
, like:
:nnoremap <F5> yi":let @/ = @"<CR>
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