1

I have put the following in my .vimrc:

inoremap <Up> <C-c>gka    

But sometime, instead of moving my cursor, gka is inserted as text as I am in insert mode. It seems the <C-c> did not work as expected. This behavior appears also with mappings that use <C-o> and <Esc>.

I don't know if could be related to this config:

set timeoutlen=1000
set ttimeoutlen=0
set timeout
set nottimeout

I am running on Cygwin mintty

  • Set ttimeoutlen to a larger value. Also read :h i_CTRL-o. – Sato Katsura Sep 18 '16 at 3:40
  • @SatoKatsura It does not work even with ttimeoutlen=20 :( – nowox Sep 18 '16 at 10:09
  • Try something like 100... – Sato Katsura Sep 18 '16 at 10:16
  • @SatoKatsura It does not work even with ttimeoutlen=200 – nowox Sep 18 '16 at 10:33
  • Actually it works better when ttimeoutlen=0 but it's far from perfect – nowox Sep 18 '16 at 11:14
4

The following mapping works fine here:

inoremap <up> <c-o>gk

Note that using Ctrl+O you don't need the a at the end of your mapping to get back to insert mode. And you should generally avoid using using Ctrl+C to exit insert mode, as it can break some functionality and plugins.

You could try the following to debug your problem:

1) Check if the problem happens in vanilla vim

Start Vim with vim -u NONE -U NONE -N -i NONE. If the problem doesn't happens, it means you have a problem related to some setting/plugin. In this case you could follow the steps at Vim-FAQ 2.5 - I have a "xyz" (some) problem with Vim. How do I determine it is a problem with my setup or with Vim? / Have I found a bug in Vim?.

2) Try to map another key instead of the arrow keys

Still with vanilla Vim, try mapping to a regular key:

inoremap a <c-o>gk

If the problem doesn't happens, check the instructions at Vim-FAQ 10.9 - When I use my arrow keys, Vim changes modes, inserts weird characters in my document but doesn't move the cursor properly. What's going on?, which references some relevant options such as 'ttimeoutlen'.

3) Try other terminals/gVim

If nothing else solves the problem, the problem is probably related to your terminal. You could try using another terminal or, even better, gVim (Graphical Vim), which is available on Windows and thus would allow you to avoid Cygwin and any problem related to shell limitations.

  • I'll go with <C-o> instead of <C-c>. The arrows keys are not the problem because I get the same problem with my <C-y> and <C-s> mapping. I will try with vanilla Vim as well. Related to the latter point, I feel gVim is much more limiting than my Terminal Vim :) – nowox Sep 19 '16 at 19:20
  • because I get the same problem with my <C-y> and <C-s> mapping - note that these are also composed keys; it would be better to test with a simpler mappings, such as a or b. About gVim, I'm curious :) how do you find it more limiting? – mMontu Sep 20 '16 at 10:53
  • I can quickly access my terminal with <C-z> which I do all the time. With my terminal I can enter in real full screen mode (no borders) and there are some mapping that fails on gvim not not on the terminal version (with proper binding). Last but not least, I can use tmux in full screen mode and directly send Python code to my iPython instance. – nowox Sep 20 '16 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.