0

for my fortran code, I have defined:

au FileType fortran let maplocalleader = "`"   # i have tried \` as well.

For fortran filetype in vim, :echo maplocalleader is showing ` as expected.

But, then, with my keyboard mapping as(inside a ftplugin):

inoremap <localleader>wr      pr<c-r>=UltiSnips#ExpandSnippet()<cr>

or anything like this, defined localleader is not honoured. Rather the expansion is working with \.

I am unable to guess what the problem is.

Any help please?

I am in vim8

3

When you register it this way, your new autocommand will be triggered after all other autocommands registered on the same event, in particular after the one that sources your ftplugin -- I suppose you define the mapping in an ftplugin (*).

You could change that, probably by changing the order between this line and the :filetype xxxx in your .vimrc, but this is not the right solution.

Unlike what its name implies, localleader is global. Somehow, I guess it's indeed meant to be used from filetype plugins, and buffer local-mappings, but you shall define it in your .vimrc, once and for all, and for all filetypes.

(*) if the mapping is defined in your .vimrc, it has even less chances to work as you were expecting as the corresponding line would be sourced before any event is happening. IOW, the mapping would be defined before the filetype(=fortran) event happens.

  • This is what :h <localleader> says: <LocalLeader> is to be used for mappings which are local to a buffer. Example: > :map <buffer> <LocalLeader>A oanother line<Esc> – BaRud Jun 18 at 13:08
  • @BaRud, yet, it's a global (g:) variable, not a buffer-local one (b:), which implies it cannot be set in a reaction of a filetype-related event without asking for troubles -- I was making that mistake until recently ^^' – Luc Hermitte Jun 18 at 13:45
  • 1
    @BaRud when you do the map command, it uses whatever the current value of localleader or leader is, so you must change it ahead of time to take effect (ie, changing my leader after creating some maps with it does not change those maps) – D. Ben Knoble Jun 18 at 16:47
  • @D. Ben Knoble: you mean my maps in ftplugin is loded first, precede by au command in vimrc? – BaRud Jun 18 at 20:03
  • @BaRud no—steps: 1. Autocommand defined. 2. Edit fortan file. 3. Ftplugins for fortran load. 4. Autocommands for fortran fire. Do you see why the autocommand can’t affect the mappings? – D. Ben Knoble Jun 18 at 20:15

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.