When i press <C-Right> in insert mode, vim does the same thing that it would being in normal mode and pressing w. But i would like to remap C-Right and C-Left so the effect would be more like the e key (specially at the end of a line, when i'm just before the last word i don't want vim to skip the line and go to the next line word, i want it to put the cursor just at the end of the line.)
I tried for the insert mode :inoremap <C-Right> <Esc> e a
but it keeps jumping the line, besides <Esc> e a doing exactly what i want.
In normal mode, :nnoremap <C-Right> E does what i want.
What i am missing to make the remap work?
Thank you for your time reading the question.
Don't put spaces inbetween the commands (or after them). All the spaces count as part of the command (which is move the cursor to the right)
:inoremap <C-Right> <Esc> e a
should be
:inoremap <C-Right> <Esc>ea
Related
I am trying to have a remap in my vimrc that adds a snippet, then goes to the next line in Insert mode:
:nnoremap <leader>b oimport pdb;pdb.set_trace()<esc> o
The snippet import pdb;pdb.set_trace() gets inserted into my current buffer, but the cursor in vim remains on the same line. Is there any way to have the cursor move to the next line after inserting the snippet?
For me, your mapping works, except at the end of the buffer (where it beeps and keeps the cursor at the end of the inserted line, as you report).
The reason is the space between the <esc> and o. :help <Space> is a motion (to the right, just like l), and if the cursor cannot move there (at the end of the buffer, maybe also elsewhere depending on the 'whichwrap' option), Vim beeps and aborts the mapping; i.e. all keys that come after that are ignored.
The fix is easy: Drop the superfluous whitespace, and the mapping will work everywhere!
nnoremap <leader>b oimport pdb;pdb.set_trace()<esc>o
How about this:
nnoremap <leader>b oimport pdb;<CR>pdb.set_trace()<CR>
I have encountered some strange behavior in vim. I have done this mapping:
execute "set <A-j>=\ej"
execute "set <A-k>=\ek"
noremap <A-j> <C-e>
noremap <A-k> <C-y>
But now when I use <A-j> or <A-k>, the cursor keeps moving to the right! It doesn't do that when I'm just using <C-e> or <C-y>.
Is this a bug or some strange feature?
Here is the Vim code you posted:
execute "set <A-j>=\ej"
execute "set <A-k>=\ek"
noremap <A-j> <C-e>
noremap <A-k> <C-y>
If you copy/paste it, or if you edit this post (or yours) and go to the end of the <A-j> line, you'll find there is a trailing space there. That is significant, because in Vim's normal mode, pressing Space will move the cursor one position to the right.
Using this code as you pasted it, I can reproduce the problem, although my cursor is moving to the right, not to the left as you describe. The map is executing as CtrleSpace, which would scroll the viewport downward by one line, and then move the cursor forward by one character.
Your question describes the cursor moving to the left, not to to the right. It's possible that you simply confused left and right when you wrote the question, but it's also possible that in your .vimrc you have an embedded backspace (Ctrl-H, or Delete) character at the end of the line. That would have the effect of moving backward (left) by one character, much as Space advances forward (right) by one character.
I have remapped <C-Space> to <Esc> using the this line in my .vimrc:
inoremap <C-Space> <Esc>
when running under MacVim or gVim (I use inoremap <Nul> <Esc> when I don't have gui_running)
It works fine except when I leave insert mode with the cursor at the end of the line. That is, if I do A to put the cursor at the end of the line, and then type <C-Space>, the cursor moves down to the first column of the next line. Hitting <Esc> leaves the cursor on the last character.
Why does it do this, and how can I stop it? The <Nul> remapping doesn't have this problem.
Most likely you have a trailing space in your mapping. Removing it should solve your problem. Space move the cursor one character forward.
I want to move one word forward in insert mode.
Why this doesn't work:
inoremap ,w <esc>w
But this works(back one word):
inoremap ,b <esc>b
That's because when the cursor is at the beginning of a word, the <Esc> will move the cursor one character left (this is a bit unintuitive, but default vi behavior), and the w will only move to the original position.
This should work:
inoremap ,w <esc>ww
mapping critique
I don't particularly like your mappings:
starting it with , adds a delay whenever you type a comma
do you really need a command that leaves insert mode and moves the cursor? <Esc>b achieves the same and also is two keystrokes (many users remap the <Esc> key to be in a less cumbersome position)
if you really must navigate in insert mode, there's already <C-Left> / <C-Right>.
I'm using imap <c-v> <ESC>"+PA in gVIM to do the pasting , however , each time i tried to paste i got unexpected result:
aa${CURSOR}aa , and press ^V right now , i got a${PASTE_TXT}aaa , but i wanted aa${PASTE_TXT}aa.
How can i fix this ?
I would suggest that you do not remap CTRL-V, it is really useful when you want to insert raw characters. In order to paste in insert mode, you needn't switch to normal mode. Use CTRL-R then CTRL-O, then +. That's not so long. You can remap an F-Key to do that:
:inoremap <F1> <C-r><C-o>+
or
:inoremap <C-v> <C-r><C-o>+
See :help i_CTRL-R for more reference. You might also like this answer I gave about registers.
If you still want to keep your mapping using normal mode, replace P with p and A with a. After all you want to paste after the last character you have stopped when leaving insert mode, and to continue inserting after pasted text, not at end of line.
:inoremap <C-v> <Esc>"+pa
Change imap <c-v> <ESC>"+PA to imap <c-v> <ESC>"+pA
Upper case P is paste before cursor position, lower case p is after cursor position.