Trouble with arrowkeys in vi


17 posts
by Kaptein » Sat Jan 05, 2013 6:14 pm
Greetings all, I got my Raspberry a couple of days ago and i'm enjoying it quite well. I'm not technically a new Linux user, I used to run Linux as my primary operating system for a while, but I've donesized my "computer park" to a laptop with windows, and some knowledge has faded. I felt the troubleshooting category was a little more geared towards Pi related than Linux related issues, so I post this here.

I am used to vi for console editing, so that's what I've been using on the RasPi. However yesterday I started having issues. Every time I press an arrowkey I get newlines with A, B, C and D's. I've had this issue years ago but forgotten the solution. I've been using nano as a quick fix, but it feels awkward. I am using PuTTy 0.62 on my Win 7 laptop to connect to my RasPi.

Screenshot of what I get:

Image
Shut up and start talking!
Posts: 5
Joined: Tue Jan 01, 2013 4:23 pm
by jojopi » Sat Jan 05, 2013 8:06 pm
You are not supposed to use the arrow keys in vi; you are supposed to use h-j-k-l. And you are certainly not supposed to try to move the cursor while you are in insert mode.

However, when you start vi you probably see this:
Code: Select all
~                        Running in Vi compatible mode                         
~                type  :set nocp<Enter>        for Vim defaults                 
And if you try that things may work more like you expect. You might also want to "sudo apt-get update && sudo apt-get -y install vim" which seems to change the behaviour permanently.
User avatar
Posts: 2939
Joined: Tue Oct 11, 2011 8:38 pm
by Kaptein » Sat Jan 05, 2013 8:40 pm
Well, it used to work, so why wouldn't I. But thanks, added :set nocp to my .vimrc and now I can do what I'm not suppsed to :)
Shut up and start talking!
Posts: 5
Joined: Tue Jan 01, 2013 4:23 pm
by efflandt » Sat Jan 05, 2013 9:24 pm
That is the first thing I noticed (cursor keys did not work) when I was going to suggest using sudo vigr to add a new user to groups after sudo adduser. After much searching, apparently starting it as vi runs it in vi compatibility mode configured for the classic cursor keys: "h" to go left, "j" to go down, "k" to go up, "l" to go right.

From there you can either :set nocp to have normal cursor keys, or start it as vim.tiny instead of vi.

To run it as vim without the .tiny, you could always:
Code: Select all
sudo ln -s /usr/bin/vim.tiny /usr/bin/vim

Real nerds use emacs! Actually I cut my teeth on Linux and other *nix (SunOS, FreeBSD) in the 1990's and NetBSD later, but do not have a photographic memory to remember cryptic commands. And from using pine e-mail reader and pico text editor (now nano in Linux) I am quite comfortable using nano. With its bottom menu which does not require remembering any commands, nano is easy for new Linux users. And it can even color highlight things in scripts (based on filename extension I think), although, I have not looked into an autoindent setting.
Posts: 359
Joined: Mon Dec 03, 2012 2:47 am
Location: Elgin, IL USA
by ksangeelee » Sat Jan 05, 2013 9:39 pm
Kaptein wrote:Every time I press an arrowkey I get newlines with A, B, C and D's. I've had this issue years ago but forgotten the solution.


I keep forgetting this too - I usually edit '/etc/vim/vimrc' and make sure there's a line near the top containing 'set nocompatible'.
Posts: 192
Joined: Sun Dec 25, 2011 5:25 pm
Location: Edinburgh, UK
by Kaptein » Sat Jan 05, 2013 9:41 pm
efflandt wrote:With its bottom menu which does not require remembering any commands, nano is easy for new Linux users. And it can even color highlight things in scripts (based on filename extension I think), although, I have not looked into an autoindent setting.


This is true. Syntax highlighting is a quick fix in vim tho with "syntax on"
Shut up and start talking!
Posts: 5
Joined: Tue Jan 01, 2013 4:23 pm
by Kaptein » Sat Jan 05, 2013 9:43 pm
ksangeelee wrote:
Kaptein wrote:Every time I press an arrowkey I get newlines with A, B, C and D's. I've had this issue years ago but forgotten the solution.


I keep forgetting this too - I usually edit '/etc/vim/vimrc' and make sure there's a line near the top containing 'set nocompatible'.


I prefer editing the ~/.vimrc file. Even though it's only me using the raspberry I like to keep personal preferences and system preferences separate
Shut up and start talking!
Posts: 5
Joined: Tue Jan 01, 2013 4:23 pm
by scruss » Sat Jan 05, 2013 11:20 pm
jojopi wrote:You are not supposed to use the arrow keys in vi; you are supposed to use h-j-k-l.


You can use the arrow keys if your vi is set up to use them. HJKL is a usability nightmare.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.
User avatar
Posts: 1180
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
by elvisimprsntr » Sun Jan 06, 2013 12:12 am
install vim which is a similar editor but uses the arrow keys.

Code: Select all
apt-get install vim


I find it a lot easier to work with when you need to quick edits without an x-windows session.

Elvis
http://www.youtube.com/user/TheElvisImprsntr
Posts: 131
Joined: Sat Dec 29, 2012 11:36 pm
by sdjf » Tue Jan 08, 2013 6:34 am
I have been having similar issues using vi in arch, which really is ex text editor on my Pi, and not the real vi. There are quite a few packages starting with name vim- in the user repository, does anyone know which are essential for running vim? I saw one named vim-a, is that the one?
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || My 512MB Model B only runs Arch.
Posts: 1388
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by pluggy » Tue Jan 08, 2013 11:37 am
Whats wrong with nano ?

vi is a little short on redeeming features IMO.
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......
User avatar
Posts: 3636
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by penguintutor » Tue Jan 08, 2013 2:44 pm
HJKL is a usability nightmare.


HJKL is good if you are a touch typist, especially if using a compact keyboard that has squashed the cursor keys up. In fact it was a long time before I realized that the Raspberry Pi was using vim.tiny so didn't support the arrow keys by default.

I normally run vim which does support cursor keys in insert mode as one if it's main improvements. I normally stick with hjkl which is where my right hand is when typing.

If you install vim then it will update the alternatives link so running vi will actually call vim (in the same way that it calls vim.tiny by default).
User avatar
Posts: 356
Joined: Tue May 08, 2012 9:11 am
Location: UK
by sdjf » Tue Jan 08, 2013 4:17 pm
pluggy wrote:Whats wrong with nano ?

vi is a little short on redeeming features IMO.


I am used to using vi. And, at the moment, my access to the Pi is as a headless server from a PDA without a hardware keyboard that cannot enter the nano commands. One key press at a time, no multiple simultaneous key presses. Not ideal, but having issues attaching the other PDA which does have a nice standard external USB keyboard.

But even with a keyboard, the only command line editor I really like is vi. Personal taste I guess.

Byt, hey, still not sure which of about half a dozen vim packages are the right one to install. Is vim-a standard vim? Or is plain vim missing from the ArchLinuxArm repository?
FORUM TIP: To view just one person's posting history, sign in, click on their user name, then click on "Search User's Posts." || My 512MB Model B only runs Arch.
Posts: 1388
Joined: Fri Mar 16, 2012 5:20 am
Location: California
by joan » Tue Jan 08, 2013 4:21 pm
pluggy wrote:Whats wrong with nano ?

vi is a little short on redeeming features IMO.

Macros and regular expressions are great redeeming features.
User avatar
Posts: 12687
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK
by pluggy » Tue Jan 08, 2013 4:45 pm
Vim is a slightly more polished Vi. Personally I use gedit in Ubuntu Linux via Ubuntu's built in sftp and the Pi's SSH......

Image
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......
User avatar
Posts: 3636
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK
by Joe Schmoe » Tue Jan 08, 2013 5:37 pm
Vim is a slightly more polished Vi. Personally I use gedit in Ubuntu Linux via Ubuntu's built in sftp and the Pi's SSH......


Personally, I use Microsoft Word, because I find nano too hard.

Math is hard...
And some folks need to stop being fanboys and see the forest behind the trees.

(One of the best lines I've seen on this board lately)
Posts: 4277
Joined: Sun Jan 15, 2012 1:11 pm
by pluggy » Tue Jan 08, 2013 5:55 pm
Might be a bit messy for Unix text files on the Pi.

I wouldn't let little things like 'object of the exercise' put you off though.....

Image
Don't judge Linux by the Pi.......
I must not tread on too many sacred cows......
User avatar
Posts: 3636
Joined: Thu May 31, 2012 3:52 pm
Location: Barnoldswick, Lancashire,UK