46

Vim ships with a macro called matchit that does this for you; all you need to do is activate it with runtime macros/matchit.vim in your vimrc. This will enable you to jump from, eg, a <div> to its </div>. Note that your cursor will have to be inside the angle brackets; if you're on the angle brackets, % will jump from one bracket to the other as ...


26

You can jump between tags using visual operators, in example: Place the cursor on the tag. Enter visual mode by pressing v. Select the outer tag block by pressing a+t or i+t for inner tag block. Your cursor should jump forward to the matching closing html/xml tag. To jump backwards from closing tag, press o or O to jump to opposite tag. Now you can either ...


12

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 the line numbers. Explanations are in the script's comments. matchlines.vim function! s:get_match_lines(line) abort let lines = [] " Loop until `%` ...


9

I don't think there's any way to do this, however a better approach in this case would be to leverage vim's folding to fold away part of the code between the structures you're interested in and that can make it a lot more easy for you to visually see the matching brackets. You can also use % to jump between the start & end parenthesis too to get a fair ...


9

Especially for mapping purposes, I find using getline() more elegant than doing the yanking yourself. Calling getline() with a string '.' returns the line under the cursor. There are two good options for using this: :exec '/' . getline('.') which parses the strings '/' and what is returned from getline() together and executes that as a vim command. or /&...


7

Here's how I'd do it: Yank the line (into the unnamed register), without including the newline at the end: 0y$ Initiate a very nomagic search: /\V Add the yanked line: <c-r>" Fire off the search: <cr> As @EvergreenTree points out in a comment, you can of course create a mapping to perform all the steps in one go: nnoremap <leader>* 0y$/\...


6

What you ask is possible, but the solution is nontrivial. Both LaTeX-Box and vimtex has implemented solutions for this, see here: LaTeX-Box/ftplugin/latex-box/motion.vim:57 (s:FindMatchingPair) vimtex/autoload/vimtex/motion.vim:303 (s:highlight_matching_pair) These functions are run by autocommands whenever the cursor is moved, see here (LaTeX-Box) and ...


6

The slowness of delimiter matching is not caused by vim itself but by the matchparen plugin, which is part of the vim distribution and loaded by default in /etc/vim/vimrc in Debian. (This is why I still had the problem without a vimrc.) Fortunately the matchparen plugin supports a timeout when looking for matches, so the slowness can be avoided by setting ...


5

One approach might be to use syn* functions. Something like: fun! Qtx(qt) let x = synIDattr(synIDtrans(synID(line("."), col("."), 1)), "name") if x != "String" && x != "Comment" && x != "Constant" return a:qt . a:qt endif return a:qt endfun inoremap <silent> <expr> ' Qtx("'") inoremap <silent> <...


5

If your emails have a particular file type, you could use BufRead or BufNewFile or FileType to turn off some matchpairs automatically: au BufRead,BufNewFile *.email set mps-=<:>


5

Well, here is my explanation: there are restrictions on multi-line patterns for syntax highlighting: \zs cannot be used if it makes it jump to a line which is not where the pattern started: :helph syn-multi-line And here is a neat workaround with the keyword contains highlight link SubGroup Error syntax match SubGroup '\<subname\>' contained syntax ...


5

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 type of parenthesis by changing { to [ or whatever. It's worth taking a little time to learn text objects as they make vim a lot more powerful! See :h text-...


5

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 this does what you asked for, but it might also do much more than what you asked for because you didn't provide a lot of detail about what exactly you want to ...


4

Personally I would get a visual star plugin (there are few out there). There is a nice Vimcast about this: Search for the selected text. This means you can select the line visually and then press *. If a plugin isn't your thing you can add the following mapping to your vimrc: xnoremap * :<c-u>let @/=@"<cr>gvy:let [@/,@"]=[@",@/]<cr>/\V<...


4

The existing answers all fail if your line contains certain items that are interpreted as a part of a pattern. The \V point gets most of the way there but still messes up with the backslash. Try this to escape the backslashes... /\V<C-R>=escape(getline('.'), '\') And then if you're using it in a mapping you'll need one or two <Enter>s at the ...


4

You should try Rainbow Parenthesis : Highlight matching parens in a rainbow of colors (or one of its clones): This script highlights matching parenthesis with a rainbow of colors. This make it visually very obvious which matches what. Most useful for Lisp. It highlights all the parenthesis, not only the one before the cursor. Nonetheless, it could ...


4

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 command. (:h i_CTRL-O) II) Use the built-in motion command: In normal mode f+character goes to the next character (:h f). For example: "foo bar| baz" In ...


4

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 opening [. \+ means "one or more".


3

Your $ match is ignored, % searches forward for the first character in a pair that it knows about: so it finds { and then the matching }, and moves between them. From :h mps: Only character pairs are allowed that are different, thus you cannot jump between two double quotes. One solution would be: to use the 'matchit' plugin (which allows for ...


3

The xmledit (http://vimawesome.com/plugin/xmledit) plugin allows to jump between open and close tags using <localleader>% Often <localleader> will be \, so you can jump with \% NOTE: Unlike matchit, you don't have to put your cursor inside the tag. Placing it right on the < or > is perfectly fine for the xmledit plugin. :) NOTE 2: A drawback ...


3

It is hard to match balanced parentheses with regular expressions, but fortunately, Vim has built-in motions for ( and {. See :help [( and :help [{.


3

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 match: :%s/\%(( \|, \)\zs\(.\{-}\)\ze\%( )\|,\)/<\1>/g Here i also changed the first and third captuting groups to non-capturing as we don't need to ...


3

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 used with other possible pairs like _ and * in markdown, * and | in vim help files, we have to use search() twice searchpairpos() returns a byte offset and not ...


3

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 the former with the latter matched your example string. That is: \\todo{\_.*}


2

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 searches for the 1st delimiter in the list, goes after it and appends a comma. So it roughly goes out of the "most inner" delimited group. If I'd use such a map, I'd ...


2

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 and works even when the line includes slashes. So to make, say, \* map to a line search: nnoremap <leader>* :set hlsearch<cr>:let @/=getline('.')&...


2

One more way to do this is using the command-line window: yy/<Ctrl-F>p<Enter> Yank the whole line you need with yy Press / and then Ctrl-F to open command-line window Press p to paste the line Press Enter to start the search


2

With vim-asterisk installed just use V$* (or 0v$*) to select the current line and search for it. In the second command 0 is not necessary if the cursor is already on the start of the line.


2

As it has been said, you'll have to check the syntax-context. The old lh-brackets API provides functions for that purpose: Map*Context() functions. Since then the brackets definitions has been encapsulated in :Bracket which will take the context (strings or comments) into consideration. By default context aware mappings are defined for all the usual ...


2

I am not sure if I understand you correctly and you didn't provide an example, how it is supposed to look afterwards. So here is how I would do, what I think you want to be done: :g/\\textstyleMTConvertedEquation{/:exe ":norm! 0dt{c%$\<C-R>\"$" You might need to remove the extra brace before/after the '$', which could be done in a single step like ...


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