7

I am working on a ChromeOS computer with both Vi and Vim. When I open up the editor to an existing document, I type A to begin editing. When I try to move around with my arrow keys, the following happens:

vim and vi arrow keys

I have tried both Vim and Vi, and both of the have this problem. How do I move around in my document while editing it?

  • 4
    Related (though not an exact duplicate, as this is about vi, not Vim): Fix arrow keys displaying A, B, C, D in vi (not in vim). – Martin Tournoij Dec 26 '15 at 16:45
  • 1
    In the shell, what is the output of echo $TERM? What is the output of set term in Vim? – muru Dec 26 '15 at 17:09
  • @muru $TERM is xterm, set term is term=xterm – Elliot A. Dec 27 '15 at 2:13
  • If you don't have set nocompatible (i.e. no vimrc) you should have one. – FDinoff Dec 27 '15 at 5:13
  • 2
    Use :set nocomptible in vim. Also please check the values: :verbose set cp? cpo? – Christian Brabandt Jan 22 '16 at 12:44
6
+100

I do need to point out the elephant in the room: You shouldn't be navigating in insert mode.

Insert mode is for inserting text. While many implementations of vi allow you to navigate (using the arrow keys) while in insert mode, the recommended, normal method of navigation is to navigate in normal mode. Normal mode should be the mode you are normally in, hence the name.

The topic of modal editing vs. arrow keys is well described (at a beginner level) under "Misconception #1" in this excellent article.

As an additional point of background, the terminals upon which vi was originally designed didn't even have arrow keys. On some old keyboards the HJKL keys are additionally labelled with arrows; I don't actually know if this came before or after vi but I suspect the former.

I highly recommend working your way through the vimtutor (on the command line) and reading through the above linked article to start getting a handle on the power of modal editing. I suspect that the problem of non-functioning arrow keys will drop into total insignificance once you get a feel for the powerful motion commands available in normal mode. I know I personally never use arrow keys while editing text in Vim, and I feel handicapped when using other editors where I must use the arrow keys to navigate.

This site itself will also be of great assistance; for instance, here are a couple posts you may find helpful:

As to the nitty-gritty of Chrome OS and how it interprets arrow key presses in your terminal, I suspect that debugging it will go beyond the scope of this site. If you are truly determined to use arrow keys in vi, perhaps you will have better luck with the keyboard-to-terminal debugging issue amongst the knowledgeable people over at superuser.com. Best of luck to you whatever you decide, and I hope you may come to appreciate the power of Vim even with non-arrow-key only usage patterns. :)


P.S.: The most basic motion commands there are, are h, j, k, l. To these you can add <Space>, <Backspace>, <Return> and -, and of course the great favorites w, b, e and their whitespace-separated-word counterparts W, B, E. If you add in sentence motions ( and ), paragraph motions { and }, searching the word under the cursor forward or backward with * and # respectively, and same-line character search with f, t, F, T, ; and ,, and if you actually learn all of those well, or even most of those (which won't take you very long, actually)...I can promise you with total confidence that you will never go back to using arrow keys to navigate text within Vim.

This isn't even a complete list of motion commands; far from it. To see a more complete list along with documentation for each, start Vim, type :help motion.txt, and use j and k as your "down" and "up" keys to scroll through the document.

  • 1
    "You shouldn't be navigating in insert mode" - > Because pressing the down arrow twice is somehow not as fast as pressing <Esc>jji. Never mind that <Esc> is also outside the home row, just like the down arrow. – Martin Tournoij Jan 29 '16 at 2:19
  • @Carpetsmoker, if a down arrow keystroke could be properly replayed as part of a dot command, I would probably do that sometimes. Since it can't...I don't bother with arrow keys; <C-o>2j is still faster. – Wildcard Jan 29 '16 at 2:40
  • 1
    Also, I haven't touched the <Esc> key a single time since learning that <C-[> does the same thing. – Wildcard Jan 31 '16 at 7:49
  • I've mapped my caps lock key to <kbd>esc</kbd>, it's useful in everything not just vim. – theonlygusti Nov 9 '17 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.