开发者

HOME and END keys Problem in Vim

I am on Ubuntu. I am a beginner user of Vim. I have setup key 开发者_Python百科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.

--


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


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


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>


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜