kana / vim-submode

Vim plugin: Create your own submodes
http://www.vim.org/scripts/script.php?script_id=2467
217 stars 24 forks source link

How to use submode enter for mappings? #19

Closed kshenoy closed 10 years ago

kshenoy commented 10 years ago

Hi, I have a mapping as follows:

nnoremap <l :execute 'let &lines = &lines - 1<CR>

Is it possible to create a submode for this such that typing <l once enters the submode and all subsequent < will trigger <l?

kana commented 10 years ago

How about this?

nnoremap <Plug>shrink  :<C-u>let &lines -= 1<CR>
call submode#enter_with('sizing', 'n', '', '<lt>l')
call submode#map('sizing', 'n', 'r', '<lt>', '<Plug>shrink')
kshenoy commented 10 years ago

Thanks, that worked. Can you clarify what exactly the role of the 5th argument in the enter_with function is? If I don't specify that does it just enter the submode without doing anything or enter the submode and execute whatever is specified as the 4th argument?

Also, is it possible to treat the repeated edits made when in a submode as a single change so that a single undo can revert the change?

kana commented 10 years ago

It might be achieved by correctly using :undojoin for all submode key mappings. But it seems to be too hard to implement such behavior.