5

I want to use vi when running adb shell. Starting "vi" is easy. However, I found that the ESC key doesn't seem to get through to it, so I can't exit insert mode.

More broadly, it doesn't appear that I'm able to send an ESC character to the adb shell at all. I've scanned the web pretty thoroughly and haven't been able to find anyone with a similar problem (much less an answer).

I'm running VRUFNK1 on a Samsung S4. On the PC end I'm running the "adb shell" command from Cygwin under Windows.

Ideas???


UPDATE: Here's are some possible clues.

  1. The adb shell doesn't seem to be the problem. I can capture ESC in a file running
    od -cb > file, so ESC seems to be getting to the program being run under the adb shell.
  2. All commands get echoed in my "adb shell" (as if set -v was on, but it isn't).
  3. I notice that input doesn't seem to get sent to adb shell from my cygwin shell in "raw mode" -- i.e., any text I type gets buffered locally until I hit carriage return -- then the entire line gets sent. I'm not sure why that would make ESC ineffective, but certainly vi doesn't expect to be receiving input in quite that manner and perhaps its an indication of something unusual in my environment.

Similar to #1, bash (Bash X) seems to receive it, although echoing from bash is very strange. I can use ESC to enter "edit mode" in my bash shell (Bash X) to scroll through my history (I've run set -o vi), but the experience is very strange. When I hit ESC,k, nothing changes on the screen but my location in the command history goes up one rung (as it should); subsequent presses of 'k' cause a 'k' to be echoed to the screen (instead of the relevant command from my history list). When I finally hit carriage return, the correct command from my history list is executed (!).


UPDATE 2: Progress…
I tried setting the stty value in the "adb shell" to the same as the ones in my cygwin bash shell and that didn't have any effect.

I also tried this: Avoiding escape timeout issues in vim but it didn't help.

  • I tried this (by reading in from a file using :so <filename>).
  • Unfortunately, the commands weren't recognized by "vi" (they are actually "vim" commands).

Partial Solution: Typing a <cr> immediately after the ESC when in "vi" works -- the ESC is accepted and I can exit the editor. It's awkward, and the editing window is still unusable (as if TERM was set to the wrong value), but this is progress.

Also, things work fine when I ssh in. That shell gets started by the telnet server; similar situation as Terminal Emulator directly on the device. Ssh has its own server which then forks off the shell. In the case of the "adb shell", the shell is forked off by /sbin/adbd -- as far as I can tell, there is simply something unusual about that environment. This is a huge step for me -- at least now I have a way to do full screen editing on the device using my PC (rather than editing directly on the S4's tiny screen). Thanks to Jack Palevich for that suggestion.

I can only think of two things to try at this point:

  1. Try running adb shell against someone's device (but the device must be running root, so that I can run Busybox's "vi") (BTW, the version of "vi" is not the problem -- it runs fine from ssh.)
  2. As someone else to run "vi" in "adb shell" on my device, from their host (preferably someone who has succeeded in running "adb shell" and vi somewhere previously.

I'm starting to think that It Simply Doesn't Work.


UPDATE 3: Info from XDA Developers
I found some relevant posts on the XDA Developers forum. It seems to be the case that people have had problems with this for a long time (since at least 2010). I didn't find any solutions.

XDA Link 1
XDA Link 2
XDA Link 3

There is also a paragraph listing various perceived/proposed adb shell bugs that match my experience, here:

Proposed ADB Shell Bugs

Volo
  • 28,673
  • 12
  • 97
  • 125
Barry Holroyd
  • 1,005
  • 1
  • 11
  • 20
  • To exit a VI editor you have to quit the edit mode (if you entered on it with esc key), type `:` then `q` it states that you want to leave the VI and if you have made any changes on you have either to save or discard which would be `:q!` or `:qw` respectivelly – Jorge Campos Jan 06 '15 at 00:58
  • 1
    Yes, I'm familiar with how to use vi generally (I was one of the first 50 users back in about 1979 :-)). The problem is that I can't exit insert mode -- the screen doesn't accept the ESC key when I use it. – Barry Holroyd Jan 06 '15 at 19:59
  • UPDATE: The adb shell _is_ accepting the ESC key (I checked using "od -cb"). Apparently "vi" is the problem. I've checked around and can't find any TERM configuration (e.g., TERM=linux, TERM=tv102) that has any effect at all. I did find one other posting describing this problem (http://forum.xda-developers.com/showthread.php?t=81615), but there was no solution posted. It seems to be rare, so I'm not sure what is awry. – Barry Holroyd Jan 06 '15 at 20:04
  • 2
    Wow, nice to know that you were one of the first ones!! We here almost always assume that new members are in fact new in knowledge. Maybe your problem as you say it's rare is related with some bug on Cygwin on windows. There are lots of bugs on it take a look here at a glance http://stackoverflow.com/questions/18115644/vim-has-many-ui-bugs-on-cygwin-on-windows-8 . Maybe there are some bugs with this combination cygwin, adb and vi I think that worth a search on this matter. – Jorge Campos Jan 07 '15 at 16:41
  • Interesting idea, but I don't think that's the source of the problem. I did just try running adb shell directly from Windows (without involving cygwin) and still wasn't able to get vi to recognized ESC (although there was one difference -- I got tons of garbage output to my screen). I also tried setting TERM in my local (cygwin) shell as well as in the adb shell (both to "linux") -- a long shot. That didn't make any difference either. – Barry Holroyd Jan 08 '15 at 02:02

2 Answers2

1

You're right - it simply doesn't work under Windows or Cygwin shell. I found that the simplest way to make it work is to use PuTTYTray.

Check my answer in the linked thread for instructions and additional details.

Community
  • 1
  • 1
Volo
  • 28,673
  • 12
  • 97
  • 125
  • 1
    Fantastic -- thank you!!! I appreciate you taking the time to share that information -- PuTTYTray works great for me :-)! Barry – Barry Holroyd Mar 16 '15 at 23:09
  • Hi @Barry, I'm glad I could help. If this answer has solved your issue please consider [accepting it](http://meta.stackexchange.com/q/5234/) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. Thanks. – Volo Mar 18 '15 at 10:32
0

Another solution: Use Windows PowerShell instead of cygwin. Commands like 'o', 'esc', and ':wq' work nicely here.

Jack Miller
  • 6,843
  • 3
  • 48
  • 66