the weirdest VI problem EVER - vim

Ok, so I am trying to type the following in .cshrc file: alias ls 'ls --color=auto'. I type one character at a tiem.
However, when I reach --color= i type a and cursor goes to the next line.
I checked the .vimrc file and didn't fine anything out of whack. I am using vim7.2
EDIT
I noticed it is only happens in the .cshrc file, and cursor starts blinking with ' character.
I had "set mouse=a" set in .vimrc file
What is the problem?

Do you have textwidth set? If so it'll break your lines once they reach a certain length. Inspect the value via
:set textwidth?
Set it to 0 to turn off hard line-wrapping. Otherwise, do you have a mapped to something weird in insert mode? Check
:imap a
to see if you do.

I cannot test it now, but probably something wrong with the appropriate indent file for that filetype. Does it happen if you edit some other configuration file ?

Related

Vim weird behaviour with backspace with empty .vimrc

I'm having a weird issue with vim on Ubuntu. I've been using it for the last few weeks, trying to learn, on Windows and it behaves differently now that I'm using it on Linux.
I noticed that while in insert mode pressing backspace will delete text just like any other editor on Windows, but on Linux the text is "deleted" yet it stays there until I press ESC or write over it.
I was trying to fix this but I'm confused as to whether this is intended behaviour or not. It happens in gvim too.
The reason of this question is this, however:
I deleted my .vimrc file to see if any of my config was at fault and it fixed it. Backspace was now back to its regular self.
But then I tried creating an empty .vimrc file and that made it go back to the delayed delete. It's empty. Why the hell?
So I have no idea what's causing this. Hope my question makes sense my English ain't the best. Thanks.
Alright so looking at :h compatible I found this:
"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. (Note: This doesn't
happen for the system-wide vimrc or gvimrc file, nor for a file given
with the |-u| argument). Also see |compatible-default| and
|posix-compliance|."
So if I'm getting this right, running Vim with a .vimrc file should automatically set nocompatible and running it without one should set compatible... ? Whatever the case, I tried checking with :verbose set compatible? and it always says nocompatible is on so the -N flag shouldn't do anything... Yet it fixes the issue.
Without a vimrc Vim will load /usr/share/vim/vim80/defaults.vim (depending on your vim version). In this file the bs/backspace parameter is set to 2, or actually it is indent,eol,start which is the same as 2 (see :h bs)
Now if you create an empty .vimrc, defaults.vim will not be loaded, so your bs will possibly be 0.
This behaviour is described in :h defaults.vim
So to solve your problem, just put set bs=2 in your .vimrc
Alright I fixed it.
Running vim with the -N command makes it work properly. I'm not sure why but that's what's happening.

Different cscopequickfix behavior for vimrc and command line

If I do set cscopequickfix=g- in my vimrc file, it does not work: search results do not get listed in quick fix window.
But if I do :set cscopequickfix=g- from vim command line, it starts working as expected.
What's even more puzzling to me, is that g search is the only one that this happens to. The rest of them e-, s-, etc... if I put set cscopequickfix=e-,s-, in my vimrc file, search results for them get directed to quick fix window correctly.
Ideas? Thanks!

How to exit automatically at end of file on vim?

I tried vim/less.sh as pager with syntax highlighting, but there is a little issue:
when displaying small file, vim uses 'full screen' and waits for a command from user.
Can I let vim to act like a less --quit-at-eof?
In other words, is there a way to automatically quit vim if displayed file is several lines length?
I found one solution with a shell script: count file lines by wc -l, then get terminal height, if size is small - use custom vim config file, where custom config file ending with :quit string.
However, this solution looks terrible and leave extra lines with ~ after end of small file, so I'm looking for better way to do this.
Vim switches to the alternate terminal page, so when you exit it, its contents are gone. Even if you turn that off:
$ vim --cmd 'set t_ti= t_te='
UI stuff like the ~, ruler and statusline would remain, too. Therefore, the solution you've found looks like a reasonable workaround. Either use that or (better) get used to quitting the Vim pager.

Vim --remote-silent always opens [No Name] buffer for first file

I want to be able to open files using the same instance so I added --remote-silent when opening files. But the first time it loads, Vim will open an empty buffer, then my file. So now I have 2 buffers.
Upon further investigation, I noticed that setting nohidden will solve this problem. BUT, not only is it against my liking, it will cause the first buffer to have no syntax highlighting.
This doesn't happen without the --remote-silent option.
Any help appreciated. Thanks!
Doing $ vim --servername FOO --remote[-silent] filename without an instance already running launches a new instance first then opens the file: it is not like $vim filename. You have to find a way to completely remove the first empty buffer.
From my limited testing, adding set bufhidden=wipe to your ~/.vimrc may solve the problem.
set bufhidden=wipe, being local to a buffer, is applied only to the first empty buffer and reset afterwards.
See :h bufhidden.
This will certainly cause some problems when you run Vim normally, though.
edit
Yes, set bufhidden=wipe causes obvious problems. When launched "normally" (with $vim file1) the first buffer is wiped when you edit a second file which is not what you want.
A simple check on the name of the buffer resolves that problem:
if bufname('%') == ''
set bufhidden=wipe
endif
Syntax highlighting works in every situation, here. Could you post the content of your ~/.vim/ and ~/.vimrc somewhere?
The --remote family of options allows for an additional Ex command to be performed after opening the file.
What you can do here is add :bd1 which deletes buffer #1 which is the [No Name] buffer.
example: --remote-silent +:bd1 {file}

After running :make in Vim, vim will jump to nonsenical files

Sometimes I'll have an error in a file and the output from :make is something like this:
In file included from /path/to/some/src/file.cpp|22| 0:
And so when it jumps to that file, it doesn't jump to file.cpp, it jumps to the file named In file included from /path/to/some/src/file.cpp, which is clearly nonsensical. In general I like the jumping, just not when the error is of that form causing me to have useless files open instead of the real error I care about
Is there a way to make it smarter so that it jumps to the real error, which is on the next line, or at very least, only jump if the thing it finds is a real file?
You might want to modify the errorformat setting. See :help 'errorformat' and :help errorformat. To know the current value you can run :set errorformat?.

Resources