Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A setting to disable default mappings #20

Open
mawkler opened this issue May 19, 2020 · 8 comments
Open

A setting to disable default mappings #20

mawkler opened this issue May 19, 2020 · 8 comments
Assignees

Comments

@mawkler
Copy link

mawkler commented May 19, 2020

By default, this plugin hijacks <leader>f and <leader>r in normal mode and insert mode. The insert mode mapping makes this plugin unusable for anyone who has for instance has <leader> mapped to <space>.

There should definitely be a setting for disabling default mappings.

@alerque
Copy link
Member

alerque commented May 19, 2020

There should already be a way to handle this. If you create your own bindings to the plugin's functions first, the plugin won't add its default ones. It only adds them if it finds that there are no existing bindings. There are two commands in two modes for a total of four bindings that get created in none others exist. The defaults are:

imap <buffer> <Leader>f <Plug>AddVimFootnote
nmap <buffer> <Leader>f <Plug>AddVimFootnote
imap <buffer> <Leader>r <Plug>ReturnFromFootnote
nmap <buffer> <Leader>r <Plug>ReturnFromFootnote

If you map those functions to your own keys (you can use anything it doesn't have to involve the leader at all) you should get the effect you want. If you don't want a binding at all bind it to something impossible.

I agree that is less than ideal and a documented way to suppress this (particularly the insert mode bindings) might be useful. I'd be happy to review and merge any contribution that took this on.

@alerque
Copy link
Member

alerque commented May 19, 2020

Also if you could review #17 that might be useful. I proposed some changes particularly to the insert maps and simplifying to have fewer bindings by default, but we never really agreed on whether my proposal was an improvement. Feedback would be great.

@m040601
Copy link

m040601 commented May 26, 2020

this plugin hijacks f and r in normal mode and insert mode.

I can fully understand the OP concern, and me too, I want to decide and control for my self which bindings this plugin uses. In particular the "precious" Leader mappings.

... If you create your own bindings to the plugin's functions first, the plugin won't add its default ones. It only adds them if it finds that there are no existing bindings.

Yes, this does work in fact seems to work, in some cases.
Could you add this information the the markdownfootnotes.txt in the docs ? It should be made prominent.

I tried 2 different cases:

  1. The first case, simple 2 char mappings. This works. Some examples:

Say you already have other plans for Leader f and Leader r. This change works:

imap <buffer> <Leader>n <Plug>AddVimFootnote
nmap <buffer> <Leader>n <Plug>AddVimFootnote
imap <buffer> <Leader>b <Plug>ReturnFromFootnote
nmap <buffer> <Leader>b <Plug>ReturnFromFootnote

Another example with a simple letter, say "g". Just as illustration example. A bit silly, i know, and besides "gn" and "gb" have other (meanings in normal mode:

imap <buffer> gn <Plug>AddVimFootnote
nmap <buffer> gn <Plug>AddVimFootnote
imap <buffer> gb <Plug>ReturnFromFootnote
nmap <buffer> gb <Plug>ReturnFromFootnote

Another interesting variant is making use of "]" and "[". This is what the very wise Tim Pope does, with the Vim unimpaired mappings, https://github.com/tpope/vim-unimpaired. I checked and, for ex. the letter "r" is still "free". So this could make a sensible solution without conflict with other plugins:

imap <buffer> ]r <Plug>AddVimFootnote
nmap <buffer> ]r <Plug>AddVimFootnote
imap <buffer> [r <Plug>ReturnFromFootnote
nmap <buffer> [r <Plug>ReturnFromFootnote

Related issues:
#15
#17

This variant is interesting. Very low cognitive overload. "]" do something, go forward etc, and "[" do the opposint, go back etc. One could even use it to do the same mapping for visual mode.
Say you have already wrote most of your text, you are kind of past insert mode. You are editing, mainly in normal mode. Shuffling things around. On your main text body, you found something that is "too much" and want to move it from the main body to a text note at the bottom. You want to do this by visually selecting it.

A possible visual mapping for this plugin, markdownfootnotes, if this was supported:

vmap <buffer> ]r <Plug>MoveSelectedToVimFootnote
vmap <buffer> [r <Plug>MoveVimFootnoteBackToMainText

Just a small additional question about the "noremap" thing. Pardon my vim ignorance. If I instead do:

inoremap <buffer> <Leader>n <Plug>AddVimFootnote
nnoremap <buffer> <Leader>n <Plug>AddVimFootnote
inoremap <buffer> <Leader>b <Plug>ReturnFromFootnote
nnoremap <buffer> <Leader>b <Plug>ReturnFromFootnote

this doesnt seem work anymore. The plugin will add its default mappings, and mines won't work. Why ? I've always been told that it's "best" to choose the "noremap" thing.

  1. Now the second case, 3 chars mappings.

It' doesnt seem to work. Say for example I want to "save" and not "waste" Leader mappings. I choose to "reserve" \n as a prefix to this plugin.
If I add this to my vim/nvim config:

imap <buffer> <Leader>nf <Plug>AddVimFootnote
nmap <buffer> <Leader>nf <Plug>AddVimFootnote
imap <buffer> <Leader>nr <Plug>ReturnFromFootnote
nmap <buffer> <Leader>nr <Plug>ReturnFromFootnote

It doesnt seems to work. It keeps getting only the first note

@mawkler
Copy link
Author

mawkler commented May 27, 2020

There should already be a way to handle this. If you create your own bindings to the plugin's functions first, the plugin won't add its default ones

@alerque How would I go about to simply disable the insert mappings? Could this be done without remapping <Plug>AddVimFootnote and <Plug>ReturnFromFootnote to some obscure key in insert mode?

@alerque
Copy link
Member

alerque commented May 29, 2020

No, I don't think that can be done right now. It should be possible (hence this issue being open!).

@alerque alerque self-assigned this Jun 7, 2020
@Konfekt
Copy link
Contributor

Konfekt commented Sep 9, 2020

I currently work around it by

imap <SID>(DisableAddVimFootnote)     <Plug>AddVimFootnote
imap <SID>(DisableReturnFromFootnote) <Plug>ReturnFromFootnote
nmap <SID>(DisableReturnFromFootnote) <Plug>ReturnFromFootnote

augroup epnMarkdownFootnote
  autocmd!
  autocmd FileType markdown inoreabbrev afn <c-o>:<c-u>exe "normal \<Plug>AddVimFootnote"<cr>
augroup end

@mawkler
Copy link
Author

mawkler commented Sep 13, 2020

Here's another workaround. Remap it to <F13> and <F14> in insert mode (valid keys that aren't on most keyboards):

imap <buffer> <F13> <Plug>AddVimFootnote
imap <buffer> <F14> <Plug>ReturnFromFootnote

I would prefer a builtin feature to simply disable the insert mode mapping, but this seems to do the trick.

@falko-strenzke
Copy link

Please note that the imap mappings leads to the following unintended and highly undesirable behaviour:
Typing "\r" in a Markdown buffer causes that buffer to be closed immediately with Vim exiting if that was the only open buffer. This will lead to loss of unsaved data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants