Vim: Remove mapping created by vim-plugin - vim

I use the Vimwiki-Plugin a lot, but remapping <Backspace> and <CR> is just anoying. If I use :nmap, the mapping is shown:
n <CR> #<Plug>VimwikiFollowLink
n <Backspace> #<Plug>VimwikiGoBackLink
If I try to remove tha mapping with :nunmap <CR> I get an "E31: No such mapping" error. Is there a way to give <CR> and <Backspace> its's normal behaviour back?

if you want to just disable it, you could give
:nunmap <buffer> <CR>
because it is a buffer-local mapping.
or
:h vimwiki_<cr>
you found:
<CR> Follow/create wiki link (create target wiki page if
needed).
Maps to |:VimwikiFollowLink|.
To remap: >
:nmap <Leader>wf <Plug>VimwikiFollowLink
if you remap that to another key, e.g. the keys in example <leader>wf, the <cr> would be reset to normal.
because in its code, vimwiki has:
if !hasmapto('<Plug>VimwikiFollowLink')
nmap <silent><buffer> <CR> <Plug>VimwikiFollowLink
endif
same for the <BS>

Related

vim mapping problem in vimrc file but can not find the mapping that I set

I am using vim-markdown-toc plugin(successfully installed) and want to remapping some hotkey to specific function. I export this code autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked to my .vimrc file. But when I type :verbose imap <C-x>, it shows can not find the mapping.
Can anyone tell me what's the problem about this?
and also I also want to ask how to map one hotkey to multiple function?
autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked
has two obvious errors:
noremapb should be noremap, without the b:
noremap <silent> <C-x> :GenTocMarked
There should be a <CR> at the end:
noremap <silent> <C-x> :GenTocMarked<CR>
The right-hand-side of a mapping is a macro: since you press <CR> to execute the command :GenTocMarked, it should be present in the RHS.
Then comes the diagnostic mistake: the :map command, and its non-recursive buddy :noremap create mappings for normal, visual, and operator-pending modes, but :imap prints out insert mode mappings so you can't really expect it to find a mapping created with :map.
Then comes the semantic mistake: the re in noremap is part of nore (short for non-recursive), not of remap. <C-x> is not a mapping so you are not "remapping" anything.
Then comes the scoping mistake: :noremap creates mappings for three modes, which is something you probably don't want. You should be more specific:
" normal mode mapping
nnoremap <silent> <C-x> :GenTocMarked<CR>
and, finally, the autocommand abuse mistake: there already is a built-in mechanism for sourcing filetype-specific config so there is no need to reinvent the wheel in your vimrc:
" in after/ftplugin/markdown.vim
nnoremap <buffer> <silent> <C-x> :GenTocMarked<CR>

Remapping <ESC> breaks <S-TAB> mapping in vim

I had the following mapping on my vimrc
nnoremap <TAB> gt
nnoremap <S-TAB> gT
Then I mapped ESC to clear highlights as:
noremap <silent> <ESC> :noh<return>
And then <S-TAB> wont work anymore. If I remove <silent> from <ESC> mapping I see :noh when I press <S-TAB>. I don't know if <S-TAB> and <ESC> has something in common. I'm on Linux, using vim on gnome-terminal.
You're right in assuming that <S-TAB> and <ESC> have something in common. S-TAB is an escape-prefixed keycode.
The ESC keycode is ^[, while S-TAB is ^[[Z. You can see the first part of the S-TAB key code matching the ESC keycode.
See a full table of combinations here.
So you just can't remap the escape key while also remapping one of the key codes including it. Either pick a different key to clear highlights or a different way of switching tabs.

Why nnoremap doesn't work with CtrlP and nmap does work? - VIM

I have this in my .vimrc
nnoremap <leader>p :CtrlP<CR><C-\>w
I change all nmap to nnoremap in my .vimrc and everything works fine except this one:
nnoremap <leader>p :CtrlP<CR><C-\>w
With nmap <leader>p :CtrlP<CR><C-\>w it does automatically insert word into CtrlP and with nnoremap it doesn't, I get blank field, like I just pressed Ctrl-P.
Why it doesn't work with nnoremap?
When you create a mapping with nnoremap, it does not consider your prior mappings when resolving what to do. In other words, if you had previously mapped any of these:
<CR>
<C-\>
w
Then those maps would be ignored in your <leader>p mapping, and instead the default action of those keystrokes would be used.
As far as I know, <C-\> has no default action, so I would suspect you have mapped it (or you are relying on a mapping that another plugin has added), but that mapping is not being taken into account here.

How to remap Vim keys (PageUp and PageDown)

I want to remap <PageUp> to <C-u> and PageDown to <C-d> per the Vim scrolling documentation.
As it stands right now, my /etc/vim/vimrc looks like this:
nnoremap <PageUp> <C-u>
nnoremap <PageDown> <C-d>
I've tried a lot of different combinations and nothing I've done has worked.
My goal is to make the cursor move to the Start Of File or EOF when holding down PageUp/PageDown. As it is right now, the cursor stops before it gets all the way to the top (and PageDown scrolls past the EOF). Just annoyances I'm trying to fix.
EDIT: The above settings work fine. I was placing my mappings too early in the file.
What about the following mappings?
nnoremap <PageUp> gg
nnoremap <PageDown> G
Or simply using gg and G?
Instead of placing the mappings into the system-wide /etc/vim/vimrc, you should put user customizations into the ~/.vimrc file. Nonetheless, the global configuration (if that's what you want) should work, too. That it doesn't means that the mappings get cleared or redefined. You can check with
:verbose nmap <PageDown>
If it didn't get redefined, you have to hunt for :nunmap commands in all loaded scripts (:scriptnames), or capture a log with vim -V20vimlog.
You can do this with
map <silent> <PageUp> 1000<C-U>
map <silent> <PageDown> 1000<C-D>
imap <silent> <PageUp> <C-O>1000<C-U>
imap <silent> <PageDown> <C-O>1000<C-D>
from fixing-pageup-and-pagedown

How to always clear hlsearch on clicking enter?

Right now I am using:
nnoremap <cr> :nohlsearch<cr><cr>k
But after I press Enter my cursor goes to beginning of line.
I have additional <cr>k because I want to use default <Enter> behaviour for example when I try to open file in Ack results quickview.
If you want Enter to keep the default behavior, then this mapping should take care of it.
nnoremap <CR> :nohlsearch<CR><CR>
It turns off search highlighting, moves the cursor down, and only applies to normal mode.
An alternative approach is to locally override the new behavior in the quickfix window and the command-line window, where <CR> has special meaning:
:nnoremap <CR> :nohlsearch<CR>
:autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
:autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR>

Resources