Am 19.08.2010 14:27, schrieb Jeri Raye:
Hi,

I have certain scripts in my plugin directory. And for them I have
several mappings. Nothing special. But now I want to merge two
mappings into one.

In script 1 I have a mapping <leader>f

"{{{ mappings and default options
if !hasmapto("<Plug>SimpleFold_Foldsearch")
map <unique> <silent> <Leader>f <Plug>SimpleFold_Foldsearch
endif
noremap <unique> <script> <Plug>SimpleFold_Foldsearch <SID>FoldSearch
noremap <SID>FoldSearch :call <SID>Foldsearch("")<cr>



In script 2 I have a mapping <C-space>

nnoremap <C-space> :call ToggleFold()<CR>
inoremap <C-space> <C-O>:call ToggleFold()<CR>

I want to updated the <C-space> mapping that it does first the
<leader>f function and then the orignal function after.

But then I write this as the mapping
nnoremap <C-space> <Leader>f :call ToggleFold()<CR>
inoremap <C-space> <C-O> <Leader>f :call ToggleFold()<CR>

Nothing happens.

Question 1: Can a nnoremap and and inoremap be combined?
Question 2: Is the leader mapping causing the problem? If not what
            else might be the problem?

Alternative I can merge the scripts, but I prefer to keep them
seperated.

Issue 1:
:nnoremap <C-Space> <Leader>f...  prevents remapping of <Leader>f,
use :nmap instead.

Issue 2:
on the right hand side, each character has a meaning (including white
space)
    :nmap <C-space> <Leader>f :call ToggleFold()<CR>
    -------------------------^
instead you want
    :nmap <C-space> <Leader>f:call ToggleFold()<CR>

Issue 3:
<C-O> only executes one Normal- (or Ex-) mode command
bad :   :imap <C-space> <C-O><Leader>f:call ToggleFold()<CR>
good:   :imap <C-space> <C-O><Leader>f<C-O>:call ToggleFold()<CR>

Issue 4:
this is redundant:
    :imap <C-space> <C-O><Leader>f<C-O>:call ToggleFold()<CR>
why not use
    :imap <C-Space> <Esc><C-Space>gi

Issue 5:
You were on the right way: with some plugins installed, it's better to
use :nnoremap instead of :nmap (but :nmap also has its advantages ...).
For example, <CR> in Command-line mode is often remapped by plugins.
What I sometimes do is to define <SID> mappings for a few critical keys,
to protect them.
For example, to forbid remapping of <CR> in Cmdline-mode :

    :cnoremap <SID><CR> <CR>

and then use <SID><CR> instead of <CR> in your mappings (these mappings
must be in the same script):

    :nmap <C-space> <Leader>f:call ToggleFold()<SID><CR>

Issue 6:
given you decide to use another key for <Plug>SimpleFold_Foldsearch than
<Leader>f
    :nmap <Leader>g  <Plug>SimpleFold_Foldsearch

now you will also have to change the mapping for <C-Space>.  Thus for
<C-Space> it might be better to have <Plug>SimpleFold_Foldsearch in the
{rhs}:

    :nmap <C-space> <Plug>SimpleFold_Foldsearch:call ToggleFold()<CR>

(all untested, incomplete, no warranty, you know ...)

--
Andy

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to