1

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

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.

5
  • I was hoping for some formal all-inclusive solution, e.g. to get Tab as <Tab>, etc. Is there something like this?
    – igorepst
    Commented 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
    Commented Jun 20, 2018 at 7:24
  • 1
    That's a pity. Let's wait for other answers before I accept yours
    – igorepst
    Commented 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
    Commented Jun 21, 2018 at 21:00
  • Good, didn't think of that
    – igorepst
    Commented Jun 22, 2018 at 16:07

Your Answer

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

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