3

I am looking at some plugin that happens to be configurable through a curious mapping (e.g. unite.vim):

More advanced configuration example:
>
    " The prefix key.
    nnoremap    [unite]   <Nop>
    nmap    f [unite]

    nnoremap <silent> [unite]c  :<C-u>UniteWithCurrentDir
            \ -buffer-name=files buffer bookmark file<CR>

What does the [unite] means ?

I understand that it stands for a custom leader/prefix only for the plugin, but what is it's meaning for Vim ?

6
  • 2
    The way I see it, it's a clever way to create a custom leader. If you only press f in your example, it will be resolved to [unite] (due to the nmap), which in turn resolves to <Nop>, i.e. nothing, but only after the map timeout, or if not followed by one of the defined combinations, such as c, in which case it suddenly turns into [unite]c, which resolves to the mapped command :) Basically, f turns to nothing, but fc turns to the mapped command. [unite] is just a convenient placeholder, you can use other text if you want. Vim won't interpret its characters individually.
    – VanLaser
    Mar 1, 2016 at 0:38
  • OK I see, this is indeed really clever. What about the [ square bracket ] ? Does they means "treats this as one symbol" ?
    – nobe4
    Mar 1, 2016 at 0:50
  • 2
    Nope, they are no more special than any other characters. They are for your eyes only, to look like a prefix key. :)
    – VanLaser
    Mar 1, 2016 at 0:51
  • So I can imagine nnoremap myprefix <nop> and then using myprefix anywhere ? or using {} instead ?
    – nobe4
    Mar 1, 2016 at 1:17
  • 1
    Do it, please :) There is a side-effect of choosing a certain 'prefix' - e.g. [unite] could affect a map defined in the same buffer, made from its first letters (e.g. [u) in that Vim will now wait to see if you type n after it, or not.
    – VanLaser
    Mar 1, 2016 at 8:36

1 Answer 1

2

After discussion with VanLaser, it seems that the [unite] mapping is used only with a combination of another key.

Let's break down the mappings:

nnoremap    [unite]   <Nop>

Map [unite] to nothing.

nmap    f [unite]

Map f to [unite]. At this point if we press f, nothing will happen, as [unite] is mapped to <nop>.

But when we add a [unite]-based mapping:

nnoremap <silent> [unite]c  :<C-u>UniteWithCurrentDir ...

Then the [unite]c (which will be triggered by pressing fc) will call the desired command. If the f key is pressed alone, after the map timeout, nothing will append as it will be translated to [unite] alone.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.