When using Vim you can find your <Leader>
(see :help <Leader
) by checking the value of mapleader
:echo mapleader
however there are some edge cases.
Undefined Mapleader
If mapleader
is not defined, you’ll get the message
E121: Undefined variable: mapleader
in which case your Leader is the default value, which is a backslash (\
).
Space bar as Leader
If mapleader
is set to your space bar (currently this is my preferred Leader value), you won’t see any output.
Tab as Leader
If mapleader
is set to the tab key, you won’t see any output.
A Better Way to Find Your Leader
The following command will output:
- if leader is undefined, it will display
mapleader is \ (the default value)
- if leader is space bar, it will display
mapleader is <Space>
- if leader is tab, it will display
mapleader is <Tab>
- otherwise, it will display the value of mapleader, e.g.
mapleader is ,
Command to Display Leader
:echo join([ 'mapleader is ', ! exists("mapleader") ? '\' : mapleader ==? "\<Space>" ? '<Space>' : mapleader ==? "\<Tab>" ? '<Tab>' : mapleader, ! exists("mapleader") ? ' (the default value)' : '' ], '')
Breakdown of Command
First we call echo join()
, this outputs all of the strings in the array we pass to join()
concatenated together. We pass a second parameter to join()
of ''
so there are no spaces between the parts of the string (the default value for this second parameter is ' '
). (See :help echo
, :help join
)
Then we pass a chain of inline conditionals (see :help expression-syntax
, :help exists
, :help expr-==?
, :help <>
), the logic here is
:if ! exists("mapleader")
: echo '\'
:elseif mapleader ==? "\<Space>"
: echo '<Space>'
:elseif mapleader ==? "\<Tab>"
: echo '<Tab>'
:else
: echo mapleader
:endif
Finally, we display the text ” (the default value)” for the case when mapleader is not defined.
:if ! exists("mapleader")
: echo "( the default value)"
:endif
Leave a Reply