(→Solution 4: Works on Synology NAS default configuration.) Tag: Visual edit |
|||
(21 intermediate revisions by 16 users not shown) | |||
Line 4: | Line 4: | ||
|previous=548 |
|previous=548 |
||
|next=551 |
|next=551 |
||
− | |created= |
+ | |created=2003 |
|complexity=basic |
|complexity=basic |
||
|author=VT |
|author=VT |
||
Line 23: | Line 23: | ||
==Comments== |
==Comments== |
||
− | === |
+ | ===Easy solution=== |
<pre> |
<pre> |
||
1) Open Vim editor, |
1) Open Vim editor, |
||
Line 29: | Line 29: | ||
3) Check if you have .vimrc file in $HOME location,(if you don't have create it) |
3) Check if you have .vimrc file in $HOME location,(if you don't have create it) |
||
4) Add the following line line to .vimrc file |
4) Add the following line line to .vimrc file |
||
− | + | set nocompatible |
|
+ | or |
||
+ | set nocp |
||
</pre> |
</pre> |
||
+ | It also fixes the "backspace won't delete" problem that some people have. |
||
− | Spent a whole day trying to use the escape characters and down arrow keys, i always got the message about error in RHS, finally the above solution worked and now i can use arrow keys in insert mode with both vi and vim. |
||
− | === |
+ | ===Solution 1=== |
⚫ | |||
− | |||
⚫ | |||
<pre> |
<pre> |
||
imap ^[OA <ESC>ki |
imap ^[OA <ESC>ki |
||
Line 43: | Line 44: | ||
imap ^[OD <ESC>hi |
imap ^[OD <ESC>hi |
||
</pre> |
</pre> |
||
+ | |||
+ | See solution 15 for another imap binding solution if this one doesn't work for you. |
||
Note: ^[ is one symbol, try to enter it using <Ctrl-V>ESC or <Ctrl-V><Ctrl-[> |
Note: ^[ is one symbol, try to enter it using <Ctrl-V>ESC or <Ctrl-V><Ctrl-[> |
||
− | === additional solution 2 === |
||
⚫ | |||
This doesn't really work very well for me on SunOS -- I have the same problem but :set term=cons25 just gives me OC everywhere before each character until I redraw. Weird. |
This doesn't really work very well for me on SunOS -- I have the same problem but :set term=cons25 just gives me OC everywhere before each character until I redraw. Weird. |
||
− | But, < |
+ | But, <code>:set term=ansi</code> works great, and the arrow keys work. |
A better solution is to, while in vi, type in insert mode [ctrl-v][arrow up] and see what you get. |
A better solution is to, while in vi, type in insert mode [ctrl-v][arrow up] and see what you get. |
||
Line 67: | Line 70: | ||
(though you want ''real'' escape chars instead of "^[".) |
(though you want ''real'' escape chars instead of "^[".) |
||
− | ---- |
||
And in addition, set term=ansi makes syntax color off in vim (afair FreeBSD with color xterm). |
And in addition, set term=ansi makes syntax color off in vim (afair FreeBSD with color xterm). |
||
⚫ | |||
− | ---- |
||
− | === additional solution 3 === |
||
− | |||
So are we to be left with no good freebsd / bash solution? |
So are we to be left with no good freebsd / bash solution? |
||
<pre> |
<pre> |
||
Line 83: | Line 83: | ||
did nothing for me... and the no environment option is not a good one. |
did nothing for me... and the no environment option is not a good one. |
||
− | < |
+ | <code>set mouse=a</code> at least allows me to move in insert mode. |
− | === |
+ | ===Solution 4=== |
− | |||
− | ---- |
||
I had the same problem a few days ago. I figured out that i didnt have the ~.vimrc file. So, i went to /usr/local/share/vim/vim58 and copied the vimrc_example.vim to ~.vimrc. Problem solved! |
I had the same problem a few days ago. I figured out that i didnt have the ~.vimrc file. So, i went to /usr/local/share/vim/vim58 and copied the vimrc_example.vim to ~.vimrc. Problem solved! |
||
− | |||
---- |
---- |
||
I can confirm that the arrow-key problem (under freebsd) disappeared as soon as I introduced .vimrc |
I can confirm that the arrow-key problem (under freebsd) disappeared as soon as I introduced .vimrc |
||
− | |||
---- |
---- |
||
+ | This also works on a Synology NAS. |
||
− | === additional solution 5 === |
||
⚫ | |||
After experiencing this issue on FreeBSD 6 and 7 I found the clue as to why arrow keys would display A B C D when in insert mode - buried within ''':help nocompatible''' is this nugget: |
After experiencing this issue on FreeBSD 6 and 7 I found the clue as to why arrow keys would display A B C D when in insert mode - buried within ''':help nocompatible''' is this nugget: |
||
Line 101: | Line 98: | ||
:When a vimrc or gvimrc file is found while Vim is starting up, this option is switched off, and all options that have not been modified will be set to the Vim defaults. Effectively, this means that when a vimrc or gvimrc file exists, Vim will use the Vim defaults, otherwise it will use the Vi defaults. |
:When a vimrc or gvimrc file is found while Vim is starting up, this option is switched off, and all options that have not been modified will be set to the Vim defaults. Effectively, this means that when a vimrc or gvimrc file exists, Vim will use the Vim defaults, otherwise it will use the Vi defaults. |
||
− | So rather than mucking around with termcap settings create an empty < |
+ | So rather than mucking around with termcap settings create an empty <code>.vimrc</code> file first and see if the issue is resolved. Or, copy the default <code>vimrc_example.vim</code> to <code>~/.vimrc</code> If not, try the termcap suggestions. |
---- |
---- |
||
Line 110: | Line 107: | ||
set t_kd= (now type Ctrl-V and press cursor down) |
set t_kd= (now type Ctrl-V and press cursor down) |
||
set t_kr= (now type Ctrl-V and press cursor right) |
set t_kr= (now type Ctrl-V and press cursor right) |
||
− | set |
+ | set t_kl= (now type Ctrl-V and press cursor left) |
</pre> |
</pre> |
||
Line 136: | Line 133: | ||
Slightly different path for me, but confirmed it works on sunOS 10, also fixed my backspace issue, setup the colors, and search highlights. |
Slightly different path for me, but confirmed it works on sunOS 10, also fixed my backspace issue, setup the colors, and search highlights. |
||
⚫ | |||
− | ---- |
||
− | === additional solution 6 === |
||
− | |||
I have a similar problem but slightly different. After a very recent update of my system including vim71 the left and right arrow keys started to play up. They both moved left and right respectively, but only by word increments! |
I have a similar problem but slightly different. After a very recent update of my system including vim71 the left and right arrow keys started to play up. They both moved left and right respectively, but only by word increments! |
||
Line 148: | Line 143: | ||
:I had the same problem, but solved it in a better way by "se term=linux" in my .vimrc. That way, I don't lose my syntax highlighting, function keys, etc, and still managed to stop the "word jumping" arrow keys. |
:I had the same problem, but solved it in a better way by "se term=linux" in my .vimrc. That way, I don't lose my syntax highlighting, function keys, etc, and still managed to stop the "word jumping" arrow keys. |
||
+ | ===Solution 7=== |
||
− | ---- |
||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | ---- |
||
− | |||
⚫ | |||
− | |||
⚫ | I had the arrow keys switching from normal mode to insert mode when I was using vim in the terminal: E.g. pressing "up" would do the same as <Esc>OA, where <Esc> had no effect, O would switch to insert mode, and A would enter the letter "A". |
||
− | === |
+ | ===Solution 8=== |
⚫ | I had the arrow keys switching from normal mode to insert mode when I was using vim in the terminal: E.g. pressing "up" would do the same as <Esc>OA, where <Esc> had no effect, O would switch to insert mode, and A would enter the letter "A". The reason was that I in my .vimrc I had mapped <Esc> in normal mode to do funky stuff. Removing the mapping fixed it. |
||
+ | ===Solution 9=== |
||
On my default Ubuntu install, vi meant actual vi, but I was used to vim where this problem didn't occur. |
On my default Ubuntu install, vi meant actual vi, but I was used to vim where this problem didn't occur. |
||
Line 168: | Line 156: | ||
Also by default on Ubuntu 10.10 you can use vim-tiny and that takes care of the odd characters. |
Also by default on Ubuntu 10.10 you can use vim-tiny and that takes care of the odd characters. |
||
− | === |
+ | ===Solution 10=== |
− | |||
On my Gentoo and Debian installs, this problem was caused by the autoclose plugin and using the workarounds above didn't help. |
On my Gentoo and Debian installs, this problem was caused by the autoclose plugin and using the workarounds above didn't help. |
||
The only solution for me was to get rid of the autoclose plugin. |
The only solution for me was to get rid of the autoclose plugin. |
||
Line 179: | Line 166: | ||
---- |
---- |
||
− | It does seem like the version of autoclose distributed with Limp is causing this. |
+ | It does seem like the version of autoclose distributed with Limp is causing this. The latest version doesn't have this problem, although Backspace still isn't working for me. |
− | You can fix the arrow key problem by downloading the newest version of autoclose. |
+ | You can fix the arrow key problem by downloading the newest version of autoclose. You then need to modify mode.vim in Limp. Autoclose no longer has the functions AutoClose_start and AutoClose_stop, and mode.vim calls these functions. Edit mode.vim to change |
call AutoClose_start() |
call AutoClose_start() |
||
to |
to |
||
Line 190: | Line 177: | ||
AutoCloseOff |
AutoCloseOff |
||
+ | ===Solution 11=== |
||
− | Hope this helps. |
||
− | Nick Coleman |
||
− | |||
⚫ | |||
− | |||
I had this problem with a client's server config. Because I didn't have much power or permission to change things, and time was tight, I simply did the following and resolved the problem. |
I had this problem with a client's server config. Because I didn't have much power or permission to change things, and time was tight, I simply did the following and resolved the problem. |
||
− | |||
<pre> |
<pre> |
||
:set term=ansi |
:set term=ansi |
||
Line 203: | Line 185: | ||
If you ever have that kind of situation, give that a shot. |
If you ever have that kind of situation, give that a shot. |
||
− | === |
+ | ===Solution 12=== |
− | |||
I had this problem when I would ssh into a debian squeeze server. My solution was an alias on the server: |
I had this problem when I would ssh into a debian squeeze server. My solution was an alias on the server: |
||
− | |||
<pre> |
<pre> |
||
alias vim='vim.tiny' |
alias vim='vim.tiny' |
||
</pre> |
</pre> |
||
+ | ===Solution 13=== |
||
− | Hope this helps ... Pick2 |
||
⚫ | |||
+ | <pre> |
||
⚫ | |||
+ | </pre> |
||
+ | If ":echo $TERM" outputs "xterm-256color," and you are using putty in windows, make sure the above is unchecked or it will cause the issue. |
||
⚫ | |||
+ | ===Solution 14=== |
||
⚫ | |||
+ | I had this problem with a remote target, where I made a cross build for. For me it was sufficient to put an empty .vimrc file in my home. |
||
<pre> |
<pre> |
||
+ | touch ~/.vimrc |
||
⚫ | |||
+ | </pre> |
||
+ | |||
+ | ===Solution 15=== |
||
+ | I'm using ubuntu and the latest version of Vim from the apt repository with xubuntu's default terminal, which is xTerm IIRC. |
||
+ | <pre> |
||
+ | imap <ESC>oA <ESC>ki |
||
+ | imap <ESC>oB <ESC>ji |
||
+ | imap <ESC>oC <ESC>li |
||
+ | imap <ESC>oD <ESC>hi |
||
+ | </pre> |
||
+ | |||
+ | This solution is nearly identical to solution 2 with the exception that "^[O" from "imap ^[OA <ESC>ki" has been replaced with "<ESC>o" |
||
+ | |||
+ | I think the imap solution is preferable to any of that term modification stuff because I found that changing the term value corresponding with the other solutions on this page may completely lock out the ability to use escape characters, such as in the context of changing the cursor color depending on which mode you are in. Using imap is def. the least invasive solution. |
||
+ | |||
+ | ===Check whether a plugin is causing this behavior=== |
||
+ | This behavior can also be caused by a defective plugin. If you are using [https://github.com/tpope/vim-pathogen Pathogen] for managing your bundles (which you should), you can disable individual plugins by adding them to the list variable "pathogen_disabled" ([http://stackoverflow.com/questions/4261785/temporarily-disable-some-plugins-using-pathogen-in-vim StackOverflow tip]): |
||
+ | <pre> |
||
+ | let g:pathogen_disabled = ['delimitMate'] |
||
+ | </pre> |
||
+ | |||
+ | ===Solution 16=== |
||
+ | If you are using Cygwin or Cygwin64 Terminal, the "set nocompatible" in a .vimrc does not always work. |
||
+ | |||
+ | Run vi with -N (which does the same thing as nocompatible -- but works). |
||
+ | |||
+ | For example: |
||
+ | vi -N .bashrc |
||
+ | |||
+ | then add the line: |
||
+ | alias vim='vi -N' |
||
+ | |||
+ | Exit Vim and the terminal. |
||
+ | |||
+ | ===Solution 17=== |
||
+ | I tried all suggestions from this page, but the only thing that worked for me (Debian server, connected with "Konsole" from other linux), was to uninstall the vim-tiny package and to install the vim package. |
||
+ | |||
+ | ===Solution 18=== |
||
+ | Having "set noesckeys" in my ~/.vimrc set caused the problem to me with Vim 7.4 on Gnome Terminal on Debian. |
||
+ | |||
+ | ===Solution 19 for Terminal.app in MAC==== |
||
+ | Had issue with Up/Down in cscope/vim. Enable VT mode in Terminal Preferences " Allow VT100 application keypad mode |
||
+ | |||
+ | ===Solution 20=== |
||
+ | Add the following mappings in your .vimrc for whatever terms to disable arrow keys in normal and insert mode. It works for me. |
||
+ | <pre> |
||
+ | nnoremap <silent> <ESC>OA <Nop> |
||
+ | nnoremap <silent> <ESC>OB <Nop> |
||
+ | nnoremap <silent> <ESC>OC <Nop> |
||
+ | nnoremap <silent> <ESC>OD <Nop> |
||
+ | inoremap <silent> <ESC>OA <Nop> |
||
+ | inoremap <silent> <ESC>OB <Nop> |
||
+ | inoremap <silent> <ESC>OC <Nop> |
||
+ | inoremap <silent> <ESC>OD <Nop> |
||
</pre> |
</pre> |
||
− | [[Category:Temporary]] |
Revision as of 10:41, 2 October 2014
I wonder how many of you are annoyed with the arrow key behavior during insert mode in Vim.
Leave all the key mappings default, do not change your TERM environment. Here's a simple tip,
:set term=cons25
It was tested with Vim 5.8 and 6.1 editions on; FreeBSD 4.X-STABLE; xterm(-color),VT100 remote terminals; (t)csh shells.
Comments
Easy solution
1) Open Vim editor, 2) Get the path of your home directory by typing :echo $HOME 3) Check if you have .vimrc file in $HOME location,(if you don't have create it) 4) Add the following line line to .vimrc file set nocompatible or set nocp
It also fixes the "backspace won't delete" problem that some people have.
Solution 1
Try this mapping, worked on gvim v7.2
imap ^[OA <ESC>ki imap ^[OB <ESC>ji imap ^[OC <ESC>li imap ^[OD <ESC>hi
See solution 15 for another imap binding solution if this one doesn't work for you.
Note: ^[ is one symbol, try to enter it using <Ctrl-V>ESC or <Ctrl-V><Ctrl-[>
Solution 2
This doesn't really work very well for me on SunOS -- I have the same problem but :set term=cons25 just gives me OC everywhere before each character until I redraw. Weird.
But, :set term=ansi
works great, and the arrow keys work.
A better solution is to, while in vi, type in insert mode [ctrl-v][arrow up] and see what you get. Then, in your .vimrc, add the lines
set t_ku=[ctrl-v][esc]OA # or whatever you saw
so it ends up looking something like
set t_ku=^[OA set t_kd=^[OB set t_kr=^[OC set t_kl=^[OD
(though you want real escape chars instead of "^[".)
And in addition, set term=ansi makes syntax color off in vim (afair FreeBSD with color xterm).
Solution 3
So are we to be left with no good freebsd / bash solution?
set t_ku=^[OA set t_kd=^[OB set t_kr=^[OC set t_kl=^[OD
did nothing for me... and the no environment option is not a good one.
set mouse=a
at least allows me to move in insert mode.
Solution 4
I had the same problem a few days ago. I figured out that i didnt have the ~.vimrc file. So, i went to /usr/local/share/vim/vim58 and copied the vimrc_example.vim to ~.vimrc. Problem solved!
I can confirm that the arrow-key problem (under freebsd) disappeared as soon as I introduced .vimrc
This also works on a Synology NAS.
Solution 5
After experiencing this issue on FreeBSD 6 and 7 I found the clue as to why arrow keys would display A B C D when in insert mode - buried within :help nocompatible is this nugget:
- By default this option is on and the Vi defaults are used for the options. This default was chosen for those people who want to use Vim just like Vi, and don't even (want to) know about the 'compatible' option.
- When a vimrc or gvimrc file is found while Vim is starting up, this option is switched off, and all options that have not been modified will be set to the Vim defaults. Effectively, this means that when a vimrc or gvimrc file exists, Vim will use the Vim defaults, otherwise it will use the Vi defaults.
So rather than mucking around with termcap settings create an empty .vimrc
file first and see if the issue is resolved. Or, copy the default vimrc_example.vim
to ~/.vimrc
If not, try the termcap suggestions.
Do this:
$ vim ~/.vimrc set t_ku= (now type Ctrl-V and press cursor up) set t_kd= (now type Ctrl-V and press cursor down) set t_kr= (now type Ctrl-V and press cursor right) set t_kl= (now type Ctrl-V and press cursor left)
You should get something that looks like
set t_ku=^[OA set t_kd=^[OB set t_kr=^[OC set t_kl=^[OD
but the ^[ is actually a single escape character.
That certainly works for me here (FreeBSD 6.1, ssh in from Mac OS).
It also appears that it must be started as "vim" rather than "vi" in order to read the .vimrc file. I've added an alias to my bashrc scripts to take care of this... "alias vi=vim"
If you are using vi instead of vim, you need to update the above commands in .exrc file instead of .vimrc. Since alias makes you to work in vim, even you type vi.
"So, i went to /usr/local/share/vim/vim58 and copied the vimrc_example.vim to ~.vimrc. Problem solved!"
Slightly different path for me, but confirmed it works on sunOS 10, also fixed my backspace issue, setup the colors, and search highlights.
Solution 6
I have a similar problem but slightly different. After a very recent update of my system including vim71 the left and right arrow keys started to play up. They both moved left and right respectively, but only by word increments!
Setting ":set term=builtin_ansi" fixed the problem, so I knew it was a terminal problem.
Looking further ":set t_kl" reporting the weird string "^[O*D" Setting this to "^[[D" or "^[OD" has no effect on the arrow keys actions, it remains jumping by word.
Only setting "term=ansi" seems to help. But destroys use of function keys, and the alternate editing screen (preserving normal command line output display, when not editing). So I am stuck with 'word jumping arrow keys'.
- I had the same problem, but solved it in a better way by "se term=linux" in my .vimrc. That way, I don't lose my syntax highlighting, function keys, etc, and still managed to stop the "word jumping" arrow keys.
Solution 7
I had the same problem using Mandriva 2010. The solution was to install vim-common from the urpmi repository.
Solution 8
I had the arrow keys switching from normal mode to insert mode when I was using vim in the terminal: E.g. pressing "up" would do the same as <Esc>OA, where <Esc> had no effect, O would switch to insert mode, and A would enter the letter "A". The reason was that I in my .vimrc I had mapped <Esc> in normal mode to do funky stuff. Removing the mapping fixed it.
Solution 9
On my default Ubuntu install, vi meant actual vi, but I was used to vim where this problem didn't occur.
My solution was apt-get install vim.
Also by default on Ubuntu 10.10 you can use vim-tiny and that takes care of the odd characters.
Solution 10
On my Gentoo and Debian installs, this problem was caused by the autoclose plugin and using the workarounds above didn't help. The only solution for me was to get rid of the autoclose plugin.
Same problem here, the issue appeared on my machine after installing "Limp for Vim", Lisp IDE, for all open Lisp files. Disabling autoclose plugin in Limp got me the arrow keys back. Thanks!
It does seem like the version of autoclose distributed with Limp is causing this. The latest version doesn't have this problem, although Backspace still isn't working for me.
You can fix the arrow key problem by downloading the newest version of autoclose. You then need to modify mode.vim in Limp. Autoclose no longer has the functions AutoClose_start and AutoClose_stop, and mode.vim calls these functions. Edit mode.vim to change
call AutoClose_start()
to
AutoCloseOn
and
call AutoClose_stop()
to
AutoCloseOff
Solution 11
I had this problem with a client's server config. Because I didn't have much power or permission to change things, and time was tight, I simply did the following and resolved the problem.
:set term=ansi
If you ever have that kind of situation, give that a shot.
Solution 12
I had this problem when I would ssh into a debian squeeze server. My solution was an alias on the server:
alias vim='vim.tiny'
Solution 13
If you are using putty in windows, try to disable application cursor keys mode:
Session config -> Terminal -> Features -> [V] Disable application cursor keys mode
If ":echo $TERM" outputs "xterm-256color," and you are using putty in windows, make sure the above is unchecked or it will cause the issue.
Solution 14
I had this problem with a remote target, where I made a cross build for. For me it was sufficient to put an empty .vimrc file in my home.
touch ~/.vimrc
Solution 15
I'm using ubuntu and the latest version of Vim from the apt repository with xubuntu's default terminal, which is xTerm IIRC.
imap <ESC>oA <ESC>ki imap <ESC>oB <ESC>ji imap <ESC>oC <ESC>li imap <ESC>oD <ESC>hi
This solution is nearly identical to solution 2 with the exception that "^[O" from "imap ^[OA <ESC>ki" has been replaced with "<ESC>o"
I think the imap solution is preferable to any of that term modification stuff because I found that changing the term value corresponding with the other solutions on this page may completely lock out the ability to use escape characters, such as in the context of changing the cursor color depending on which mode you are in. Using imap is def. the least invasive solution.
Check whether a plugin is causing this behavior
This behavior can also be caused by a defective plugin. If you are using Pathogen for managing your bundles (which you should), you can disable individual plugins by adding them to the list variable "pathogen_disabled" (StackOverflow tip):
let g:pathogen_disabled = ['delimitMate']
Solution 16
If you are using Cygwin or Cygwin64 Terminal, the "set nocompatible" in a .vimrc does not always work.
Run vi with -N (which does the same thing as nocompatible -- but works).
For example:
vi -N .bashrc
then add the line:
alias vim='vi -N'
Exit Vim and the terminal.
Solution 17
I tried all suggestions from this page, but the only thing that worked for me (Debian server, connected with "Konsole" from other linux), was to uninstall the vim-tiny package and to install the vim package.
Solution 18
Having "set noesckeys" in my ~/.vimrc set caused the problem to me with Vim 7.4 on Gnome Terminal on Debian.
Solution 19 for Terminal.app in MAC=
Had issue with Up/Down in cscope/vim. Enable VT mode in Terminal Preferences " Allow VT100 application keypad mode
Solution 20
Add the following mappings in your .vimrc for whatever terms to disable arrow keys in normal and insert mode. It works for me.
nnoremap <silent> <ESC>OA <Nop> nnoremap <silent> <ESC>OB <Nop> nnoremap <silent> <ESC>OC <Nop> nnoremap <silent> <ESC>OD <Nop> inoremap <silent> <ESC>OA <Nop> inoremap <silent> <ESC>OB <Nop> inoremap <silent> <ESC>OC <Nop> inoremap <silent> <ESC>OD <Nop>