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?

1
  • 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? Apr 20, 2011 at 19:46

7 Answers 7

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.

2
  • Would have been nice if you would have said how to set no compatibility off.
    – gideon
    May 20, 2013 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, 2017 at 8: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

6
  • 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 9, 2015 at 23:29
  • Did not work until a PC restart. But it works!
    – 3bdalla
    May 11, 2015 at 7: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, 2015 at 16:24
  • This is by far the best answer!! Mar 27, 2016 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, 2016 at 2:13
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.

1
  • That fixed it for me. I had the same issue with the insert key and arrows not working in vim. That was on Windows 10. Dec 21, 2015 at 20:37
2

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

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"
    
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.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .