2

I tried following this tip from vim wikia:

:inoremap \fn <C-R>=expand("%:t:r")<CR>

For me this doesn't make any difference to the functionality of Ctrlr% in insert mode (it still just gives the full path and file extension), so I was looking at that and some linked tips and vim help sections, to no avail.

Why doesn't this work? Should it? If so could there be something in my config or an extension that ruins it?

Somewhat tangentially, what is the \fn about? I've seen variations on this in other map commands but can't find any explanation of it. If someone could break this line down completely and explain the meaning that would be great.

1 Answer 1

3

Ah, you misread the mapping. It doesn't map <c-r>, it maps \fn. Typing \fn while in insert mode is what gets you the filename.

If you wrote it this way, perhaps it might be clearer:

inoremap <leader>fn <c-r>=expand("%:t:r")<cr>

(The default leader is \.)

1
  • Awesome. I did read help mapleader but did not get the meaning. All my bindings are <Fn> and <M-Fn> (and those are used up...) so this should come in handy all kinds of ways.
    – goldilocks
    Feb 7, 2016 at 16:10

Your Answer

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

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