Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

In a question about jVi and its capability to parse .vimrc, the author gives an example of a complex vim binding that he asserts jVi would not be able to handle:

inoremap hh <c-o>?\%<c-r>=line('.')<Return>l\({}\\|\[]\\|<>\\|><\\|()\\|""\\|''\\|><lt>\)?s+1<Return>

I wonder what (mostly how) it does. So far I get:

  • <c-o> : execute one command in normal mode and return to insert mode
  • ?/%n : look backwards for a character with the specified dec / hex code
    • what is the point of inserting the line number here?
  • the last part looks for a specific combination of brackets and places the cursor there
    • I don't understand how l can be used like that

Care to clarify?

add comment

1 Answer

up vote 4 down vote accepted

The Ctrl+O is as you indicated. And the first ? does start a backwards search.

A pattern sequence like \%15l restricts the search to line 15, the l after the first <Return> is the end of such a sequence. The mapping uses Ctrl+R, the special = register (:help i_CTRL-R), and the expression line('.') to insert the current line number into that sequence, preventing the search from going to a different line.

The rest of the mapping up to the final ? character is a fairly straight forward regular expression to match any of a number of character sequences.

The final ? indicates the end of the pattern, the s+1 portion causes the cursor to be positioned 1 character after the start of the match (:help search-offset).

I appreciate the :help references. –  Ярослав Рахматуллин Mar 15 '13 at 18:21
add comment

This site is currently not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .