The answer to the question with the same title doesn't seem to work for me. Not sure if the behavior has just changed overtime.

To reproduce the issue, open Vim via vim -Nu filebelow.vim, where the first two lines are from my vimrc and the third line is from the linked answer and it should presumably allow prepending Leader to a key a in a normal command via :NormLead a.

let mapleader = "\<Space>"
nnoremap <leader>p  :pwd<CR>
command! -nargs=1 NormLead  let leader=get(g:,"mapleader","\\") | exec "normal " . (leader==' '?"1":leader).<f-args> 

Unfortunately this solution just seems to result in putting (whatever is the " register), and that's the case even if I use the command originally suggested in the comment by statox.

  • 1
    I didn't give much thought about why you don't get the expected behavior but I feel like I should mention that <leader> is a placeholder that is expanded at the time of sourcing. This means that your <leader>p mapping is actually registered as <Space>p and that g:mapleader can be changed later on without changing previously registered <leader> mappings. In other words, querying g:mapleader only gives you its current value, which might not be the same as the one used when the mapping was created. Therefore, this strategy is too brittle.
    – romainl
    Commented Sep 2, 2023 at 10:30
  • You’ve eliminated the function but continued to use f-args… does it work if you actually use the full script from the linked question, or if you use q-args?
    – D. Ben Knoble
    Commented Sep 2, 2023 at 12:08
  • @D.BenKnoble, that might apply to the update reported in the answer, but in the comment, statox writes what he says is a oneliner solution, so I expect that to have worked at some point in the past. Anyway, I'll give a shot to the full script later.
    – Enlico
    Commented Sep 2, 2023 at 12:47
  • Oh, it’s not f- vs q-args, it’s the oneliner not replicating the logic correctly. Try (leader==' '?'1'.leader:leader)
    – D. Ben Knoble
    Commented Sep 2, 2023 at 18:22
  • (If you referred to the oneliner in the answer and not that in the comment) Nope, it doesn't work: upon doing :NormLead p I get E481: No range allowed, because the attempted command line has become :.pwd.
    – Enlico
    Commented Sep 3, 2023 at 6:05


Your Answer

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

Browse other questions tagged or ask your own question.