Horizontal line in vim - linux

What does a horizontal line in vim mean? While editing a remote file I see a horizontal line in the current line.
I don't see it while editing local files
Edit:
cursorline is not shown until I save the file(:w). When I type :w and enter password, cursorline appears. Why does it have such a behavior? When I edit file in remote machine cursorline is turned off and is not shown.

As others have answered, the effect is probably being caused by the cursorline option.
You can track down what is script made the most recent change to an option by running the command set optname? under the verbose command:
:verbose set cursorline?
You will probably just find that the Netrw plugin set it; Netrw handles local directory browsing and remote directory/file access like your scp:// example. Netrw adjusts cursorline (and cursorcolumn) for its own purposes (e.g. directory listings), but it tries to restore the value to the “user value”. Unfortunately, its idea of the “user value” is captured when part of the Netrw code loads and is not updated afterwards.
My guess is that, somehow (via some other plugin, or bit of configuration), cursorline is set when Netrw loads (and captures its value), but it is later reset by the time you start editing the first file. Then, when you later save the file (:w), Netrw restores the “captured” value. Unfortunately, there does not appear to be any good way to update this “captured” value of the cursorline option (there is no “external” access to the script variable it uses, and it does not “recapture” if you manually reload the file).
What you can do, however, is explicitly load the bit of Netrw that “captures” cursorline when your desired value is active. You could do that with the following two commands early in your ~/.vimrc (possibly at the very top, if necessary—it needs to be before the first time autoload/netrw.vim would ever be used):
set nocursorline
runtime autoload/netrw.vim " will 'capture' cursorline and cursorcolumn values
Netrw will still set/reset cursorline (and cursorcolumn), but as long as the value you normally want matches the value that is active right before Netrw is loaded, then you will not notice it.

I don't quite know the simplest solution to get get netrw to really capture the right value, but at very least (since for me, nocul is right,) adding:
let g:netrw_cursorline=0
To the end of my ~/.vimrc seems to have fixed the problem for me. Hope this helps someone!

It's the cursorLine. Its appearance is defined in your colorscheme. The one on the remote machine is probably different than yours or there's a mismatch between your client/server's $TERM.

Yup, ":set cursorline" or ":set nocursorline" to turn the line on or off.
The command "vim scp://...." copies the remote file onto your local machine (i.e. machine where the "vim" process runs), then opens the file in "vim" for you to edit, then, if you have modified the file, copies the file back onto the remote system. As such, syntax highlighting etc. is determined only by "vim" on your local machine.
Files with the same syntax type (":se syn" to show current syntax highlighting scheme) are highlighted the same way. Do the files, in which you see the difference, have the same syntax type?

Version 142 of netrw.vim has fixed this bug, at least for me (vim 7.3, old netrw.vim version was 140, running under cygwin).
You can get the latest version here: http://www.vim.org/scripts/script.php?script_id=1075

Related

Can not switch to previous page in gvim

I have a very weird problem which did not exist in my environment before but now happened. When editing files, I'm used to doing this way:
gvim . #open current directory browsing
scroll up/down to select file, enter then edit.
ctrl-6 #back to previous directory
However one day I found the step3 was failed, it said "No alternate file".
My .vimrc file only contains:
colorscheme darkblue
set number
set autoindent
set nowrap
set ignorecase
set cursorline
I tried to clean all content in .cshrc but the same.
Can anyone tell me what's wrong with my gvim ?
Thanks in advance.
This looks to be a change in behavior introduced in Vim 7.4. The netrw view is no longer stored as an alternate file. See this discussion.
The Vim maintainers seemed split on what the correct behavior should be, but Bram himself offered up this advice with a mapping:
I do realize that editing the directory of the current file is
something I often do, but I never bothered to set up a mapping for
it. Typing ":e %:h" is not too difficult, but CTRL-O to jump back to
the netrw %directory view was easier.
I now added a mapping:
map ,d :e %:h<CR>
Let's see if I can get used to that.
Another related discussion can be found here.
You are likely using netrw to edit a directory. This is the equivalent of :Explore. Sadly netrw has a bad habit of not maintaining the alternative buffer, #. You maybe able to upgrade netrw or use :Rexplore (:Rex for short) to resume exploring.
Another option is to just use :e with wildcards and tab completion to explore files. Use <c-d> to list out completions as well.

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.

Changing NERDTree ~/.vimrc options on the fly without restarting VIM

I would like to change my sort order dynamically. At times, I want my sources to be listed alphabetical, at times I want only one extension to be shown.
I can currently get it to work by editing NERDTreeSortOrder in my ~/.vimrc.
But how do I do this without re-launching VIM?
I tried just executing ":let NERDTreeSortOrder = ['new sort order']" but that doesn't really change anything. i add it to my vimrc, quit VIM and restart and it works.
By the way, if someone can tell me how to make NerdTree show only a specific extension, that would work for me too. I know I can make NERDTree not show a particular file type by adding it to ignore, but I want the other way around.
Any ideas?
You'll need to refresh the directory (after entering let NERDTreeSortOrder=[...]).
While in the NERDTree buffer, either :
r to limit the refresh to the selected directory
R to refresh from the start of the root node.
As for whitelisting specific file extensions, have at look at this question.
Have your tried source-ing your .vimrc from within vim?
:source $MYVIMRC or :source ~/.vimrc
:source can be shortened to :so, e.g. :so ~/.vimrc

set tags=tags in gvimrc not working, unless set it explicitly

I have a problem to set my tags file correctly. It use to work without problem after I reinstalled the system. error message like
E433: No tags file
E426: tag not found: Pids
accurs when I press ctrl+].
I have this line in my .gvimrc file
set tags=~/projectdirectory/tags
and tags-exuberant installed properly.
It works fine when I type :set tags=~/projectdirectory/tags in gvim
I also tried use set tags=~/projectdirectory/tags;/
All other .gvimrc settings function well. How this could be possible?
UPDATE:
I have solved the problem, it is because I have multiple tags setting in ~/.gvimrc, vim take the last one in current session.
You can check the actual effective value (after starting GVIM) via
:verbose set tags?
The option might have been overwritten by a later :set command, or a plugin.
Even if you only use GVIM, it's recommended to put the general settings into ~/.vimrc (which is also sourced in GVIM), and keep ~/.gvimrc reserved for GUI-specific settings. An important difference between the two is that the latter is only sourced at the very end, so it's unsuitable for configuring plugins.

vim undo limited to one step on some hosts

On one of my dev machines I have unlimited undos, I can hold u and go all the way back to when I opened the file.
On another, pressing u toggles between the last two changes I made, no more.
The first dev machine I have Administrator access to and the vim installer had free reign. The second I do not and vim had to be installed off the normal OS paths and have to launch vim with a 'Sendto'. Perhaps this is related and I'm missing some rc commands.
Also noticed I have to run 'syn on' to get highlighting on that box. vimrc was also blank so now I'm sure it has something to do with it.
From other threads I don't believe this is related to the persistent undo feature, but simply a .swp or ~ issue (whatever those files are used for..)
Deadlines have prompted punting what is probably a simple issue.. How do I fix this?
vimrc was blank on the affected box.
I added these lines from my other dev box and everything was hapy again.
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin
Looks like you need a vimrc file on the second box: see :he compatible-default.
If there is no vimrc file, vim runs in vi compatible mode, and there is no syntax highlighting etc...
Create one. Output of :version will show you more where the files are expected.
If undo still does not work have a look at :he undo-two-ways.

Resources