Given that I defined let mapleader="\<Space>", I would like to get in the vimscript the value of the leader as <Space> and not as ' '. The latter may be obtained by using get(g:,"mapleader","\\"), but how to get the former? I'm searching for a formal solution to get Tab character as <Tab>, escape as <Esc>, etc.

Thank you

1 Answer 1


You can simply use substitute():

substitute(get(g:,"mapleader","\\"), ' ', '<Space>', '')

Since there is only one case where get(g:,"mapleader","\\") will return a single whitespace this should work.

  • I was hoping for some formal all-inclusive solution, e.g. to get Tab as <Tab>, etc. Is there something like this?
    – igorepst
    Jun 20, 2018 at 7:11
  • @igorepst Maybe someone can prove me wrong but I don't think you have a built-in way to do that
    – statox
    Jun 20, 2018 at 7:24
  • 1
    That's a pity. Let's wait for other answers before I accept yours
    – igorepst
    Jun 20, 2018 at 7:36
  • 1
    I tried to come up with something by abusing nnoremap, which prints its RHS in this form. but it doesn't work for space and tab.. and just decided a look-up table is a lot simpler
    – Mass
    Jun 21, 2018 at 21:00
  • Good, didn't think of that
    – igorepst
    Jun 22, 2018 at 16:07

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.