Autocmd to have a mapping only for a specific file

35 views
Skip to first unread message

av

unread,
Apr 23, 2015, 3:25:11 AM4/23/15
to vim...@googlegroups.com
Hi,

I try to have an autocommand that would provide a mapping to the <enter> and <c-enter> keys only on a certain file name. Like myfile.txt for example.

I have tried a test like this here, and it works for the <c-Enter> mapping but not for the <Enter> one:

autocmd! BufNewFile,BufRead,BufEnter myfile.txt nmap <buffer> <Enter> :echo 'Hi!'<cr>
autocmd! BufNewFile,BufRead,BufEnter myfile.txt nmap <buffer> <c-Enter> :echo 'Test!'<cr>

And when I do :map <enter> vim says that there are "No mapping found"

Any ideas why? And please tell me if I chose the right list of events.

Thank you very much,

Alexandre

av

unread,
Apr 23, 2015, 6:50:45 AM4/23/15
to vim...@googlegroups.com
It seems I cannot use <Enter> and <c-Enter> at the same time, only one of the 2 works. Why is that?

Thanks,

Alexandre

Christian Brabandt

unread,
Apr 23, 2015, 6:55:52 AM4/23/15
to vim...@googlegroups.com, av
Am 2015-04-23 12:50, schrieb av:
> It seems I cannot use <Enter> and <c-Enter> at the same time, only one
> of the 2 works. Why is that?

http://vimhelp.appspot.com/vim_faq.txt.html#faq-20.5

Best,
Christian

Charles Campbell

unread,
Apr 29, 2015, 11:04:59 AM4/29/15
to vim...@googlegroups.com
Go into insert mode.

Type ctrl-v [return]
Type ctrl-v ctrl-[return]

You'll likely find that there's no difference between them.

Regards,
Chip Campbell

alexandre viau

unread,
Apr 30, 2015, 3:36:44 AM4/30/15
to vim...@googlegroups.com
But even if i put backspace instead of ctrl-enter it will not be executed, only one of the mapping is executed
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/y9qYhazt1Ls/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Charles Campbell

unread,
May 28, 2015, 1:22:20 PM5/28/15
to vim...@googlegroups.com
alexandre viau wrote:
> But even if i put backspace instead of ctrl-enter it will not be
> executed, only one of the mapping is executed
> Le mer. 29 avr. 2015 à 17:05, Charles Campbell
> <Charles.E...@nasa.gov <mailto:Charles.E...@nasa.gov>> a
Do the same thing with ctrl-v [backspace] and ctrl-v ctrl-[backspace].
Under gvim I do get a difference (<BS> vs <C-BS>) but not under vim.
btw, bottom posting is preferred on this list.

clearer
writing
makes
it

Regards,
Chip Campbell

Reply all
Reply to author
Forward
0 new messages