Why can I map <M-w> but not <M-r> in gvim? - vim

I successfully defined a mapping to be invoked with ALT+w like so :map <M-w> ....
Yet, if I try to define a new mapping to be invoked with ALT+r like so :map <M-r> ... it doesn't work. Instead, the character ò (if the mapping is invoked in insert mode) is inserted. This is the same character that is inserted without mappings at all (and also with gvim started with gvim -u NONE).
I don't understand why one mapping works and the other doesn't.
Edit to answer some quiestions
I am working on a german Windows 7. The current keyboard layout is English (USA)
When I press Alt+w in insert mode without mapping, I get a ÷.

Both mappings works on my machine.
Maybe there is some problem with your mapping command, or it is still being changed by some setting you are using. Despite of using u -NONE you could try some other switches, as -U and -i; more info on this can be found on vim faq 36.12. You could also try with noremap instead of map.
"20.4. I am not able to create a mapping for the key. What is wrong?" has some additional suggestions.

Related

Error in my Vim mapping

I would like to map Control + F3 with map <c-f3> :w <CR> :make <CR><CR><CR>. When I leave out the Control this works fine. With control from normal command mode insert mode is entered and 1;5R is inserted into the buffer.
When I use a simpler command e.g. map <c-f3> dd this works as expected.
With Shift instead of control I get a similar behavior (1;2R inserted into buffer). What can I do get my mapping right?
Edit: I want the command to be executed from normal command mode. However, vim enters insert mode, which is not desired.
The combination of function keys and modifiers is problematic in terminal Vim; whether this works depends on the terminal.
Check your $TERM value; a wrong one can cause these problems. Also, your termcap database must be correct and complete.
Try out another terminal (gnome-terminal vs. konsole vs. xterm); it may work there.
Alternatively, use GVIM; it doesn't have these problems (but still can't map some other combinations).
If you use varying terminals, it's best to avoid these key combinations, and just use plain <F1..12>, and <Leader>... for the rest.
map defines keystrokes for normal, visual and operation modes. For insert mode you should use imap.
Something like this I believe: imap <c-f3> <esc>:w :make <cr><cr><cr>. <ESC> puts the Vim to normal mode.
:he :key-mapping for explaining.

Vim commands containing `r` cause me to replace

I'm using vim and the python-mode extension, but I'm having a hard time using commands that contain r. It's causing vim to replace characters instead of executing my desired command.
Here is what the vim docs for python-mode say -
let g:pymode_rope_organize_imports_bind = '<C-c>ro'
So I'm doing CTRL-cro, but like I said, it's replacing which ever character I'm under with the letter o.
What am I missing?
It seems that your mapping is not being interpreted by Vim, so it only sees the Ctrl-c, which by default aborts the current action, then the replace command r (see :help r) followed by its "argument".
You could check if the mapping is defined with :map <c-c>.
If it is correctly defined it may be that your terminal is handling the Ctrl-c directly and not passing it to Vim, as stated in Vim FAQ 20.5 - Why does mapping the key not work?. In this case you could follow the instructions on Vim FAQ 20.4 - I am not able to create a mapping for the key. What is wrong?, in special:
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.

restore tab key binding to default action

One of vim plugin added this mapping, which starts auto completion when I press tab.
s <Tab> * <Esc>i<Right><C-R>=TriggerSnippet()<CR>
How do I restore the tab mapping to insert spaces instead of autocomplete. I tried various noremap but it did not take effect or simply did nothing. unmap do not help either.
Vim version 7.2
CentOS 6.4
Use :unmap <Tab>, considering the mode(s). You've shown the :smap (presumably of the snipMate plugin), but the behavior you've described is the :imap.
Now, that unmap needs to be done after the plugin has defined the mapping, so you can't do that in your ~/.vimrc. Usually you put the commands into ~/.vim/after/plugin/<pluginname>.vim, but snipMate already uses such a file to define the mapping! Therefore, choose a name in the after directory that alphabetically comes after snipMate, e.g. ~/.vim/after/plugin/zzzSnipMate.vim.
As you probably want to define different mapping keys for it (otherwise you could just uninstall the plugin, right?), you can do that there, too.

how to remap <C-;>

I want to use the following code to quickly go from insert mode -> command mode. The problem is it just doesnt seem to be registering my keys. I've tried with control (nothing happens) and i've also tried with command (D) and it just says spellcheck not activated.
" Quick command mode from insert
imap <C-;> <esc>:
How do i go about doing this? is there an easier vim way that I'm not aware of?
Certain Ctrl chords can't be mapped, including Ctrl-;.
This is mentioned in this FAQ, see also the Vim FAQ:
20.4. I am not able to create a mapping for the <xxx> key. What is wrong?
First make sure that the key is passed to Vim. In insert mode, press Ctrl-V
followed by the desired key. You should see the keycode corresponding to
the key. If you do see the keycode, then you can create a mapping for the
key using the following command:
:map <C-V><xxx> <your_command_to_be_mapped>
For more information, read
:help map-keys-fails
:help :map-special-keys
:help key-codes
The tip about trying to print the character using Ctrl-V is good to remember if you run into this problem with another key combo.
I tried it, however it doesn't seem to work, also as pb2q said, it just can't be mapped. But there are other ways to escape using a Ctrl key combination.
For example, you can also escape insert mode with the following key presses:
Ctrl-[
Ctrl-c
On OS X (I think Lion and above), you are able to map alt - ; using this method, alt - ; on OS X outputs ç, which you can map.
But at a MacBook, I prefer to use PCKeyboardHack to map caps lock to esc. Or at Windows, use a tool I've created myself for that or even Ctrl2Cap.
EDIT
oh sorry, I thought you wanted to switch to normal mode, that's why I talked about caps lock mappings.

mapping already exists for ^I in vim

I have added the following lines to the vimrc file so that i could use s-tab for indenting
map <esc>[Z <s-tab>
ounmap <esc>[Z
After i have added this , i get the following error. I use SnippetsEmu plugin
Error detected while processing function <SNR>15_SnipMapKeys:
line 10:
E227: mapping already exists for ^I
How do i solve this conflict.Why does this happen
A helpful way you can detect whether your version of vim is capable of differentiating between Tab and Shift-Tab is to:
Go into insert mode, press Ctrl-v* then Shift-Tab. I get <S-Tab> when I do that (gvim 7.2 on Windows XP).
If you don't get that then I don't think you can map Shift-Tab separately from Tab with your current setup.
*Ctrl-v will take the next key combination you press and output the key combination that vim actually sees.
EDIT: If you're sourced mswin.vim then you'll want to use Ctrl-q instead.

Resources