How to make vim search wrap more obvious? - vim

I mostly use vim (console and gvim) full screen on a large monitor. My peripheral vision tends to miss details at the bottom of the screen.
Any suggestions on how to make the "search hit BOTTOM, continuing at TOP" message that appears when the current search wraps more obvious?
I do set
set noerrorbells
set novisualbell
in my vimrc to avoid the bell/screen flash every time I type Esc. However, re-enabling those options has no effect on search wrap (still no beep or flash on wrap).
Using visual bell to indicate search wrap would work well, I think. Any idea how to implement that?

It's hard to change that behavior, you'd have to override all built-in search commands (/, n / N, *, #, etc.) and any custom (plugin) mappings. If this is bothering you, maybe
:set nowrapscan
is worth a try. You can then still "manually" wrap via gg / G, which will soon go into your muscle memory, yet keep you alert.

My solution for now is to adjust my color scheme to make the WarningMsg color more obnoxious (in this case, bright red background). Here's the adjusted line from my color scheme file:
hi WarningMsg ctermfg=white ctermbg=red guifg=White guibg=Red gui=None
I find this makes the search wrap message much more noticeable.

Related

How to get matching brace highlighting without cursor jump in vim

I am running vim 7.3 on several machines. By default MatchParen is enabled on all of my instances. Using gvim on my windows machine, it is doing exactly what I want - when my cursor is on a bracket, paren, etc. it visually highlights the match. It does not affect cursor navigation. However, on my Ubuntu boxes, when I move the cursor onto the character, it actually jumps to the match.
I'm sure that the behavior is caused by MatchParens because if I do a :NoMatchParen, it stops. Unfortunately, I also don't get the highlighting at that point. I can't figure out where my settings differ, though.
I'll like you even more if you can point me towards a plugin that will always highlight the closest enclosing pair of characters around my current position (like a code oriented version of MatchTagsAlways)
When showmatch is set, the cursor is actually jumping, and the following line fixes the problem:
set matchtime=0
More details:
http://vimdoc.sourceforge.net/htmldoc/options.html#'matchtime'
Just like FDinoff said in the accepted answer, this is probably only a problem of colors.
So if the color of the matching "paren" disorients you, tweaking colors of background and foreground is likely the solution.
But HOW do you do this?? ^^
I've had quite a journey through the vimdoc (it was not easy).
I've tested a whole bunch of variables and found that the relevant tweak is the [hi]ghlight command and specifically the MatchParen group.
The solution
Adding this in my .vimrc did the trick:
hi MatchParen ctermfg=208 ctermbg=bg
Note that vim config files are read from top to bottom, and some types of "words" are matched by several options. For example, a boolean could also be a keyword. Thus you have to pay attention to the order of these options.
How does this work?
My problem was that the background had the flashy color while the foreground had the color of the background of my terminal, which made it really confusing. Thus switching colors was the solution for me. But maybe you will have to tweak it differently.
First, you can check the current value for highlight MatchParen by entering the following command (while inside vim, in normal mode):
:hi MatchParen
You'll see hi MatchParen followed by XXX in the current style, followed by a list of argument=value separated by spaces.
The important arguments are ctermfg and ctermbg for the "terminal" vim, guifg and guibg for the "gui" vim. (Where fg means foreground and bg means background)
You can change a value and see the result in real time. Just put your cursor over a match character and enter the following command:
:hi MatchParen SomeArgument=SomeValue
This will not be saved, so don't worry. When you find a proper combination of values, you can add them in your .vimrc as shown above.
Personally, I set ctermfg to 208 (orange color) and ctermbg to bg (a keyword for the current background color, if known by vim).
If you use vim in a gui, take a look here for the available choice of colors.
The cursor isn't jumping. The color scheme probably has defined bad colors for the MatchParen highlight group which makes it look like the cursor is jumping.
Running default gVim (v7.4.461) without any configuration (i.e. no .vim files) in openSUSE 13.2 Legacy 32 Bit, :set showmatch? reveals that showmatch is on at start, which is not Vim's stated default behaviour. We can account for this by adding :set noshowmatch in our .vimrc.

Can't override background color

I have this in my .vimrc:
highlight ColorColumn ctermbg=234 guibg=#2c2d27
let &colorcolumn=join(range(81,999),",")
When I search for words that fall into this range, the background color for the word does not show up. How do I fix this?
Unfortunately, you can't. The priorities of search highlighting and hlsearch are fixed, you can only specify the priority when using matchadd(), but even with a high number there, I wasn't able to override the 'colorcolumn'. It appears that this is completely separate (like syntax highlighting), and cannot be overruled.
Anyway, the colorcolumn is meant to be a single (or multiple few) columns, not the broad area you've created with your range() trick. So in a way, you're suffering under your own cleverness: You've misused a built-in feature, and now complain about the side effects.
So, move back to a single colorcolumn, or use the emulation used in older Vim versions, matchadd() with a low priority:
:call matchadd('ColorColumn', '\%>80v', -10)

How to make vim's replacement selection blinking

In latex files I have the on-fly spelling switched so you can imagine that together with the syntax highlighting there is already a lot of colors in the terminal screen. When in such environment I am running a string replacement, say with :%s/x/y/gc I need a lot of time to identify where the string-to-be-replaced is located in all this color mess. Is it possible to make vim's current selection blink?
You change the highlighting of the to-be-replaced text with highlight IncSearch.
For example,
:highlight IncSearch ctermfg=Red guifg=Red
highlights the text with a red background (despite it being fg not bg).
However, I don't think there's any way to make it blink (and are you sure you really want that?). You might be able to use italics or underlines instead. See :h highlight for the options that are available.

Spelling errors hidden while highlighting line in vim

When there's a misspelling (with set spell), it highlights it red (good!), but when the line is highlighted as my current line the red goes away (bad). Removing set cul fixes the problem, but how do I keep the word marked red while being highlighted? I may have multiple words misspelled on a line and also while typing the misspellings are hidden until I go to the next which kinda sucks.
vimrc: https://gist.github.com/OscarGodson/d1b05d52df4ff160b891
colorscheme: https://github.com/tomasr/molokai
1) one could change the vim color scheme, or the SpellBad highlight scheme; one example of the second case is to add in vimrc the following,
hi clear SpellBad
hi SpellBad cterm=bold
2) (not a solution) someone might find 'spell checking while composing' is a bit annoying / distracting and prefer switching the spell checking off until they finish writing the article.
The problem is that the cursorline highlighting has priority over the syntax highlighting (spell errors belong to that), and that cannot be changed. (You can only specify the priority with the newer matchadd() functions.)
I've once raised this issue for error highlighting, but nothing came out of it. (I'd still like to implement a patch for that one day.)
The problem is only about overlap of background highlighting; in GVIM, most color schemes use the undercurl attribute to avoid that issue. In the console, you can only change the highlighting to foreground color, italic or bold attributes to work around it.
workaround
One clever workaround involves swapping the foreground and background colors while adding the reverse attribute: Turn
hi SpellBad cterm=NONE ctermbg=red ctermfg=white
to
hi SpellBad cterm=reverse ctermbg=white ctermfg=red
These two changes cancel each other out normally, but on a CursorLine, the foreground color now contributes to the coloring, turning hard-to-read white-on-cursorline to red-on-cursorline.
Curiously, and jumping off of both answers from the other posters, adding the following in my vimrc made my red background persist accidentally due to my terminal not being able to fulfill the "italic" switch because it can't mix font types like that (I think). I stuck it in the section of my vimrc that is tested for gvim because gvim underlines my spelling mistakes without issue. Give it a try!
if has("gui_running")
#all my gvim settings
else #we're in terminal
hi clear SpellBad
hi SpellBad cterm=bold,italic ctermfg=red
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