Hi all :)
I have a doubt about remapping the "Enter" key, in the following
scenario: if Enter is pressed in certain context in normal or insert
mode, it will change some of the text, insert a <CR> and leave us in
insert mode. Outside that context, the "Enter" key should have the
default behaviour.
So far I've written the following solution (abbreviated):
nnoremap <Enter> :call SuperEnter()<CR>
imap <Enter> <C-\><C-O><Enter>
function! SuperEnter()
if match(getline('.'), "some context") < 0
" This only works for normal mode!
execute "normal! \<CR>"
return
endif
" Perform the "magic" here. Since part of the "magic" is
" to leave Vim in insert mode, this part works both for
" normal and insert mode, no problem.
endfunction
The problem is that, when we are outside the "context" and want the
default behaviour of Enter (insert <CR> in insert mode, move to the line
below in normal mode), the above only works for normal mode, not for
insert mode.
An obvious solution is to call the function with a parameter, indicating
whether it was called from normal mode or using <C-\><C-O> from insert
mode, but I don't know if that is a good solution or if a more elegant
way exists.
Which is the preferred way of doing such kind of discrimination?
Thanks a lot in advance :)
--
Raúl "DervishD" Núñez de Arenas Coronado
Linux Registered User 88736 | http://www.dervishd.net
It's my PC and I'll cry if I want to... RAmen!
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---