New answers tagged

4

You can solve that with this regex: \v(['"])%(\1@![^\\]|\\.)*\1 Which will solve all of your test cases, plus others such as "\\" or '\\'. Explaining it: \v: Use "verymagic" mode, so we don't need to backslash parens, etc. (['"]): Matches either a single or double quote and store it in \1. %(...)*: Then match zero or more of: \1@![^\\]: A single ...


2

In the department of simplified versions this may do... \v(['"]).{-}[^\\]\1 I say "may" as I wouldn't stake my life on there being zero failing corner cases but it passes your tests and and every other I've tried so far. Using "very magic" that's... (['"]) - capture a quote .{-} - non-greedy slurp (of all but two characters...see next) [^\\]\1 - match ...


0

Note: I have tested the above process in vim(not it vscode extension). It didn't worked so the answer is for general vim. Using Regular expressions The solution to the first problem is to use "very magic" mode of regex. In very magic mode the characters except a-zA-Z0-9 and _ have a special meaning. You can enable very magic mode by putting \v in start ...


2

Prior to version 8.1.0271, in order to preview searches in this way you have to adjust your workflow slightly. First, set up your regular expression by using a normal search, during which highlighting will be active: /regular<CR> Then, you can re-use the regular expression from your search command by leaving the field blank in your substitute ...


4

You can add a line break by using the atom \r in the replacement part of the :s command (while in the pattern part, you would need to use \n to match a line break). That allows to split your string using the following command: :s/,\ze \d\+=/&\r/g That is search for a comma (and end the match there), followed by a space, at least one number and a = and ...


7

This is done by setting just two options: set is hls (incremental search and highlight all matches). Make sure you've also read the appropriate help topics, excerpted below: :h 'is' While typing a search command, show where the pattern, as it was typed so far, matches. The matched string is highlighted. If the pattern is invalid or not found, ...


1

You're mixing up a few concepts... You can use <C-R> from Insert or Command-line mode (when typing an Ex command after entering it with a :) to insert the literal contents of a register. (See :help c_CTRL-R.) So you can use that in a direct mapping (without the indirection of :execute), like so: nnoremap <Leader>c :%s/<C-R>//\=Count(...


2

| is used to separate a map command from the next one, you need to escape it or use <bar> instead, read :h map-bar for further detail. Your map is unnecessarily complicated, {rhs} of a map without :h :map-<expr> is applied as typed, no need to use execute and normal in this case: nnoremap <Leader>h /\(A\<bar>B\)<cr>


0

This is a bit of a guess, but I suspect it has to with | also being the ex command separator. So execute probably mangles things, and needs to see \|, which in string form would \\\|—in other words, | needs to be escaped. Alternative ideas: :/ is an ex command that addresses the search pattern entered. If memory serves, it works rather like a normal / You ...


0

No need for a plugin, just apply the substitution command: :%s/(\(\([^()]\|\n\)*\))/[\1]/g Notes Supports multiple matches per line: (aa) (bb) -> [aa] [bb] Supports multi-line content: (aa \n bb) -> [aa \n bb] Supports nested parenthesis: ((aa)) -> ([aa]) Doesn't change unmatched characters: a) (b) -> a) [b] However it needs to be applied ...


Top 50 recent answers are included