29

I am unable to edit text files using vim in cygwin.

I have to press i many times to insert text. Sometimes it works and sometimes doesn't. Whenever I move cursor up down I have to press I many times.

What could be the problem? Does backspace work in cygwin?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Mirage
  • 1,537
  • 7
  • 19
  • 19
  • Are you running inside the native Windows console, in another terminal emulator running as a native application, in a terminal emulator running under X? What version of Windows? Does the delay between pressing `ESC` and pressing `i` matter? – Gilles 'SO- stop being evil' Apr 20 '11 at 19:46

7 Answers7

35

Cygwin vim ships with vim's default configuration, which leaves vim in vi compatibility mode where it tries to emulate the original vi as closely as possible. Among other limitations, arrow keys do not work in that mode, and backspace just moves the cursor left rather than erasing a character.

Creating an empty ~/.vimrc is sufficient to disable vi compatibility mode:

touch ~/.vimrc

Having said that, i to enter insert mode should work anyway. You'll need to provide more details on where and how you're running vim. Also, are you actually running the vim that comes with Cygwin, or the native Windows version of vim?

Update

You can add below sets in ~/.vimrc to make is similar to default vim

set nocompatible
set backspace=indent,eol,start
set backup
set history=50
set ruler
set background=dark
set showcmd
set incsearch
syntax on
set hlsearch

If vim does not pick up your vimrc file, it may be looking for a .virc file instead. In this case, rename the file and the changes will be applied.

ak2
  • 12,395
  • 1
  • 18
  • 14
  • Would have been nice if you would have said how to set no compatibility off. – gideon May 20 '13 at 12:02
  • Do you know where is the default home location of cygwin? I want to create .virc by GUI instead of cygwin – Alex Mar 12 '17 at 08:07
13

The easiest way is copy Cygwin VIM's sample vimrc file

cp /usr/share/vim/vim*/vimrc_example.vim /etc/vimrc

This will fix the problem for every account on your system. If, for some reason, you only want to change it for a particular user, do

cp /usr/share/vim/vim*/vimrc_example.vim ~/.vimrc

See reference here

AdminBee
  • 21,637
  • 21
  • 47
  • 71
Gaurav
  • 131
  • 1
  • 2
  • 1
    This should be the accepted answer because the example actually turns on syntax highlighting by default and probably a lot of other defaults people are used to. – JohnEye Feb 09 '15 at 23:29
  • Did not work until a PC restart. But it works! – 3bdalla May 11 '15 at 07:44
  • Excellent answer, simple and solved all the different issues I was seeing with a fresh cygwin install, and syntax highlighting is a bonus that was unexpected – crobicha Aug 19 '15 at 16:24
  • This is by far the best answer!! – Theodore R. Smith Mar 27 '16 at 14:36
  • 1
    where is located that file? i was searching for that in /usr/share/ but then i cannot see any directory called vim. – neo33 Aug 15 '16 at 02:13
  • There is certainly some package dependency needed here. I know I'm writing some years ahead, but a recent fresh Cygwin install (default package selection) does not present the referenced file. – Charles Roberto Canato Sep 26 '19 at 22:49
3

I had problem with arrow keys while trying vim inside Windows 8.1 using cygwin. The issue was, printing A/B/C/D while navigating with Arrow keys in insertion mode. The solution worked for me is:

cp vimrc_example.vim ~/.vimrc

Basically, above command copying vimrc_example.vim file to /home/<user name>/.vimrc.

muru
  • 69,900
  • 13
  • 192
  • 292
noufal
  • 31
  • 1
2

Are you sure you're not using vi instead of vim?

rfelsburg
  • 645
  • 4
  • 5
1

Try this way:

  • first:

    cp /usr/share/vim/vim73/vimrc_example.vim ~/.vimrc
    
  • then, add this line to your ./.bashrc file:

    alias vi="vim"
    
Mat
  • 51,578
  • 10
  • 158
  • 140
binghenzq
  • 581
  • 2
  • 7
  • 13
0

No the commands are exactly the same. It sounds like you have an input problem. Either your keyboard is messed up or your terminal is on the fritz or something.

Caleb
  • 69,278
  • 18
  • 196
  • 226
0

Depending on the characteristics of your terminal program, when you press a cursor key it sends a sequence of characters starting with the ESC key. For example, the Up Arrow key sends the three characters ESC [ A. With vim in input mode, pressing a cursor key may terminate input mode when ESC is seen, and the subsequent characters may be interpreted as vim commands. Since it exits input mode, you need to press i again to continue inserting text. Perhaps this is what's happening for you.

Check if your terminal has options that can change the emulation, such as VT-100, VT-220, or a setting that specifies what is sent when the Backspace or Del keys are pressed. Changing those settings may get the behavior you want. If you're using the native Windows command console, you probably don't get those options.

You may have to avoid using the cursor keys in input mode. Press ESC to exit input mode, then move the cursor, then i again for more input. That's how us old-timers had to do it before vim got smart enough to interpret the cursor keys in input mode.

juggler
  • 191
  • 5