I am currently using vim editor and want to customize my keys
I have learned how to map certain keys to keys by searching documentations,
but failed to find how the special keys are defined in vim.
for example, I have to use map <Esc> <CR> instead of map esc enter
I want to change ctrl key to caps lock key, but cannot find how that special keys are represented in vim editor.
Also want to change :w to something.
failed to find recommended documentations, some advice would be appreciated!
You can find all special Key notations by entering :h key-notation. :h key-codes or :h keycodes.
But Vim will not receive the press of a key Like Capslock or Ctrl (Modifiers). The OS does not pass it to vim. Vim will only know about Ctrl the moment a second key is pressed, and receive the result of them both: Ctrl+p for example is one keypress for vim.
It is the same with Capslock. Vim will just receive the modified Character. So if Capslock is on and you press a vim will not receive Capslock+a but only A because that is the result of both.
Related
When typing <Enter> in normal mode in Vim with the Tagbar plugin installed, the Tagbar window is opened automatically. I want to disable this functionality. What must I do?
put the flowing code in you .vimrc
unmap <cr>
Your mapping for <C-m> is actually the cause of the Enter key opening Tagbar. If you remove that map from your vimrc, the enter key will no longer trigger :TagbarToggle.
Mappings for <C-m> and <CR> (Enter) are synonymous in Vim:
The following table shows the mapping between some of the keys on the keyboard and the equivalent Ctrl-key combination:
Ctrl-I Tab
Ctrl-[ Esc
Ctrl-M Enter
Ctrl-H Backspace
If you use one of the Ctrl-key combination in the above table in a map, the map also applies to the corresponding key. Both the keys produce the same key scan code. For example, if you create a map for CTRL-I, then you can invoke the map by pressing Ctrl-I or the Tab key.
This means when you set nmap <C-m> :TagbarToggle<CR>, it is the same as
also setting nmap <CR> :TagbarToggle<CR>.
You'll probably want to choose a new key instead of M. The alternative is to
change the key code sent by <C-m> at the operating system level with some
remapping program.
The terminal key bindings come from readline, the program that processes input text in
your terminal prompt. A full list of key bindings is in the readline
manual.
You can find more info about Vim key codes by typing :help keycodes in Vim, or reading the help docs here.
Try :help tagbar to open the documentation. It sounds like you might have a mapping in your vimrc file that says something like
nnoremap <silent> <CR> :TagbarToggle<CR>
or
nnoremap <silent> <CR> :TagbarOpen<CR>
if you find and remove that mapping will no longer open Tagbar
i am trying to figure out vim key bindings... what key does correspond to? or more generally how do I read vim key bindings? I looked at the VIM documentation but it was not very clear.
It's Ctrl+C. See :help key-notation.
You can use #romainl's answer:help key-notation to find the notation of each modifier keys.
And you can use below commands to see the current mappings in your vim:
:nmap Show key maps for normal mode
:vmap Show key maps for visual mode
:imap Show key maps for insert mode
:map Show all the key maps
How can I remap my CTRL-A to CTRL-Q in the command line mode?
I use VIM within Tmux session (which has CTRL-A set as a prefix). When I try to insert all files which names match the pattern (i.e. for :bd command) I have to press CTRL-A twice (as it's also a prefix for tmux). I would like to use one key stroke <C-a> for that.
I've tried to put cnoremap <C-q> <C-a> to my .vimrc but it doesn't work. Any suggestions?
This works for me; note that in the terminal, Ctrl-S and Ctrl-Q are special sequences for flow control. See here for how to unconfigure that, or use another left-hand side for your mapping, e.g. <C-g>.
Thank you guys for letting me know that is special key, I wasn't aware of that.
In that case I decided to use different key (<C-b>). Key map for that:
cnoremap <C-b> <C-a>
I know that <C-b> is for scrolling but I guess in command line mode it should be ok to use that key.
I want to map the Home button so vim goes to the first non blank character in vim. But mapping the home button doesn't do anything? If I map another key, then it works correctly.
See below my vimrc file:
map <Home> 0w
imap <Home> <ESC>0wi
The above doesn't work. While the following works (Ctrl-F for example)
map <C-f> 0w
imap <C-f> <ESC>0wi
Isn't there a way to map Home key to this? I really need it, because I got used to this when working with Notepad++, Sublime text 2, Visual Studio,...
I also tried the following, with no results. When using another key, it works again...
http://vim.wikia.com/wiki/Smart_home
From Vim FAQ (also available through this nice plugin):
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
1) First make sure, the key is passed correctly to Vim. To determine if
this is the case, put Vim in Insert mode and then hit Ctrl-V (or
Ctrl-Q if your Ctrl-V is remapped to the paste operation (e.g. on
Windows if you are using the mswin.vim script file) followed by your
key.
If nothing appears in the buffer (and assuming that you have
'showcmd' on, ^V remains displayed near the bottom right of the Vim
screen), then Vim doesn't get your key correctly and there is nothing
to be done, other than selecting a different key for your mapping or
using GVim, which should recognise the key correctly.
This way you can check if the home key you are pressing is the same that Vim understand as <Home>.
Another possibility is that some other mapping is interfering with this one. You could try the following:
noremap <Home> 0w
inoremap <Home> <ESC>0wi
Edit:
It seems the problem is that your terminal is sending a home keycode that Vim isn't recognizing as <Home>.
I believe that the best solution is make Vim recognize that key correctly, so you can move your .vimrc to other terminals/systems without changes.
From :h xterm-end-home-keys:
On some systems (at least on FreeBSD with XFree86 3.1.2) the codes that the
<End> and <Home> keys send contain a <Nul> character. To make these keys send
the proper key code, add these lines to your ~/.Xdefaults file:
*VT100.Translations: #override \n\
<Key>Home: string("0x1b") string("[7~") \n\
<Key>End: string("0x1b") string("[8~")
If that doesn't work, you could try :set t_kh=^V^[[1~. If it work you can enclose it on a check of your terminal type.
Additional information can be found at :h terminal options
Edit 2:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
:
:
3) If the key is seen, but not as itself and not as some recognizable
key, then there is probably an error in the terminal library for the
current terminal (termcap or terminfo database). In that case >
:set term?
will tell you which termcap or terminfo Vim is using. You can try to
tell vim, what termcode to use in that terminal, by adding the
following to your vimrc: >
if &term == <termname>
set <C-Right>=<keycode>
endif
where <termname> above should be replaced by the value of 'term'
(with quotes around it) and <keycode> by what you get when hitting
Ctrl-V followed by Ctrl-Right in Insert mode (with nothing around
it). <C-Right> should be left as-is (9 characters). Don't forget that
in a :set command, white space is not allowed between the equal sign
and the value, and any space, double quote, vertical bar or backslash
present as part of the value must be backslash-escaped.
Now you should be able to see the keycode corresponding to the key
and you can create a mapping for the key using the following command: >
:map <C-Right> <your_command_to_be_mapped>
For more information, read
:h map-keys-fails
:h map-special-keys
:h key-codes
Is there any key combination that simulate the Del in Vim insert mode? For the Backspace, there is the Ctrl-H which is very convenient, and make it easier than pushing the far away Backspace button.
Take a look at http://vimdoc.sourceforge.net/htmldoc/insert.html There are a few more built-in key combinations for various tasks.
Also you can set your own mappings using .vimrc for example your given example is just
imap ^H <Left><Del>
On my vim installation, Del in insert mode Just Works. :help i_<Del>
If Del isn't doing what you want, you can try :fixdel. :help :fixdel has a good explanation of what that tries to fix.
If you simply wanted to simulate Del via another Ctrl-key mapping (e.g. Ctrl-D), I'd recommend the following mapping:
imap <C-D> <C-O>x
Ctrl-O in insert mode will allow you to run a single normal mode command and automatically return back to insert mode. x deletes the key under the cursor.
You can map keys yourself in vim, including insert mode. The following article reveals more details:
Mapping keys in VIM