3

In some keyboard, < and > are painful to hit. This is why I've remapped these 2 characters respectively to aa and pp

inoremap aa <
cnoremap aa <
inoremap pp >
cnoremap pp >
onoremap aa <
onoremap pp >

The problem is this binding doesn't work in the operator pending mode. Consider this example where _ is my cursor:

<tag> _foobar </tag>

I want my cursor to go to the <, so I hit faa but vim understands my command as : fa + a (go to the next a, and append).

How could I change this behavior ?

Second question : I want it to be very fast, for example, if I type fa, I don't want vim to wait for a second a. So I've set a timeout:

set ttimeout
set ttimeoutlen=10 "ms

These commands don't seem working, because if I press a in insert mode and another a 500 ms after (no chrono), a < appear.

Thank you for reading

  • For the second question, I answered myself set ttimeout set timeoutlen=150 ttimeoutlen=100 – Epitouille Dec 14 '15 at 20:52
  • :h f also helps – VanLaser Dec 14 '15 at 22:38
  • 1
    IMHO, if you want a global remapping of < and >, you should do this at the OS level, not inside Vim. On Linux, this could be done with xmodmap or similar. – Karl Yngve Lervåg Dec 15 '15 at 7:27
3

What is the purpose of the :onoremap mappings ?

If you want to operate on tags without typing < or >, it and at can help you.

Here are two usage examples:

  • cit = cut the text inside the tags (change inside tags)

  • yat = copy the tags and the text between them (yank around tags)

If for some reasons, you can't or don't want to use the it and at objects and prefer aa and pp instead, here's a way to do it:

:vnoremap aa :<c-u>normal! T>vt<<cr>
:omap aa :<c-u>normal vaa<cr>

:vnoremap pp :<c-u>normal! F<v2f><cr>
:omap pp :<c-u>normal vpp<cr>

For the mappings in other modes (insert mode, command-line mode, argument of the f command), there may be other ways, but you could try adding the following code:

:lnoremap aa <
:lnoremap pp >

If I understood the help correctly, when you're in insert mode or command-line mode you will have to hit <C-^> to enable / disable those mappings (it will change the value of the 'iminsert' option):

In Insert mode and in Command-line mode the mappings can be disabled with
the CTRL-^ command i_CTRL-^ c_CTRL-^. These commands change the value of
the 'iminsert' option.  When starting to enter a normal command line (not a
search pattern) the mappings are disabled until a CTRL-^ is typed.  The state
last used is remembered for Insert mode and Search patterns separately.  The
state for Insert mode is also used when typing a character as an argument to
command like "f" or "t".

For more information, see:

:help language-mapping
:help 'iminsert'
:help i_CTRL-^
:help c_CTRL-^
:help v_it
:help v_at

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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