0

I am trying to do a small plugin for vim to let me browse the clear case history of a file, but I am having trouble getting started. I need help with setting up the mapping exposed to the user.

Here is the bare minimum version of what I've done

function! s:DefineLeftKeyMaps()
    echom 'in defineLeft'
    nnoremap  <leader>k <Plug>MinimalDoSomething
endfunction


noremap <script> <Plug>MinimalDoSomething    <SID>DoSomething
noremap <SID>DoSomething :call <SID>DoSomething()<CR>

function! s:DoSomething()
    echom 'In DoSomething'
endfunction

command! InitCCTTSample call s:DefineLeftKeyMaps()

I need to set the final map exposed to the user in a function cause it will be used in a split where I open up different files (eventually using said mapping). Since it is a buffer local map i assume i need to reset it every time.

Edit: The problem with the above solution was that even thou the mapping was it didn't do anything.

:map reported:

....
....
\k     * <Plug>MinimalDoSomething
....
....

The reason was that I used noremap instead of map, so the subsequent mapping to the function call was ignored

Cheers

2 Answers 2

2

<plug>-mappings are difficult to define as buffer local mappings. Indeed the end-user cannot define them in their .vimrc, and to define them in a ftplugin, that'll mean you'll need to associate a filetype to your split buffers.

You'll need to provide a hook to the end user. I see two solutions

  1. Provide a function where the end user will be able to register her/his preferences in their .vimrc.

    " .vimrc
    call your#plug#tune_mappings({'<Plug>MinimalDoSomething': '<localleader>left'})
    
  2. Expose a User Event for the user to do stuff (like defining the mappings) when you trigger the event from your plugin.

    " .vimrc
    augroup YourPlugUser
      au!
      au User TuneKeyBindings let b:maplocalleader = ',,'
      au User TuneKeyBindings nmap <buffer> <localleader><left> <Plug>MinimalDoSomething
    aug END
    
    " your plugin
    split yourplug://foobar
    doautocommand User TuneKeyBindings 
    if !hasmapto('<Plug>MinimalDoSomething, 'n')
      nmap <buffer> <leader>k <Plug>MinimalDoSomething
    endif
    
Sign up to request clarification or add additional context in comments.

2 Comments

I appreciate you taking your time to answer me and would like to express my gratitude. Thank you! My issue, however, was actually a lot simpler so ill provide the answer myself in case somebody else has the same problem
Indeed I missed that. BTW, I doubt you really want to define a global mapping as it should be restricted to the new split/scratch buffer.
0

The reason it doesnt work is because I used nnoremap <leader>k <Plug>MinimalDoSomething rather than nmap <leader>k <Plug>MinimalDoSomething

Cheers

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.