1

I have the following line in a vim plugin:

nn <silent> <LocalLeader>E :call HOLSelectTactic()<CR>-Vo+

:help helped me in understanding lots of details, I list them to check if they were true:

  • nn means nnoremap, a command for normal mode
  • <silent> means that the command will not be echoed on the command line
  • <LocalLeader> is the h letter in this plugin, the letter every two-letter command starts with
  • E is for command hE
  • HOLSelectTactic is the VimL function being called

What is not clear is the end of line. What type does a VimL function return? What does a Carriage Return and -Vo+ does? What kind of commands are these?

5

What you are creating with the maps commands are mappings (:h key-mapping) which are used to change the meaning of typed keys. Very concretely what you command does is to say to Vim "When I type the keys <LocalLeader> followed by shift+e then consider that I actually pressed the following keys: :call HOLSelectTactic()<CR>-Vo+

So let's take your questions one by one:

  • nn means nnoremap

    That is true. A general advice is to always use the long form in your vimrc to improve readability. More specifically nnoremap can be described like this:

    nnoremap
         map        We are creating a mapping
    n               It will be a mapping only active in normal mode
     nore           It will be a non recursive mapping
    

    A non recursive mapping means that all the keys in the right hand side of the mapping (:call HOLSelectTactic()<CR>-Vo+) will be interpreted with their built-in meaning. Even if you remapped : or c or V Vim will ignore these mappings. Most of the time this is what you want to use (unlike nmap which is recursive).

  • <silent> means that the command will not be echoed on the command line.

    Right again: :h :map-silent says To define a mapping which will not be echoed on the command line, add "<silent>" as the first argument this means that you will not see :call HOLSelectTactic()<CR>-Vo+ in the command line when you use your mapping

  • <LocalLeader> is the h letter in this plugin

    If the plugin author defined it as h then it is true. However you can change its value with :h maplocalleader (Maybe you'll need to put that in a ftplugin to change it only for the concerned filetype :h ftplugin)

  • <LocalLeader> is the letter every two-letter command starts with.

    That is not necessarily true: it is possible to create two letters mapping without a local leader. A useless example:

    nnoremap aa :echo 'foo'<CR>
    
  • E is for command hE

    A mapping command is composed of optional arguments, a left hand side and a right hand side:

    nn <silent> <LocalLeader>E :call HOLSelectTactic()<CR>-Vo+
    nn                                                         the map command
       <silent>                                                the optional arguments
                <LocalLeader>E                                 the left hand side
                               :call HOLSelectTactic()<CR>-Vo+ the right hand side
    

    So <LocalLeader>E is the left hand side which describe which keys will trigger the right hand side. In both the left hand side and right hand side you can use a specific syntax to refer to some keys: <localleader> and <leader> are aliases to other keys, <CR> is the Enter key, <F1> is the Fn1 key see :h keycodes for a complete list. Here <LocalLeader>E it is indeed hE.

  • HOLSelectTactic is the VimL function being called

    True but incomplete. The function HOLSelectTactic will be called because the mapping will simulate the key presses :call HOLSelectTactic()<CR> this is the exact keys you would press when you want to call the function manually. Here <CR> is used to validate the command Vim just wrote in the command line.

    If you create the following mapping:

    nn <silent> <LocalLeader>E :call HOLSelectTactic()
    

    You will see that pressing <LocalLeader>E will write call HOLSelectStatic() in the command line and do nothing else since you didn't pressed <CR>

    That means that -Vo+ is on the same principe: They simulate you pressing -shift+vo+ after calling the function.

What this does is

-          Go one line up
V          Start linewise visual selection
o          Move the cursor to the other end of the selection
+          Go one line down

Which essentially means that you visually select the current line and the next one.

Finally for your question about what is returned by a vimscript function: Like in most other programming languages functions can return anything they want to. But here it is not really important since you do not use the returned value, you simply call the function and then continue to execute other normal mode commands like - or V.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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