I'm having issues with my backspace in Vim, it is inserting ^? instead of deleting characters. I found this wonder bit of Vim documentation that will hopefully fix this problem.
If the backspace key terminal code is wrong you can
use this:
:if &term == "termname"
: set t_kb=^V<BS>
: fixdel
:endif
Where "^V" is CTRL-V and "<BS>" is the backspace key
(don't type four characters!). Replace "termname"
with your terminal name.
I am trying to add this bit of code to my .vimrc as the site suggests, but how do I know what my "terminal name" is?
When you see &something in Vimscript, the something stands for one of Vim’s options (as are set with :set); &something refers to the current value or setting of something. You can use echo (or echom) to get the current setting of a given option. So in this case, you can get the terminal name — what is referred to in that code as &term — by starting Vim and running
:echom &term
and you can then replace termname in the code with the result.
(You can also use :set for this, as it turns out, by appending a ? to the option; running
:set term?
would print out the current setting of term, as e.g. term=xterm-color.)
Related
my setting for command mode completion is:
set wildmenu
set wildmode=longest,list,full
currently when i type
:set fdm=
in command mode, then press tab, manual appended, if i Press tab again , character ^I appended, what i want is manual changed to another foldmethod options such as syntax, indent and so on.
does anyone know is that possible or if there is any plugin could do that ?
thanks !
As you say, when you press <Tab> after :set fdm=, you get manualinserted.
That could seem the usual autocomplete behaviour we are used to in many places, manual being just the first of all possible values. So, you expect that repeating <Tab> will give you more possibilites.
But that's not indeed the case. What you get when pressing <Tab> in such a situation is not the first autocompletion alternative, but the current option value. So, you're getting manual because that's in fact the default value for that option. Successive <Tab>s get inserted literally, as this behaviour is only fired right after =.
From Vim's help:
The old value of an option can be obtained by hitting 'wildchar' just after
the '='. For example, typing 'wildchar' after ":set dir=" will insert the
current value of 'dir'. This overrules file name completion for the options
that take a file name.
So, what you described is expected behaviour. See :help cmdline-completion for the whole story.
I don't know about any plugin capable of changing this to what you want.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
vim backspace leaves ^?
My Vim Backspace is not working correctly. When I press it, it prints out ^?. I found some other suggestions on how to fix it such as adding set backspace=indent,eol,start to the .vimrc. But this does not seem to work right. Does anyone have any other ideas on how to fix this?
Thanks!
perreal's answer tells you how to alter the Linux console to match vim's current settings, but you also have the option of altering vim's settings to match the Linux console. The relevant options are t_kb and t_kD to tell vim what characters the terminal generates when you press the Backspace and Delete keys respectively. Query the current settings first so you can see what they're set to:
:set t_kb? t_kD?
and then change them like this:
:set t_kb=XXX t_kD=XXX
In place of the XXX's you should type Ctrl-V followed by Backspace for the first one and Ctrl-V followed by Del for the second one.
There's another question you could be asking, about why these settings weren't properly detected in the first place. If you're interested in investigating that, we'll need to see your $TERM variable and the corresponding terminfo database entry, which you can get with:
echo $TERM
infocmp | egrep 'kdch1|kbs'
From vim-docs :help fixdel
Note about Linux: By default the backspace key produces CTRL-?,
which is wrong. You can fix it by putting this line in your
rc.local:
echo "keycode 14 = BackSpace" | loadkeys
I noticed that iTerm2 offers the very convenient feature of using "Option key as +ESC" (or as meta, but apparently that's obsolete).
I tried them both and the option key works as expected in Bash (set -o emacs mode) and Emacs, but not in Vim. Thus, I can't make use of any "M-" bindings.
What I've found is that:
if I set option to "+ESC", vim just understands ESC+key, and has no idea I actually meant Meta-key.
if I set option to "meta", keys modified with "option" behave just as without a modifier (don't know how to formally test what vim understands from a key combination that I'm typing).
"M-" mappings work perfectly in MacVim (7.3.53), but that's outside of a console and not in the scope of this question.
I'm interested in how to make those mappings work in Vim, under iTerm2 or Terminal.
My specs:
MAC OS X Lion 10.7.2
iTerm2 1.0.0.20111020
vim #7.3.107_0+python26 [though MacPorts]
I've downloaded the latest iTerm2 and tried to see what it sent to/what was printed by Vim (i<C-v><M-a>) with the following settings:
Option as Option:
Vim prints æ which is normal and expected on my french keyboard
Option as Meta:
Vim stays there, waiting for something to happen. Nothing is printed. If I press Option and a in sequence I just obtain a. Pressing Option and a in some random order may print á, which is weird and totally unexpected.
Option as +ESC:
Vim prints ^[a which means "Escape character followed by the character a".
From these tests it appears that Vim will never ever receive <M-> without some hypothetical black magic.
If you stick with "Option as +ESC", it seems that you will have to change all your custom <M-something> mappings to <Esc>something. This may work but it will make writing any kind of prose in any non-english language a pain.
What I do: I leave the Option key as it is so that I can type characters like œ…«» easily and I use <Leader> (mapped to ,, see :help mapleader) for all my custom mappings.
Some people here like to reserve it for plugins and advocate a somewhat simpler and potentially safer approach.
inoremap <leader>, <C-x><C-o> "my way (copied elsewhere)
inoremap ,, <C-x><C-o> "another way
I left my option key to act as Normal and discovered that Vim saw them as <T- bindings. So, for example, I have this mapping setup in my .vimrc to move to the end of a word when in Insert mode:
noremap! <T-Right> <C-o><Right>;
I use the made of code theme. I was previously using macvim but switched to standard vim and am not seeing my normal syntax highlighting. Is there a way to get it to work?
I've confirmed that :colorscheme is madeofcode, as well as echo $g:colors_name. Thanks.
then it is probably showing, but you might
not have defined ctermfg, ctermbg etc. (just guifg/guibg)
the terminal might not be capable of displaying all the colours
See also
16. Color xterms *xterm-color* *color-xterm*
Most color xterms have only eight colors. If you don't get colors with the
default setup, it should work with these lines in your .vimrc: >
:if &term =~ "xterm"
: if has("terminfo")
: set t_Co=8
: set t_Sf=<Esc>[3%p1%dm
: set t_Sb=<Esc>[4%p1%dm
: else
: set t_Co=8
: set t_Sf=<Esc>[3%dm
: set t_Sb=<Esc>[4%dm
: endif
:endif
< [<Esc> is a real escape, type CTRL-V <Esc>]
You might want to change the first "if" to match the name of your terminal,
e.g. "dtterm" instead of "xterm".
Note: Do these settings BEFORE doing ":syntax on". Otherwise the colors may
be wrong.
Type :echo &term to know your &term, try $ echo $TERM in Terminal.app too to see if it's the same, just in case.
The $TERM/&term you need is xterm-256color.
You either set it from Terminal.app's preferences or from within Vim, like in sehe's answer, or as an argument when actually lauching Vim: vim -T xterm-256color.
Beware, though, trying to use a different terminal type than the one declared by Terminal.app will most definetly mess up with lots of things including colour and keymaps.
Sorry, wrote up answer below before I noticed in a comment that you are on OS x. That's a different ball of wax, I think, I recall seeing fairly long SO thread on this issue for terminals on OS X. . . although this thread seems to indicate my solution works using iTerm:
iterm vim colorscheme not working
This may also work, and is preferable to changing your terminal type. Just put the line below in your vimrc before any colorscheme command. Your xterm should support 256 colors, at least mine in Ubuntu does:
let &t_Co=256
That should fix the problem if the problem is xterm defaulting to too few colors, which you can confirm by doing :echo &t_Co in your terminal before applying fix above. If it's currently a number less than 256 then it should help.
I think the help section on color-xterm quoted in another answer must be old. My xterm on Ubuntu supports 256 as long as I do set t_Co=256 or equivalent let statement above, and Wikipedia indicates that xterm supports 256 colors:
http://en.wikipedia.org/wiki/Comparison_of_terminal_emulators
http://en.wikipedia.org/wiki/Xterm
I'm trying to get into Vim. I'm running it in the terminal on OS X.
Anytime I hit the delete key, it simply changes case of that letter instead of deleting it. When I SSH into my server and use Vim there, it deletes normally.
Any ideas what may be going wrong?
The problem
The Del key generates the code ^[[3~ in my urxvt terminal on GNU/Linux, and might generate a similar code in your OS X terminal.
My theory is that Vim for some reason doesn't recognize any keybinding for the delete key, and simply tries to interpret the string ^[[3~ as input instead. ^[ is the keycode for the Esc key (which puts you in normal mode), and ~ is the Vim command for changing the case of a letter (from normal mode).
You can confirm the keycodes I mentioned by pressing Ctrl+V Esc and Ctrl+V Del from insert mode in Vim. Ctrl+V means that the next character should be inserted as text instead of being interpreted by the editor.
The solution
As for the solution, try editing your Vim configuration file (presumably ~/.vimrc):
vim ~/.vimrc
And append the following code to it:
nmap <Ctrl-V><Del> x
imap <Ctrl-V><Del> <Ctrl-V><Esc>lxi
I hope this helps :)
The problem was that in my .vimrc I had
set term = ansi
Took that out and all was well - sorry about the troubles, thanks!
Well, this took forever for me to resolve. When using vim I was in Iterm2 on macOSx to access a Centos5 system via gnu screen. Not only was the delete key changing the letter case, and causing delays in vim, but also the arrow keys didnt work. I think the problem was simply in the old configuration on the Centos5 machine, but may have had something to also do with either iterm or gnu screen, but i hadnt had this issue at all on any Centos6 systems.
What did Not work:
I compile vim 7.4, that did not resolve it, so don't go down that path.
I also tried these configurations that did not work
"set term=ansi
"set backspace=indent,eol,start
"set nocompatible
"fixdel
":if &term == "xterm"
":if &term == "xterm-256"
": set t_kD=^V<Delete>
":endif
"nmap <Ctrl-V><Del> x
"imap <Ctrl-V><Del> <Ctrl-V><Esc>xi
I finally found the solution.
Solution: Set the following in .vimrc
set term-builtin_xterm
Additionally, you may also notice that 256 colors have an issue on this same system. So if it helps, you can check your TERM environment variable echo $TERM. If it is xterm you can switch it to 256 colors, e.g. export TERM='xterm-256color to get the color schemes back on track for this same system. reference
I had the same issue where vim suddenly interpreted keys differently.
The answer for me was that the environment variable $TERM had somehow been to to 'dumb' in my terminal.
I added
export TERM=xterm-color
to ~/.bashrc (in my case) and that fixed all the issues with keys; DEL worked as expected etc.
I didn't need to add or change anything in ~/.vimrc
I should mention this affected more than just vim for me - if you also see 'less' behave differently for example, you may have the same cause as I did.
I use vim regularly on my OSX machine (vim version 7.2.108), and I do not have this issue. Try renaming your vimrc file and then reload vim, and see if the issue persists. If there is no issue after renaming you vimrc file, then your issue is in that file.
On my machine, my vimrc file is pretty much empty:
set ruler
set tabstop=2
set cindent
set number
syntax on
None of these solutions worked for me, until I found a solution on the vim fandom website.
Those solutions are for a similar problems with arrow keys, which I was experiencing in addition to the delete key problem.
Solution 8 fixed it for me, the problem was that I had remapped <Esc> to <Esc>l in order to move the cursor right every time I entered normal mode, evidently this caused any other key code with included ^[ (which is the escape code) including the arrow keys ( ^[OA ^[OB etc ) and the delete key ( ^[[3~ ) to be misunderstood.
Removing the offending line from my .vimrc fixed the problem.