HOME and END keys Problem in Vim

Viewed 17280

I am on Ubuntu. I am a beginner user of Vim. I have setup key mappings in /etc/vim/vimrc for home and end keys.

It is working on terminal, but when I edit a file in Guake terminal these mappings are not working. I have this problem with me this time only. Last time (I mean before reinstalling Ubuntu) it was working fine on each terminal.

I have tried

 set term=xterm

but its still not working.

It will be really nice if someone help me with this. Also if someone can give me addition info about some other keys to map or some other things useful, it will be really nice.

--

vimrc:

if has("syntax")
  syntax on
endif

//just this has been added by me

if filereadable("/etc/vim/vimrc.local")
   source /etc/vim/vimrc.local
endif

map <ESC>[8~    <End>

map <ESC>[7~    <Home>

imap <ESC>[8~    <End>  

imap <ESC>[7~    <Home>

All the ret things are commented

I would like to add that i don't think that this is the problem with vimrc file as this configuration let me use these END and HOME keys in terminal while I'm in Insert mode or Normal mode. But not working on guake.(correct me if I am wrong please.)

Still hoping you might help me with something now.

--

6 Answers

Try adding set term=xterm-256color to ~/.vimrc

This happens because pressing the home and end keys in a terminal sends an escape sequence consisting of several characters to vim, and vim isn't correctly associating these escape sequences back with the keys you pressed.

Answer taken from here https://stackoverflow.com/a/1523821/5506988

I don’t know if this is going to work for you, but it worked for me: I’ve noticed that TERM was set to “linux” [check with ‘echo $TERM’].

Then there are two ways of resolving.

First) Change .bashrc or your custom config file to:

export TERM='xterm'

or Second) Add these lines to your .vimrc:

" Fix home/end key in all modes
map <esc>OH <home>
cmap <esc>OH <home>
imap <esc>OH <home>
map <esc>OF <end>
cmap <esc>OF <end>
imap <esc>OF <end>

This works for me, edit ~/.vimrc and put these instructions:

set term=ansi
map ^[[1~ ^
map ^[[4~ $
map ^[[2~ i
map ^[[3~ x
map ^[[5~ 1G
map ^[[G ^[
map ^[[6~ G

The ^[[1~ (etc) it achieved by pressing ctrl-v and then the key itself. The text as seen will appear. ^[ is ESC (and is the key on the 5 key on my keyboard).

If some body face this problem with neovim , then use :help $TERM , it has good amount of information. If you are using Putty/MTputty then change export TERM=putty-256color .It may work.

Related