14

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
  • 3
    Are you sure this is a problem with vim and not with the terminal? Are home and end working in the shell?
    – a3nm
    Jun 14, 2011 at 6:57
  • 1
    yeah home and end are working fine in guake terminal. its just the vim which is not working as expected. My main point is when it is working on ubuntu terminal fine, why is it not working in guake, also i mentioned last time before formatting my system it was working fine
    – Kumar Alok
    Jun 14, 2011 at 7:06
  • 5
    vim is a tool commonly used by programmers, so questions about it are okay on Stack Overflow. Jun 14, 2011 at 11:22
  • 1
    If you are using keys like Home and End to move around a file, you are missing the point of vim.
    – sml
    Jun 15, 2011 at 14:43
  • 3
    @sml Don't force the questioner to abandon his question, if you don't have answer or you don't like the way he wants. I am also finding the same thing. i remembered one of my colleague uses the same server and terminal was able to use Home and End keys in Vim. If some one wants to use the key board keys to use in vim which has been given for same purpose to navigate in file, and don't want to remember the editor specific keys which may different for each kind of editor. what's the wrong in this question. stop bashing up the generic questions.
    – Amit Shah
    May 8, 2017 at 2:26

6 Answers 6

11

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

2
  • This is what did it for me, working on Windows and powershell. Sweet! Thanks!
    – user232548
    Sep 6, 2021 at 8:23
  • this made it work for me. thanks
    – bySamo
    Apr 21, 2023 at 8:17
4

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>
0
3

In vim you can reach the end of the current line using $ and the start of the line using ^. I find these characters more comfortable than Home and End when typing.

Hope it helps :)

-dave

7
  • 27
    I want to use home and end keys, as they help while typing. and $ sign works in normal mode not in insert mode. Secondly this is not an expected answer of my problem, I want to them to work and want to understand why is this not working.
    – Kumar Alok
    Jun 14, 2011 at 7:04
  • 2
    You asked "addition info about some other keys to map or some other things useful, it will be really nice" and I answered. I use vim every day and I find that it's faster navigate my code in normal mode using "hjkl" instead of arrows, or "eb" to reach next word or previous one. It's just habit.
    – dave
    Jun 14, 2011 at 10:53
  • 2
    I guess you are still not trying to understand my actual question.I want to understand what is the problem there, why vim is behaving differently on terminal and guake terminal.
    – Kumar Alok
    Jun 14, 2011 at 15:51
  • 1
    I asked you for key map because I had a similar problem on tab switching. On console ctrl+pagdown did not work properly, while in terminal did... and it was a keymap problem. For a better understanding, could you paste the setup you did in vimrc please?
    – dave
    Jun 14, 2011 at 21:26
  • 2
    In vim, you're not meant to be navigating around text while in insert mode. Its kind of the point of using vim no?
    – lsl
    Feb 24, 2014 at 22:49
0

I was having the same problem with urxvt, perhaps you could at least debug it better with the same steps.

For me, everything was normal until I've switched (from gnome terminal) to urxvt. I solved following the instructions of this link:

https://wiki.archlinux.org/index.php/Home_and_End_keys_not_working

Turns out, I had 'export TERM' in my .bashrc (then removed).

I've also fixed my .Xdefaults (URxvt*termName: rxvt-unicode-256color) and my .tmux.conf (set -g default-terminal rxvt-unicode-256color)

You could follow the steps in that archlinux link and tell us if it worked.

I would have made this as a comment but I dont have enought points to.

Also the answer with some votes here doesn't answer the question completely.

Today I did more tests: What I tested: ssh connection in CentOS; machine 1 - no tmux - $TERM = ansi machine 2 - tmux - $TERM = screen-256color

In both cases set $TERM to rxvt-256color fixed the problem. (If you use tmux/screen set in their conf files, else set in .bashrc)

Tried the same in my machine (debian - tmux - urxvt - neovim); and it worked.

0

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).

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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