Issues editing files with nano in Bash/Windows 10

8

2

I'm having display issues whenever I edit files with nano in Windows 10 Linux Subsystem.

I will connect to a remote system (local CentOS7 VM on Virtualbox) using Bash/SSH. Then, I'll proceed to edit files on said remote system using nano.

I'll open a file, start deleting text and suddenly, entire lines of text start disappearing. I have to close and restart my work. When I get tired of it, I'll just switch to vim. I'd rather be in nano which works well for the basic stuff I do.

Anyone else seeing this?

Edit #1

  • Simply navigating the document in nano can cause this issue
  • vim and Putty aren't behaving in the same manner
  • Ctrl+Shift + 6 does not fix the issue
  • Using essentially a vanilla install of CentOS7, no modifications to the shell
  • AFAIK, this issues doesn't seem to happen when I access my Ubuntu Server VPS

TekiusFanatikus

Posted 2017-01-27T13:29:54.433

Reputation: 259

Do you have the same problem if you use nano within that machine without using a remote connection? – Seth – 2017-01-27T13:31:48.190

Interesting... AFAIK, no, I don't. – TekiusFanatikus – 2017-01-27T13:37:39.890

Neither on the host or guest? Do those lines actually get deleted if you save a file while you're experiencing that error or is it just a display error? – Seth – 2017-01-27T13:38:53.497

On the guest, the content gets deleted/messed up if I save. Directly on the host via the VBox window, I don't have similar issues. – TekiusFanatikus – 2017-01-27T13:43:27.107

when you say you are deleting text, are you selecting blocks of text highlighted with the mouse, or deleting at the cursor with Del/Backspace, or using Ctrl+Shift+6 and Ctrl+K to select a block via the keyboard? – Frank Thomas – 2017-01-27T13:48:43.573

Move cursor to desired location, press Delete or backspace keys. – TekiusFanatikus – 2017-01-27T13:49:27.753

are you holding the key or tapping it for each char? does the Ctrl + Shift + 6 method do the same thing? http://askubuntu.com/questions/154431/how-do-i-delete-multiple-lines-in-nano-without-affecting-the-clipboard I believe you may be ending up with more keypresses buffered than you are expecting.

– Frank Thomas – 2017-01-27T13:50:25.863

A few taps of the Backspace key is all it takes. For example, I'm just trying to fix a typo in an Apache config, no need to remove entire lines. However, Ctrl+Shift + 6 does the same thing (after having marked some text, pressing Backspace will garble the file in the same manner). – TekiusFanatikus – 2017-01-27T13:53:16.277

SSH bindings for backspace are often not right when connecting to certian shells from windows via putty. At school we used ksh and had to tell putty to remap the backspace keep to ^[H (not a suggestion, I have no idea if that particular value would work for you or not). I wonder if you need to make a simmilar adjustment to the windows BASH. What shell are you connecting to via SSH on the linux box? – Frank Thomas – 2017-01-27T14:52:24.460

I installed Windows 10 Linux Subsystem, Ubuntu... then simply ssh remote.host.ip... – TekiusFanatikus – 2017-01-27T15:24:15.730

The Shell on the remote Linux box is whatever is default on CentOS7. – TekiusFanatikus – 2017-01-28T14:18:59.193

Try once with putty then and see whether the stange behaviour persists. Have you actually tried vim and can confirm it works without a glitch? – simlev – 2017-03-14T09:12:16.673

I wasn't able to replicate using vim or Putty just now. Windows shell + nano still shows this. – TekiusFanatikus – 2017-03-18T11:15:06.560

A few taps of the backspace and then entire lines are being erased. Are you connecting over a wireless access point by chance? – Yokai – 2018-01-12T12:47:17.843

This was locally to a VM in Virtualbox. – TekiusFanatikus – 2018-01-12T17:35:33.763

I'm experiencing this problem as well. I do not encounter this problem when connecting remotely via a Mac, only via Windows bash. Only in nano never Vim. Removing config files does not fix it. It appears to be an issue with terminal output. If you page down and then back up again, often most of the line is "restored" and if you are willing to type blindly the content will save exactly as you typed it.

Definitely not a connectivity or keyboard issue; other actions such as inserting text can trigger it, and certain characters will cancel it out, such as typing a double quote. – Jordan Reiter – 2018-03-28T17:58:58.853

For what it’s worth, this fault also happens when using the new SSH beta client for Windows, no WSL installed at all. – Michael Frank – 2018-04-01T19:12:02.060

Could this be a terminfo problem? See: https://github.com/Microsoft/WSL/issues/1436

– Aulis Ronkainen – 2018-05-30T12:07:47.480

Answers

3

This is caused by incompatible remote terminfo. You could try this fix:

TARobison commented on Feb 22, 2017 •
@ShimShamSam I had the exact same problem and it was killing me.
I work on a few different servers and only the CentOS one was behaving
like this. Using the following when I log in has so far fixed the problem
for me.

stty sane
export TERM=linux

I'm new to all of this, so maybe we aren't talking about the same thing
here, but I thought I'd offer what little I could.`

More info here: https://github.com/Microsoft/WSL/issues/1436

This is a similar problem. You could check this out if you are not able to fix the issue: https://serverfault.com/questions/329154/ssh-garbling-characters-in-vim-nano-on-remote-server

Aulis Ronkainen

Posted 2017-01-27T13:29:54.433

Reputation: 1 283

1This also works in a docker container when you open an interactive shell with something like sudo docker exec -it {container_name} bash. Just before you run nano command there exporting environment variable with export TERM=linux fixed the issue. Thanks. – muffir – 2019-12-20T08:55:08.487