While moving the cursor across a vim process open in a tmux session, every now and then, why does it leave a trail of ghost characters - ^[OB, ^[OA? - vim

These disappear if I do a page-up and page-down. Why does this happen and how do I rectify it?
http://i.stack.imgur.com/DnMYl.png
I recently fiddled around with my vimrc. Could that be the cause?
UPDATE:
I figured out the cause. I had added to functions that automatically updated the cwd name and the current git branch in my vim statusline. This caused vim to be laggy and everytime it lagged on a up/down/left/right key hit, it printed out the ghost characters ^[OA, etc.
It's possible that stuff got complicated because I was using vim in tmux, but I saw the ghost characters outside tmux also. So, probably not.
I've turned off those two functions in my .vimrc and my vim statusline is presently less awesome than it used to be :(
Wish there's a way out.

^[OB and ^[OA are how your terminal represent <down> and <up>.
I've seen these (and their friends ^[OC and ^[OD) appear in the "command line" or omni-completion menus and during usage of a couple of plugins in vim in tmux.
My solution was to map them to the directional keys:
map ^[OA <up>
map ^[OB <down>
map ^[OC <right>
map ^[OD <left>
In case you don't know, you must not type ^[ as two characters, you must do <C-v><Esc>.
That is, while in --INSERT-- mode press the Control key and the V key together then hit the Escape key. Doing so will input the correct single character that looks like ^[.

This issue is discussed at length on the Vim Wiki article. There seem to be multiple causes, I personally encountered this issue when running vim under tmux.
A solution from there that worked for me and seems less hacky than mapping the keys was the following config:
set term=cons25

Hard to say without knowing what's in your vimrc, but you can confirm whether it's something in there by starting it up without running it and seeing if it still happens using the following...
vim -u NONE

Do you happen to be using zsh? I had this issue with vim + zsh/oh-my-zsh. Moving back to vanilla bash solved this issue (amongst others) that I was having with vim.

Related

Sometimes Vim starts ignoring mappings on Ctrl-keys

Lately, when using Vim in tmux over ssh, sometimes something happens where Vim starts ignoring all my mappings that start with Ctrl: for instance <C-P>, which I have bound to the CtrlP plugin. Instead, Vim runs the builtin action (in this case, moving lines upward in the file). I don't doubt that the correct keypress is reaching Vim, as it uses the correct builtin action associated with <C-P> (using :send-keys to send ctrl-p from tmux also causes the builtin <C-P> in vim to run, instead of the mapping).
All my mappings not involving the control key still work. For instance, I can do this:
nnoremap p :echo "test"<cr>, and pressing p echoes test
But then immediately after,
nnoremap <c-p> :echo "test"<cr>, and pressing CTRL-P doesn't echo test, it moves the cursor up one line.
Restarting Vim always fixes the issue, but at some point, something I do causes the problem to surface again. I've been working mostly in tmux through ssh lately, so I'm not 100% sure if either one of those are the problem (although I think I recall this happening once in Vim in tmux not over ssh), but as mentioned above, I believe using send-keys directly from tmux as a test is ensuring that vim is getting the actual ctrl-p keycode. As well, <C-V><C-P> in insert mode does actually insert ^P.
Note that although I've used ctrl-p here as an example, since it's a key I actually use a lot in practice, this applies to any control key mapping.
Is there some kind of Vim state I don't know about that's causing this to happen? Is this likely a terminal problem? What are my next steps?

Cursor flash: Backspace-issue in Terminal Vim

Note:
This is a plugin-induced problem, but it happens with multiple plugins and it does not happen in MacVim.
Problem:
When hitting Backspace in Insert mode while using a plugin which handles automatic closing of brackets, quotes and such (delimitMate, vim-autoclose), the cursor turns into a block while deleting the character (this happens faster than I can blink my eyes but remains one of my pet peeves on terminal Vim), giving the impression of a tiny flash, which on every deletion of a character becomes annoying.
I presume it leaves Insert-mode to perform an normal/ex command), due to the remap done by the plugins, and I can confirm that this "changes to block and back"-flash does NOT happen with the plugins disabled.
The mapping for each of the plugins is as follows:
delimitMate
:verbose imap <BS> => i <BS> #<Plug>delimitMateBS
vim-autoclose:
:verbose imap <BS> => i <BS> *#<C-R>=<SNR>44_Backspace()<CR>
This problably means nothing as I'm not posting what the invoked functions actually do, it's just meant to show that Backspace is being remapped.
You're probably eager to point me to the issue tracker of each specific plugin at this point, but like mentioned earlier, this issue does not happen in MacVim. Perhaps it does, perhaps it's simply happening too fast for my eyes to see, but while using MacVim, there is absolutely no visible cursor change/flash.

VIM keybinding to jump back to initial position after indenting the whole file

I have created a keybinding that should indent a whole file.
My first solution looked like this:
map <F4> gg=G
The problem is that after pressing F4, the cursor jumped to the first line of the file. So I have tried to improve my solution with the feature of markers, look like this:
map <F4> mzgg=G'z<CR>
I expected this would have resolved my problem, but the command do the same as the first. When I try to jump to the z marker manually vim told me "marker not set".
After changing the keybinding, I have or course restarted vim! I am using the GVIM 7.3 on a WIN 7 machine.
Thank you in advance for your Help!
Edit:
After trying to get my keybinding working by tipping it directly to vim commandline. I find out that the keybinding was working quite nice. I think problem is that I create a session some times ago (with mksession) and if you load a session I think vim ignores the vimrc-file. Is this assumption right?
Solution:
In these thread I find a soultion to make mksession save less options.
Another lightweight approach: set the ` mark, format the buffer and jump back to the mark afterwards.
:nnoremap <key> m`gg=G``
I would recommend the use of CTRLo and CTRLi which allow to go respectively backward and forward in the jump list. See :help jumps.
The following mapping
map <F4> gg=G2<C-o>
works. (It jumps back two times in the jump list)
But generally, the jump list is a great way to navigate in a file, this is likely the shortcuts that use the most in my daily use. It is also works if you jump to a tag to go back to your original location.
You might also want to use nnoremap rather than map, this way it will only work in normal mode, and you could potentially reuse F4 in combination in another key binding without having recursive mappings.
so
nnoremap <F4> gg=G2<C-o>

VIM - FuzzyFinder closes on Backspace, why?

I use FuzzyFinder in VIM (cannot switch to Command-T, no Ruby support on my server). It works well, except for one issue: Whenever I hit backspace (for example, after making a typo), the entire FuzzyFinder buffer just closes.
This doesn't happen every time, only right after entering a directory. For example:
FILE>filename -- I can hit backspace just fine, and get FILE>filenam
FILE>folder/ -- if I hit backspace now, the buffer just closes. It's as if I can't navigate backwards in the hierarchy after entering a directory.
I have no idea why this happens, and it's driving me crazy. Any advice would be appreciated.
This also happens when I press Ctrl+w as it says in the fuf documentation.
I've been using FuzzyFinder for a while and never faced this problem.
Possible you have some mapping that may be interfering with FuzzyFinder. You could try :map <bs> to find out if there is any mapping on backspace key, and :10verbose map <bs> to find out where such mapping was set.
You also could try :unmap <bs> and :unmap! <bs> to remove any mappings from backspace and check if the issue still exists.
If the above doesn't solve the problem you might consider contacting the plugin author, as the issue could also be related to some other mapping, as stated on FuzzyFinder changelog, :h fuf-changelog:
- Fixed the bug that it did not work correctly when a user have mapped <C-p>
or <Down>.

Delete Key is changing letter case in 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.

Resources