Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
13 votes
Accepted

How can I highlight matching "%" names (e.g. if/end, for/end) defined by matchit.vim on selection?

I thought this idea was interesting, so I gave it a shot. It will be particularly useful in dense files, such as HTML. The following script simply lets matchit.vim do what it does while recording ...
Tommy A's user avatar
  • 6,780
10 votes
Accepted

How to select the content within brackets including brackets and without including brackets?

You can use text objects to accomplish this. Start a selection with v and then: For selecting inside use: i{ For selecting the whole block including braces use: a{ You can also do this with any ...
Tumbler41's user avatar
  • 7,756
5 votes
Accepted

Divide a line with curly braces that contains curly braces

Recursive macro time! qaqqa: start a macro in the register a after clearing it 0%aEnterEsc: find a whole block and add a newline after it @a: recursive invocation q@a: finish recording and run If ...
D. Ben Knoble's user avatar
  • 26.4k
5 votes
Accepted

Changing the color of delimited text

This is not too complicated. Try this: syn match delimited /\\note{\_.\{-}}/ containedin=ALL hi delimited guifg=red ctermfg=red Of course, you can change red to whatever color you want. Note that ...
DJMcMayhem's user avatar
  • 17.6k
4 votes

How move cursore "past the first paired delimiter" (quote, parentheses, etc) - searchpair()?

I) Don't create an insert mode mapping: Insert mode is made to insert characters, when you need to move your cursor you should go back to normal mode or use ctrl+o to go to normal mode for only one ...
statox's user avatar
  • 50k
4 votes
Accepted

How to match each occurrence per line?

Try: %s/_\([A-Za-z]\+\)_/=\1=/g Where [A-Za-z] matches the chars A-Z and a-z. You could add other chars between []. Note: If you want to add a dash (-), it has to be the first char after the ...
Ralf's user avatar
  • 9,237
3 votes

Remove look ahead behaviour on match brackets (%)

The only way I can see is to create your own mapping that should do what you want, for example: nnoremap <expr> % match(getline('.')[col('.')-1], '[()\[\]{}]') == -1 ? "" : "%&...
Maxim Kim's user avatar
  • 13.5k
3 votes
Accepted

Rules for 2-tier recursive syntaxes

After reading the syn-extend and the use of keepend and extend keywords, I used Error for my first region syntax and Todo for that last character after the region (semicolon). My recursive region is ...
John Greene's user avatar
3 votes
Accepted

How to match braces or brackets?

Per the help pages in Vim: \{-} matches 0 or more of the preceding atom, as few as possible * Matches 0 or more of the preceding atom, as many as possible. In my small test case replacing ...
Vitor's user avatar
  • 1,752
3 votes
Accepted

How move cursore "past the first paired delimiter" (quote, parentheses, etc) - searchpair()?

This was a tough one as: I couldn't get getpos('``<') to work searchpair*() don't work when the opening and the closing signs are not identical. Here, two cases: with strings, va' and va" can be ...
Luc Hermitte's user avatar
  • 17.4k
3 votes
Accepted

Substitute words enclosed between comma or open-parenthesis and comma or closed parenthesis

It's because your matching groups have overlap! Exept for zero-width pattern items, every charachter in your string will be consumed in the matching. so here you can use \zs and \ze to confine your ...
dNitro's user avatar
  • 401
2 votes

How to search for lines matching current line in vim

http://vim.wikia.com/wiki/Searching_for_expressions_which_include_slashes points out that the search register can be set directly, like this: :let @/='/abc/def/ghi/' This allows search on the line ...
Bernard Ogden's user avatar
2 votes
Accepted

How do you sort lines by longest substring to shortest substring?

You could use external commands to do that. Take for example, giving that the buffer has only the content you share the following commands: %!awk -F ',' '{print length($1) "|" $0}' %!sort -nr %norm ...
rbernabe's user avatar
  • 801
2 votes
Accepted

How can I stop [Neo]Vim from tracking parens in certain situations?

You are looking for matchit-zip The matchit.vim script allows you to configure % to match more than just single characters. You can match words and even regular expressions. Also, matching treats ...
laktak's user avatar
  • 2,943
2 votes

How move cursore "past the first paired delimiter" (quote, parentheses, etc) - searchpair()?

This is a simple one, you can add more delimiters in the [ ] group, but it won't check for the "inside" of anything: inoremap <C-x><C-x> <Esc>/[\])}"]/e<CR>a, It just ...
VanLaser's user avatar
  • 9,750
2 votes

Divide a line with curly braces that contains curly braces

A lot of people will likely think of using a regular expression to parse and split up those "bracket blocks" but that's problematic. Identifying recursively nested parens/brackets/braces is ...
B Layer's user avatar
  • 19.9k
2 votes
Accepted

How to use vi to batch match characters and paste after the matched characters

I think something like %substitute/\.\(\w\+\)/&(\1)/ Would do it. Assumptions: comma is not a “word” character (?), no more than one record per line.
D. Ben Knoble's user avatar
  • 26.4k
2 votes
Accepted

Remove look ahead behaviour on match brackets (%)

Since a comment under the question mentions that OP is using the plugin vim-matchup, I'll give the match-up specific solution. The plugin provides matchup#custom#define_motion to facilitate such ...
Mass's user avatar
  • 14.1k
2 votes

Remove look ahead behaviour on match brackets (%)

A possible version that hasn't been tested: const s:old_percent = maparg('%') function s:doPercent() abort if empty(s:old_percent) normal! % else execute s:old_percent endif endfunction ...
D. Ben Knoble's user avatar
  • 26.4k
2 votes

add quotes to each string and change the delimiter for a comma

You can break this up into 3 substitutions and apply them in sequence: :s/ | /", "/g | s/^/"/ | s/$/"/ s/ | /", "/g replaces all the | delimiters with the quote and ...
mattb's user avatar
  • 1,141
2 votes
Accepted

is there something like `%` but for matching double quotes

(N.B. I'm not sure if by "macro" you mean a mapping or a recording, so I've just included the keystrokes in the below, to match what you did in your question.) It might not work in general, ...
Rich's user avatar
  • 32.1k
1 vote

Searching with "/" with line limits: Is it possible to specify relative line numbers?

No, this syntax /\%>.-1l\%<.+1lPATTERN is not supported. The workaround is to calculate the expected line numbers directly and place those into the pattern: let above='\%>' .. (line('.')-1) ...
Christian Brabandt's user avatar
1 vote

is there something like `%` but for matching double quotes

One solution would be to install the target Vim plugin that extend the i" text object such that it works on multiple line (among other improvements).
Vivian De Smedt's user avatar
1 vote

Jumping to open paren with % doesn't work when open paren followed by $ and cursor is in method call experssion

OK, here's a much better fix, albeit probably not perfect. In after/ftplugin/php.vim, add the following 3 lines: let b:match_words .= '<?php:[^-]>' set matchpairs-=<:> let b:match_words = ...
StevieD's user avatar
  • 1,492
1 vote

How to match braces or brackets?

As @LucHermite already mentioned in a comment, regular expressions are not meant for recursive patterns. The solution by @Vitor does not work, as was already confirmed in the comment, because it will ...
Karl Yngve Lervåg's user avatar
1 vote
Accepted

Enable %-key jumping/highlighting for backticks (`) and single-quotes (') in M4 files

For question 1, try this: set matchpairs+=`:' See :help 'matchpairs' This requires the characters to be different, so it won't help you with question 2 (or indeed 3). For these latter two ...
Rich's user avatar
  • 32.1k
1 vote

Highlighting after a line limit

A much simpler option is to set colorcolumn=80 or whatever number(s) you want: then you have a line down the screen that shows your breakpoint.
D. Ben Knoble's user avatar
  • 26.4k
1 vote

Highlighting after a line limit

If you are not insisting on using matchadd you can try to use properties, here is the proof of concept you can play with: call prop_type_add('TEST', {'highlight': 'ErrorMsg'}) "screen jumps ...
Maxim Kim's user avatar
  • 13.5k
1 vote
Accepted

DelimitMate Plugin: How can I specify my own delimiters? Also, can I jump the cursor to the end of the generated right-delims with an insert-mode map?

Look into the delimitMate_quotes variable. The following line in your vimrc should take care of the $ sign delimiter. au FileType tex let b:delimitMate_quotes = "\" ' $" Not sure how you would go ...
Bryan Bugyi's user avatar
1 vote

How to make matchpairs not match closing '>' in "<(>)" while still matching it in "<()>"?

matchit will most probably not do this for you. You probably want to write a small wrapper function for %, which identifies the character under your cursor with: let curChar = char2nr(matchstr(...
Cbhihe's user avatar
  • 241

Only top scored, non community-wiki answers of a minimum length are eligible