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?

share|improve this question

1 Answer 1

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).

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.