gVim - show position marker of matched search terms - search

Is there functionality, plugin or ways in gVim to show markers of matched search terms, which point out their rough positions in the buffer? For example, when search "foo" in the buffer, the feature put markers along with the vertical scrollbar. Each marker indicates an matched "foo". When you scroll to that position, you see a "foo" in the buffer. With this feature I can easily tell the distribution pattern of the term visually, where the current term is relatively in the document and approximately how many occurrences.
If no such feature, is there way to manipulate scrollbar and other GUI components of gVim in plugin?
In Firefox the similar feature is done by Search Marker (outdated), XUL/Migemo (outdated) or FindBar Tweak (up-to-date) extensions.
UPDATE:
(source: mozilla.net)
(source: mozilla.net)

If you want to see the distribution, you could try:
:g//#
this will show the lines where the search pattern is found.

Try :set hlsearch to get highlighted search terms.
Also try pressing ^G to see the line and column of the cursor.

Related

How do I enable highlight on the scroll bar displayihng the occurences of a search result in VIM?

When searching for a pattern within file/files in vim, I will like to show the match on the right hand scroll bar, so that I know the locations of the matches within the file and I could simply scroll with my mouse to the match location (similar to visual studio). Any advice on how to do this will be much appreciated.
I tried to google search on this, but answers are normally related to showing the search results at the bottom panel, but this is not what I am looking for.
The expected result should show highlights on the scroll bar on the right.
In the terminal, Vim does not provide a scrollbar (there is :set ruler and the statusline to provide orientation). In graphical GVIM, the default scrollbars provided by the operating system / window manager are used.
To give you orientation for searches, recent Vim 8.1 versions can give search statistics (e.g. [1/5]), enabled via :set shortmess-=S. Plugins like my SearchPosition plugin can give you much more detailed information:
1 match after cursor in this line, 8 following, 2 in previous lines; ~
total 10 within 11,42 for /\<SearchPosition\>/ ~

Show the autocomplete match as preview text in vim

Is it possible with Vim itself or a plugin to display the autocomplete option inline?
If not is there a way to display text in vim without inserting it into the buffer?
You can disable the popup menu (:help popupmenu-completion; it usually displays [a subset of] the available choices) by removing menu[one] from the 'completeopt' option. Then, the first candidate (or longest common part) is directly inserted into the buffer, and <C-n> cycles through candidates at that location. To remove the current suggested completion and return to the original state before the completion, press <C-e>.
That technically still (if only temporarily) inserts the candidate into the buffer, but I think it closely fits what you're asking for, and is built-in. To display text without inserting, there's currently only a (rather crude) workaround of using the :help conceal feature to change the appearance of individual characters (for a static text, matching the exact location in the buffer via \%l and \%c) into something else via matchadd(). However, this only works if there's existing text; it wouldn't work at the end of a line. Currently, a generic overlay feature is being discussed on the the vim_dev mailing list, but it is in very early stages.

Vim spell check automatically splits the screen

I typed z= underneath a misspelled word, and vim split the screen horizontally, thereby keeping the misspelled word in context, but also providing a list words to change the misspelled word from. Usually, this latter screen replaces the former screen when I hit z=.
I like this behavior, but can not replicate it. I must have hit something before z= but I do not know what.
The behavior you saw accidentally happens when there are only a few suggestions and they don't fill the entire window.
You can force a maximum size for the suggestion list (example: 20 suggestions) with
set spellsuggest=best,20
Now, as long as your window exceeds 20 lines, you will see the misspelled word in context, and the bottom 20 lines of your window filled with the suggestion list
I can't say what caused the behavior you saw, maybe it is some plugin.
But here are two options to stay in the context with spellchecker:
1) Use CTRL-X s in insert mode:
In Insert mode, when the cursor is after a badly spelled word, you can use
CTRL-X s to find suggestions. This works like Insert mode completion. Use
CTRL-N to use the next suggestion, CTRL-P to go back. |i_CTRL-X_s|
2) Use vimple plugin which turns few full-screen windows (including spell suggestions) into "overlays" (actually split windows where you can select the word you need).

Vim: Only scroll the current line

I would like vim to scroll horizontally like nano does, by scrolling only the current line, not the whole screen.
I tried playing with nowrap and scrolloff settings, without success.
Here are some screenshots (with the cursor at the end of a long line) to explain myself.
Nano:
Vim (wrap):
Vim (nowrap):
Thanks!
No, Vim cannot do this, and I think it would be hard to implement this in a way that isn't inconsistent or confusing to the user. There would need to be an indicator (like with side scrolling) that only the current line is scrolled. Also in Vim, there are several commands (like j / k and i_CTRL-Y / i_CTRL-E) that refer to the same column in above / below lines. A partially scrolled view state would make it difficult to use those.
That said, you can sort-of achieve this with a hack: The foldtext of folded lines does not scroll horizontally. So if you fold each individual line (other than the current one) via a custom 'foldexpr', set the fold text to be the line's text, and automatically close all surrounding folds, you'll get this. However, as you'll lose syntax highlighting and "normal" folding, this is more for demonstration than an actual solution.

VIM: Stay away from the edges on searches

I recently saw some VIM configuration where search matches would scroll to N lines past the match, so that there would be N lines below the search match instead of it being on the last line (to give context). I cannot find the page where this was mentioned, and apparently I do not know the right keywords to google for!
What is this feature called, and how could I have used the VIM manual to find it assuming that I don't know what it is called?
Thanks.
As far as I tell this can't be set just for search, but is a setting that will be used in all situations.
You are looking for scrolloff: Minimal number of screen lines to keep above and below the cursor. This will make some context visible around where you are working. sidescrolloff does the same thing but horizontally.
This is what I have in my .vimrc:
" When the page starts to scroll, keep the cursor 8 lines from the top and 8
" lines from the bottom and 15 lines on the left
set scrolloff=8
set sidescrolloff=15
set sidescroll=1

Resources