vim: cannot click past col 90 - vim

Since I'm pretty new with vim, I (still) find the mouse very useful to click somewhere (to move quickly) and select blocks of text.
in my vimrc:
set mouse=a
and also
set textwidth=80
set colorcolumn=80
I can click to move the cursor, but not after the column 91. I really don't understand why this behaviour and why this arbitrary limit.

You are limiting the effective width of your document to 80 columns. No wonder clicking outside of this arbitrary limit - that you choose - does nothing.
To be able to click anywhere, you must
:set virtualedit=all
but it doesn't make much sense if you set hard physical limits to your content.

you can try to set fileencoding and encoding of vim be the same value,
set fileencoding=utf-8
set encoding=utf-8
and make sure your locale is the same value, too.
you can use 'locale' command to get your own locale in a terminal.

Related

Which configuration does Vim finally apply after setting values in .vimrc, ftplugin, after/ftplugin etc.?

I am editing a python file. My current settings for tabstop are as follows(just experimenting things):
~/.vimrc: set tabstop=4
~/.vim/ftplugin/python.vim: set tabstop=2
There is no ~/.vim/after/plugin/python.vim file
set tabstop? shows tabstop=8
verbose set tabstop? shows tabstop=8. Last set from /usr/share/vim/vim80/ftplugin/python.vim
My questions:
Why is tabstop settings at 8 even though i have explicitly set it to 4 in .vimrc file or 2 in ~/.vim/ftplugin/python.vim file
When is each of the files i.e. ~/.vimrc, ~/.vim/ftplugin/python.vim, ~/.vim/after/plugin/python.vim, /usr/share/vim/vim80/ftplugin/python.vim loaded?
Which file takes priority and where should I define my settings to override the others?
How is set different from set local?
It would be great if someone answers all these questions. It will surely benefit people especially Vim beginner and intermediate users as all of these concepts are inter-related
tabstop is the width of space represented by a tab character in the file, but the width of space inserted when you press Tab on your keyboard is controlled by softtabstop (if it's set to a non-zero value). Nothing weird is going on with order of evaluation, or setlocal, or any of the other things you're asking about.
See also What is softtabstop used for? on the Vim StackExchange.
tabstop is a buffer-local setting. That means that every buffer has its own value. So by setting it from your vimrc you only set the global default which will probably be overwritten by ftplugin and such.
The plugin's code resides in $VIMRUNTIME/ftplugin.vim. Roughly speaking, what it does is runtime! ftplugin/python.vim. runtime! differs from source in two aspects: (a) it searches along :h 'runtimepath', and not in the current directory; (b) it sources all files found (that's what the "bang" stands for), not only the first one.
So, because of (b), ftplugin first sources your ~/.vim/ftplugin/python.vim, and then $VIMRUNTIME/ftplugin/python.vim. For this reason your setting gets finally overwritten.
This is why usually we want ~/.vim/after/ftplugin/python.vim instead. Also note that standard "ftplugin"-scripts have the guard against multiple sourcing:
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
....
So if you really want it, you can put this on top of your ~/.vim/ftplugin/python.vim and exclude all the stuff from $VIMRUNTIME/ftplugin/python.vim. Rarely wanted though.
The difference between set, setglobal and setlocal is actually the difference between option types: global, local-to-buffer, local-to-window, global-local. To keep the things simple, setglobal sets a global value for an option, setlocal sets a local one, and set does something "reasonable" (tm). In particular, set tabstop=x sets both global and local (current buffer's one) values.

Why doesn't Vim execute my column setting in this command?

I have a Vim command to enter a "Distraction Free" mode:
command! DistractionFreeMode set guioptions-=r gfn=Cousine:h12 showtabline=0 fullscreen laststatus=0 noruler wrap linebreak nolist linespace=5 foldcolumn=3 nonumber columns=80
Note also that I am using MacVim. The command sort of works, but some of the settings don't seem to be triggered. These include columns=80 and nolist. I always have to set these separately after executing this command in order to get them right. I have also tried putting these settings in a function that I called with the command and had the same issue. What is the source of this problem?
EDIT: Here is a screenshot of the look I'm aiming at. Using fullscreen and columns together is necessary to achieve this, as far as I know:
According for the help for fullscreen (:h fullscreen) There are option to tailor the behavior of what happens when you enter fullscreen mode which are set with fuoptions
On my MacVim fuoptions is set to
fuoptions=maxvert,maxhotz
When we look at :h fuoptions
maxvert When entering fullscreen, 'lines' is set to the maximum number
of lines fitting on the screen in fullscreen mode. When
leaving fullscreen, if 'lines' is still equal to the maximized
number of lines, it is restored to the value it had before
entering fullscreen.
maxhorz When entering fullscreen, 'columns' is set to the maximum number
of columns fitting on the screen in fullscreen mode. When
leaving fullscreen, if 'columns' is still equal to the maximized
number of columns, it is restored to the value it had before
entering fullscreen.
This mean that when you enter fullscreen mode MacVim resizes to to the maximum number of lines and columns it can. (ignoring the values you set)
To fix this you can either add set fuoption-=maxhorz to remove the offending option or add set=maxvert to force it to only use maxvert regardless if other options are set. This stops MacVim from overriding your settings in the horizontal direction.
So your fixed command would look something like
command! DistractionFreeMode set guioptions-=r gfn=Cousine:h12 showtabline=0 fuoptions-=maxhorz fullscreen laststatus=0 noruler wrap linebreak nolist linespace=5 foldcolumn=3 nonumber columns=80

gvim taking so long to display 'all tags' using g ctrl-]

I am navigating c++ code using gvim and ctags. Size of the ctags file is 3.5 GB.
ctrl-] is working pretty quick, but g+ctrl-] is taking nearly 5 seconds, which I think is too much (that is too much time for searching a sorted ctgas file!). Any suggestions to improve speed?
My .gvimrc:
set gcr=n-c-v:blinkoff0 " it switches off cursor blinks
set lines=52 columns=120 " Sets the geometry of gui window.
colorscheme default " desert load the color scheme of choice
set nocompatible " This must be first, because it changes other options as a side effect.
set ic
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set history=10000 " keep 100 lines of command line history
set showcmd " display incomplete commands
set incsearch " do incremental searching
set et
set paste
set ruler
When you have 'ignorecase' on, Vim mostly needs to perform a linear search of the tags database, instead of a much faster binary search. You may be able to avoid that penalty with a proper tags database that indicates case-folded sorting by this line:
!_TAG_FILE_SORTED 2
See :help 'tagbsearch' for all the details.
Problem is due to ic! When I removed ic(i.e. set noic), then the speed was drastically improved. g+ctrl-] is as fast as ctrl-] now.

How do I make Vim get the number of rows of the terminal from which it starts?

My work setup has several terminals open, at different heights (e.g. number of lines). How do I make Vim obtain that number of lines so that it can set itself accordingly with set lines?
I'm on bash with iTerm2.
Update: If my .vimrc doesn't have a set lines statement, Vim should adjust itself by default.
Vim's default behaviour is to take up all of the available height. Or 24 lines if it can't get the information from the Terminal emulator according to :h lines.
set lines=52 works in MacVim/GVim but it's not really supposed to do anything useful in CLI Vim besides, eventually, changing the terminal's window height.
From my limited use of iTerm2 Vim behaves as it should. So do you want Vim to take less vertical space than what is available? Or more?
Though the reason didn't require it, in case someone comes across this while trying to figure out how to get the number of rows in a terminal at startup... the answer is to use "&lines".
Eg. to enforce laststatus to display unless you are working in a small window.
if &lines > 10 | set laststatus=2 | endif

Is it possible to not display a ~ for blank lines in Vim/Neovim?

Is it possible to not display a ~ for blank lines in Vim?
This confuses Mac Vim's scrollbar, and I quite don't like these tildes.
:hi NonText guifg=bg
That command should set the color of non text characters to be the same as the background color.
Vim 8.x:
You can now change the color just for the end of the buffer ~:
highlight EndOfBuffer ctermfg=black ctermbg=black
See changelog for Vim 8.x.
As jamessan said, you can’t disable them. The scrolling behavior isn’t specific to MacVim, either — it works the same way in the terminal and in gvim:
Instead of seeing this as a problem, what you should do is learn to see this as part of Vim’s flexibility. For example, you can use the zt command to scroll the current line to the top of the screen, regardless of where in the file it is. This can make it easier to write macros that do some work and then scroll back to where you were. The commands <C-E> and <C-Y> are made simpler because of this, as is the 'scrolloffset' option.
If you must, retrain your brain to think of Vim’s scrollbar as mapping to which line is on top, instead of which screenful is visible.
For NeoVim, you can set the fillchars value for eob to a space character and that will effectively hide it. (This might not work for plain Vim).
In Lua (Nvim 0.5+):
vim.wo.fillchars='eob: '
In VimScript:
set fillchars=eob:\
Note: Calling the above will override your fillchars value for other items as well (if set), so use this as a reference to set multiple values together:
set fillchars=eob:\ ,fold:\ ,vert:\│
Or use set fillchars+=... to append it your existing values.
You can't disable them, but you can change your colorscheme such that the NonText highlight group is colored the same as the Normal highlight group. However, this affects more than just the end of document tildes.
I doubt that it's actually "confusing" MacVim's scrollbar and if it is, then that's a bug in the patching that MacVim does.
The tilde ~ characters are meant to remind the user that those lines are not part of buffer content.
The above highlight trick will hide the ~ character, but it is still there. For some terminals, this may not even work. If you happen to be a Neovim user, you can use fillchars option to change the end of buffer symbol like this:
set fillchars=fold:\ ,vert:\│,eob:\ ,msgsep:‾
This will use space instead of ~ for end of buffer, effectively hiding the annoying ~.
You may also be interested in discussions here.

Resources