Saturday, 25 May 2019

How to fix hitting arrow keys adds characters in vi editor issue in Ubuntu

Background

I just purchased a new Laptop and the obvious next thing to do was add Ubuntu to it. There are some common problems that everyone faces when a new Ubuntu OS is installed and one such problem is -  hitting arrow keys adds characters in vi the editor. In this post, I will show you how to fix this issue.




Fixing hitting arrow keys adds characters in vi editor issue

To fix this issue, edit a file called vim.rc in your root folder. If it's not present create one. You can use the following command.

  • vi ~/.vimrc
Now add the following content to it -

  • set nocompatible
If backspace is not working add following content -

  • set backspace=2

And that's it. Save the file and you should be good to go. 



Another cleaner way is just to install vim -
  • sudo apt-get install vim
Now that the problem is resolved, let's try to understand the issue here. vi as an editor has normal and insert mode. When you open a file using vi you are in normal mode. Here you can go to any line, use any arrow keys and the behavior is as expected. Now when you type "i", you essentially go into insert mode. In this mode, vi does not expect you to go left, right, top, bottom using arrow keys. You can always do that by pressing "ESC" and going back to normal mode. Insert mode is just to add text to your file and that's the behavior of vi.

Hope this helps :)




No comments:

Post a comment

t> UA-39527780-1 back to top