I've been getting more and more comfortable using vi on a daily basis, but one thing that bothers me is that when I use it on Ubuntu it behaves differently than when I use it on CentOS (and probably other places). I actually prefer the way it works in CentOS.
Here are three things that are really bothering me on Ubuntu:
In CentOS insert mode there is a big bold notice at the bottom that I'm in INSERT mode, but in Ubuntu there is no notice so I can never tell which mode I'm in.
In CentOS insert mode I can press the up/down keys and the cursor will move up and down. But when I'm in Ubuntu pressing up and down inserts the letters A and B respectively on new lines.
In CentOS insert mode I can use the backspace key and it will delete the character that is before the cursor, but in Ubuntu I just hear a beep sound and nothing happens. I can press the delete key in command mode, but I'd rather be able to press the backspace key.
Are these differences something that I have to live with or is it an easy fix?
In ubuntu, the default vim install comes from the package vim-tiny, which isn't the whole thing.
You probably want to:
apt-get install vim
or
apt-get install vim-full
Some of your other problems sound like issues with the backspace key and other things. Once you get the full version of vim, try adding these to your .vimrc:
set nocompatible
set t_kb=^H
fixdel
(IMPORTANT NOTE: that ^H is a literal ctrl-H character, which you'll get by doing Ctrl-V Ctrl-H in insert mode)
The previously offered answers did not work for me.
I tend to prefer leaving OS installations as stock as possible and keeping config files as simple as possible. In order to fix these three issues in Ubuntu 12.04, I did the following:
In "~/.vimrc", insert the lines -
set nocp
set bs=2
In addition to installing vim-full, if you do not already hava a ~/.vimrc:
$ cp /usr/share/vim/vimcurrent/vimrc_example.vim ~/.vimrc
This example .vimrc already makes the most important settings and is a good start for customization.
I'll assume you mean VIM when you say VI? And at least, the 2nd point seems to be a console/terminal issue with VIM/term combo. The page below suggests some fixes, but none that I could make work (I use vim over putty to an Ubuntu dev box)
http://vim.wikia.com/wiki/Fix_broken_arrow_key_navigation_in_insert_mode
3rd point can be overwritten by using the following in your .vimrc
set backspace=indent,eol,start
(1) Check if showmode setting is different on both.
(2) Don't know about this one, I think this has more to do with the terminal than Vi itself.
(3) Maybe try using :map <BS> :normal d ?
In CentOS, vi is an alias for a different program, vim, but in recent versions of Ubuntu, vi means just vi, not vim. The difference you see if the difference between two different programs, vi and vim.
If you like vim, just run vim, not vi. This works in Ubuntu too
Setting this in my .vimrc worked for me..
set term=builtin_ansi
I Have WDMyCLoud with Debian 7 inside, im using like:
cp /usr/share/vim/vimcurrent/debian.vim ~/.vimrc
In my case, the .vim file is created as follows:
set nocompatible
fixdel
If I add set t_kb=^H, the backspace key just hehaves as delete key.
Related
I'd like vi to show -- INSERT MODE -- whenever I tap I to enter insert mode, but it doesn't show such a message when I use it with PuTTY.
Why does it happen? And how do I make Vim display the mode I'm in? This is very important for me to get it right the first time.
Put the following line in your .vimrc file. It will show the current mode on the last line.
set showmode
I believe putting set showcmd in your .vimrc should do the trick. (Or just enter :set showcmd from inside vim)
Finally,I solved this problem by reinstall vim!
I think my Ubuntu OS caused this problem,as I'm using Chinese localization Ubuntu,there are some bugs with it.
I will try native Ubuntu later,thanks all !
I have a Ubuntu 12.04 OS. I installed vi and vim, but the backspace doesn't work properly. It is doing the same thing that delete key do.
I am expecting the backspace key to delete a character backwards, but it deletes forwards. I did some search on the Internet, there are too much suggestions for changing the .vimrc file, but non of them worked for me.
Is there anybody who has the same issue?
As explained in answer SO/a/10197995/1699311, you have to correct your terminal setting.
However, if you really want to stick with incorrect terminal behaviour (which will affect some other programs) you can instruct Vim to accommodate with that with :fixdel (it internally swap Backspace and Delete keys.)
All the previous suppose you don't have some mapping on that key.
Try adding the following to your .vimrc file, which would correct the behavior of the backspace key:
set backspace=2
Also, you can execute it inside vi/vim command mode:
:set backspace=2
Additionally, here is more information and solutions if this doesn't work for you: http://vim.wikia.com/wiki/Backspace_and_delete_problems
If your backspaces deletes forward you can use the command in vimrc file as shown below
set backspace=2
now on the vi command mode do the follwoing to re-excecute the .vimrc file
:so %
To know which .vimrc file is being read do the following
:echo $MYVIMRC
I am using Cygwin 1.7.22 (32-bit) on Windows 8 (64-bit). Within Cygwin, I am using Vim 7.3.1152, which is the default version.
Behavior that seem like bugs:
When I press I to enter insert mode, it does not say -- INSERT -- in the bottom left. In fact, it doesn't say anything. It does behave correctly, though.
When I delete letters using Backspace in insert mode, the letters do not disappear but the cursor does move to the left.
When I use the arrow keys in insert mode, it enters the letters A, B, C, and D, rather than moving the cursor. The arrow keys work normally outside of insert mode.
How do I make Vim behave as I expect?
Create a ~/.vimrc file with the following contents to put vim in nocompatible mode (actually the mere presence of the file is sufficient.)
set nocompatible
The behavior you are seeing is how vi used to behave. These are not bugs.
Take a look at :h nocompatible
In vim compatible mode tries to emulate vi as closely as possible.
--insert-- is not part of vi so it not shown in compatible mode.
I believe vi did a lazy redraw of the screen and didn't update until you exited back to normal mode. Also backspace is only usable also only works on stuff that was entered in the current insert mode. Overall its not very user friendly.
The arrow keys are sent to vim as escape sequences (escape followed by a coupled of letters). Let ^[ be escape. ^[OA is up on my computer its probably something similar on yours. vim sees this as an escape (goes back to normal mode), and O (add a line above the current) and A which is the A you see entered onto your screen. This just means that vim in compatible mode does not interpret the escape characters properly. Most likely because vi did not interpret them (nor was it designed to use them).
set nocompatible fixes problems 1 and 3.
I think set backspace=indent,eol,start should fix problem 2.
This was asked months ago, but I am answering for future reference for anyone else who encounters this problem.
I was just bitten by this issue. All advice listed in this post, and in other posts on this forum (not to mention posts on other forums) does not work, at least for some of us. I finally figured out the real issue.
vim on cygwin, for whatever reason (at least this was the case for me) does not use the .vimrc you put in your directory. Let's say you copy the example one to your working directory, or copy some .vimrc from online. Or maybe you create a new one from scratch, and put all the settings the good people here and elsewhere recommend (set backspace = blahblah, set nocompatible, set this, set that). It doesn't work. Why? Because for whatever reason (at least in my case) vim isn't looking at the .vimrc you just created.
The solution is to FORCE vim to use a particular .vimrc, by passing in -u on the command line like so:
vim -u [/INSERT/PATH/TO/.vimrc]
For the love of all that is holy, DO NOT type square brackets or the words "/INSERT/PATH/TO/.vimrc" verbatim. Use your brain please.
Anyway, this solved my problems and I was able to use the default example .vimrc and get proper delete and backspace behavior while in insert mode, not to mention other goodies.
You might want to alias the vim command in your .bashrc like this:
alias vim='vim -u [/INSERT/PATH/TO/.vimrc]'
Regarding A,B,C,D for arrow keys in Vim, adding:
:set term=cons25
to ~/.vimrc worked like a charm.
source: http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell
Following different answers in this topic I found a simple solution.
$ vi --version | head
VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Mar 30 2020 21:54:08)
Included patches: 1-486
Modified by <cygwin#cygwin.com>
Compiled by <cygwin#cygwin.com>
$ vi --version | grep 'user vimrc'
user vimrc file: "$HOME/.virc"
2nd user vimrc file: "~/.vim/vimrc"
So I just created ~/.virc (not vimrc) and it works! The content of the file:
set nocompatible
Probably, if you already have this file you will add the above string in it. Or, as people say above, if you have an empty ~/.virc, nocompatible mode must be already in use (I didn't check it).
Apart of the question, line numbers (that I find very useful) may be shown in vi by adding:
set number
After enabling set mouse=a, text copied inside of Vim will not paste outside of Vim. Does anybody know of a way to fix this?
Here, selecting text with the mouse turns on visual mode and disables the Copy option in the popup menu:
Press shift while selecting with the mouse. This will make mouse selection behave as if mouse=a was not enabled.
Note: this trick also applies to "middle button paste": if you want to paste in vim text that was selected outside, press shift while clicking the middle button. Just make sure that insert mode is activated when you do that (you may also want to :set paste to avoid unexpected effects).
OS X (mac):
hold alt/option while selecting (source)
Use ", +, y after making a visual selection either with the keyboard or the mouse. You shouldn’t be using the terminal’s copy command anyway, because that copies what the terminal sees instead of the actual content. Here is what this does:
",+ tells Vim to use the register named + for the next delete, yank or put. The register named + is a special register, it is the X11 clipboard register. (On other systems, you would use * instead, I think, see :help clipboard and :help x11-selection)
y is the yank command, which tells Vim to put the selection in the register named previously.
You could map it like this:
:vmap <C-C> "+y
And then highlight something with the mouse and press Control-C to copy it.
This feature only works when Vim has been compiled with the +xterm_clipboard option. Run vim --version to find out if it has.
Instead of set mouse=a use set mouse=r in .vimrc
On OSX use fn instead of shift.
In Ubuntu, it is possible to use the X-Term copy & paste bindings inside VIM (Ctrl-Shift-C & Ctrl-Shift-V) on text that has been hilighted using the Shift key.
Another OSX-Mac option is to uncheck View->Allow Mouse Reporting (or press ⌘-R to toggle it.) This allows you to toggle between mouse interaction and mouse selecting, which might be useful when selecting and copy/pasting a few bits because you don't have to hold a modifier key to do it.
Note for Multiline with line numbers:
I usually have line numbers enabled so this will also copy the line numbers if you select multiple lines. If you want to copy multiple lines without the line numbers disable the numbers with :set nonu and then you can :set nu to re-enable them after you're done copying.
Holding shift while copying and pasting with selection worked for me
You can use :set mouse& in the vim command line to enable copy/paste of text selected using the mouse. You can then simply use the middle mouse button or shiftinsert to paste it.
I accidently explained how to switch off set mouse=a, when I reread the question and found out that the OP did not want to switch it off in the first place. Anyway for anyone searching how to switch off the mouse (set mouse=) centrally, I leave a reference to my answer here: https://unix.stackexchange.com/a/506723/194822
Compilation settings that vim was compiled with, are part of the issue. vim --version shows these.
In OSX, the default vim has -clipboard But you need +clipboard
On osx you can and apparently generally should, use macvim. You can do brew cask install macvim That one has +clipboard.
Them you'll have two vims.
~$ ls -l /usr/bin/vim <--- default vim
-rwxr-xr-x 1 root wheel 1745984 15 Jul 2017 /usr/bin/vim
~$ ls -l /usr/local/bin/vim <-- macvim, installed recently via that mentioned brew line.
lrwxr-xr-x 1 apple admin 42 16 May 23:32 /usr/local/bin/vim -> /Applications/MacVim.app/Contents/bin/mvim
~$
running vim will run macvim 'cos /usr/local/bin should be before /usr/bin in the path, though you can check with which vim.
running vim(to run macvim), is fine but you may want to map vi to macvim 'cos otherwise running vi stays at the default vim! You can rewrite or delete(with rm) and recreate the vi sym link, with ln. And to do that without an 'operation not permitted" error, you have to (temporarily) disable SIL. https://apple.stackexchange.com/questions/208478/how-do-i-disable-system-integrity-protection-sip-aka-rootless-on-macos-os-x .
macvim has +clipboard as shown by vim --version
Here is a working ~/.vim/vimrc with just the required lines.
:set mouse=a
:map <leader>c "+y
:map <leader>v "+p
The default leader key is backslash.
I read a suggestion that one should use the leader key.. (certainly control has many keys already in use, so the suggestion was to not use control. I don't know if that applies to command key too, but anyhow).
With that mentioned mapping, \c will do "+y which will copy from the register known as +, to the clipboard. And \v will paste from the register known as +.
So that's a copy/paste that works between windows.
Another OS may require "* rather than "+
Add set clipboard=unnamed to your .vimrc. So it will use the clipboard register '*' instead of the unnamed register for all yank, delete, change and put operations (note it does not only affect the mouse).
The behavior of register '*' depends on your platform and how your vim has been compiled (or if you use neovim).
If it does not work, you can try with set clipboard=unnamedplus, but this option only makes sense on X11 systems (and gvim therefore).
If you are using, Putty session, then it automatically copies selection.
If we have used "set mouse=a" option in vim, selecting using Shift+Mouse drag selects the text automatically.
Need to check in X-term.
em...
Keep pressing Shift and then click the right mouse button
Also worth mentioning, by having set mouse=nvi, when doing a selection and then pressing : <ESC> you will get the mouse selection copied to the primary selection clipboard (equivalent to a "*y).
Reference: help mouse
Main advantage of this method is the fact that if you have multiple vertical splits, it will only select from the current buffer. Using <Shift> as mentioned in the main answer, will, in this case, copy from all 3 files at the same time which is not exactly what one would want, expect or need.
A good workaround which is worth adding:
GPM daemon can be used which is a a cut and paste utility and mouse server for virtual consoles. It will provide functionalities across all the virtual consoles!
Copy-Paste actions can be done by <CTRL-C>/<CTRL-V>.
sudo apt-get install gpm
MAN pages of GPM
set set mouse=a in vi, using MobaXterm, after installing vim-gtk3 on server, dragging with mouse and Ctrl + Insert works, but seems it only work with MobaXterm
after installing vim-gtk3, vi will link to it
lala#kubu:~$ sudo apt install gvim
[sudo] password for lala:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package gvim is a virtual package provided by:
vim-gtk3 2:8.2.2434-3ubuntu3.2
vim-athena 2:8.2.2434-3ubuntu3.2
You should explicitly select one to install.
E: Package 'gvim' has no installation candidate
lala#kubu:~$ which vi
/usr/bin/vi
lala#kubu:~$ file /usr/bin/vi
/usr/bin/vi: symbolic link to /etc/alternatives/vi
lala#kubu:~$ file /etc/alternatives/vi
/etc/alternatives/vi: symbolic link to /usr/bin/vim.gtk3
lala#kubu:~$
In ESC mode, when set mouse=a, select the text using mouse. This would enable the visual mode in vim. Then you can press 'y' to yank the selected text and 'p' to paste it wherever you want. This happens only within vim.
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.