2009/5/19 Raúl Núñez de Arenas Coronado:
>
> 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

Don't know if you've thought about it, but an <expr> map might be suitable...

nnoremap <expr> <Enter> SuperEnter()
inoremap <expr> <Enter> SuperEnter()

function! SuperEnter()
  if match(getline('.'), "some context") < 0
    return "\<CR>"
  endif

  echomsg "Magic!"
  return ""
endfunction


At least, this seems to work well for the constraints that you
outlined above.  It may not work depending on what the "magic" is,
though, since <expr> maps are executed with a textlock.

~Matt

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply via email to