I'm trying to map <Esc> to turn off search highlighting in Vim. The problem is that keys simulated by the terminal with +Esc are affected.
The terminal sends characters much fast than I type. Is there perhaps a way to map key + timeout in vim?
The same question was asked 4 years ago and the answer was that it can't be done. Is this (still) true?
Mapping :nohlsearch to escape key
Your troubles are being caused by some plugin or other, native vim handles this fine. Start vim with vim --noplugin, or if that's not enough then bypass your vimrc with vim -u NONE (or gvim -U NONE) and :source this:
set nocp " life's too short for pure vi-compatibility mode
set timeout ttimeout " enable separate mapping and keycode timeouts
set timeoutlen=250 " mapping timeout 250ms (adjust for preference)
set ttimeoutlen=20 " keycode timeout 20ms
nno <ESC> :nohls<CR>
I've never seen and can't reproduce the interference you're describing so I don't know what's causing it, all I can suggest is binary search with your plugin set.
Yes, it's still not possible for the reason given by ZyX in his answer.
<Esc> is "special" because its behavior sits between a "normal" key like a (you can map it to whatever you want) and a modifier key (it's used by the terminal to represent a lot of special keys like <Up>).
Safely mapping <Esc> to do anything else/more than <Esc> is possible but you'll have to noremap all the affected keys. Here is what I have in my vimrc to mitigate that side effect:
nnoremap <Esc>A <up>
nnoremap <Esc>B <down>
nnoremap <Esc>C <right>
nnoremap <Esc>D <left>
inoremap <Esc>A <up>
inoremap <Esc>B <down>
inoremap <Esc>C <right>
inoremap <Esc>D <left>
Related
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>
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.
I'd like to use gvim to view files with long lines. It's a table, so I'm not wrapping the lines.
Is this possible to configure gvim so arrows navigation will be like in "most" tool? Arrow key will move the whole screen 1 character lef/right/top/bottom?
Thanks a lot.
I think this should do what you want.
set nocompatible
set nowrap
set virtualedit=all
nnoremap <Left> zh
nnoremap <Right> zl
nnoremap <Up> <C-y>
nnoremap <Down> <C-e>
If you want the same behavior in insert mode, add the same mappings again as a second set, but use inoremap instead of nnoremap.
The virtualedit setting will allow the cursor to move beyond the end of the line and continue on as if the line had infinite whitespace to the right.
NOTE: virtualedit is only available if Vim was compiled with that feature. You can check with :version. If this feature is available, you should see a + next to it, e.g. +virtualedit.
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
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>