Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Easiest way to test vim regex?

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.

like image 861
sinan Avatar asked Jan 24 '13 10:01

sinan


People also ask

Does vim support regex?

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.

What is regex testing?

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.


1 Answers

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>
like image 83
Ingo Karkat Avatar answered Sep 22 '22 04:09

Ingo Karkat