26
votes

I am using Cygwin 1.7.22 (32-bit) on Windows 8 (64-bit). Within Cygwin, I am using Vim 7.3.1152, which is the default version.

Behavior that seem like bugs:

  1. When I press I to enter insert mode, it does not say -- INSERT -- in the bottom left. In fact, it doesn't say anything. It does behave correctly, though.

  2. When I delete letters using Backspace in insert mode, the letters do not disappear but the cursor does move to the left.

  3. When I use the arrow keys in insert mode, it enters the letters A, B, C, and D, rather than moving the cursor. The arrow keys work normally outside of insert mode.

How do I make Vim behave as I expect?

4
Why did people downvote my question? Is there something wrong with my question? I need feedback in order to improve.SerMetAla
I downvoted. What you claim to be bugs arn't bugs but expected behavior. You also don't have a question.FDinoff
Also did you try my answer? Did your problem go away?FDinoff
Thank you very much for your question! It solved years of frustration for me! And don't listen to the downvoters. We try to make SO a safe place despite them ;-)Theodore R. Smith
A bug in the default configuration IS STILL A BUG.user447607

4 Answers

26
votes

Create a ~/.vimrc file with the following contents to put vim in nocompatible mode (actually the mere presence of the file is sufficient.)

set nocompatible

The behavior you are seeing is how vi used to behave. These are not bugs.

Take a look at :h nocompatible


In vim compatible mode tries to emulate vi as closely as possible.

  1. --insert-- is not part of vi so it not shown in compatible mode.
  2. I believe vi did a lazy redraw of the screen and didn't update until you exited back to normal mode. Also backspace is only usable also only works on stuff that was entered in the current insert mode. Overall its not very user friendly.
  3. The arrow keys are sent to vim as escape sequences (escape followed by a coupled of letters). Let ^[ be escape. ^[OA is up on my computer its probably something similar on yours. vim sees this as an escape (goes back to normal mode), and O (add a line above the current) and A which is the A you see entered onto your screen. This just means that vim in compatible mode does not interpret the escape characters properly. Most likely because vi did not interpret them (nor was it designed to use them).

set nocompatible fixes problems 1 and 3.

I think set backspace=indent,eol,start should fix problem 2.

5
votes

This was asked months ago, but I am answering for future reference for anyone else who encounters this problem.

I was just bitten by this issue. All advice listed in this post, and in other posts on this forum (not to mention posts on other forums) does not work, at least for some of us. I finally figured out the real issue.

vim on cygwin, for whatever reason (at least this was the case for me) does not use the .vimrc you put in your directory. Let's say you copy the example one to your working directory, or copy some .vimrc from online. Or maybe you create a new one from scratch, and put all the settings the good people here and elsewhere recommend (set backspace = blahblah, set nocompatible, set this, set that). It doesn't work. Why? Because for whatever reason (at least in my case) vim isn't looking at the .vimrc you just created.

The solution is to FORCE vim to use a particular .vimrc, by passing in -u on the command line like so:

vim -u [/INSERT/PATH/TO/.vimrc]

For the love of all that is holy, DO NOT type square brackets or the words "/INSERT/PATH/TO/.vimrc" verbatim. Use your brain please.

Anyway, this solved my problems and I was able to use the default example .vimrc and get proper delete and backspace behavior while in insert mode, not to mention other goodies.

You might want to alias the vim command in your .bashrc like this:

alias vim='vim -u [/INSERT/PATH/TO/.vimrc]'
0
votes

Regarding A,B,C,D for arrow keys in Vim, adding:

:set term=cons25

to ~/.vimrc worked like a charm.

source: http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell

0
votes

Following different answers in this topic I found a simple solution.

$ vi --version | head
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 30 2020 21:54:08)
Included patches: 1-486
Modified by <[email protected]>
Compiled by <[email protected]>

$ vi --version | grep 'user vimrc'
     user vimrc file: "$HOME/.virc"
 2nd user vimrc file: "~/.vim/vimrc"

So I just created ~/.virc (not vimrc) and it works! The content of the file:

set nocompatible

Probably, if you already have this file you will add the above string in it. Or, as people say above, if you have an empty ~/.virc, nocompatible mode must be already in use (I didn't check it).

Apart of the question, line numbers (that I find very useful) may be shown in vi by adding:

set number