Mouse input in gvim - vim

Can standard mouse input be customized in vim (in my case gvim)? Plugins are acceptable options too.
I'm specifically interested in "overriding" a double-click on a word, so that instead of just highlighting the word, gvim does a search and thus highlights all instances of this word in the file. I've seen this functionality in other editors and found it very useful.

See :help double-click. It should have everything you need. For example from the help page:
An example, for using a double click to jump to the tag under the cursor:
:map <2-LeftMouse> :exe "tag ". expand("<cword>")<CR>

I don't regarding mouse, but you can press */# to search word under cursor forward/backward.

Related

How Do You Split the Neovim Spell Suggestion Window Horizontally?

In Neovim, with the spell checker enabled by set spell, if you hover over a word which is underlined to indicate improper spelling and type z= a window will open which obscures the entirety of your work to list all of the suggested words. I would like for this window to be split horizontally, above, or below the the current buffer so that I can select the properly spelled word while still being able to see my work.
I'm not sure if this is possible. I can't find a setting that would change this functionality.
While not an exact answer to your question, you can just make a remap to display a drop-down list of suggestions like so (see image below - just Tab to traverse the list and press <Esc> to choose and be returned to normal mode):
" move to insert mode with drop-down menu of spelling suggestions for word under the cursor
nnoremap <Leader>sp a<C-X>s
I found that 99% of the time I chose the first spelling suggestion, so I made the mapping to do that and return to normal mode - with no window/drop-down list appearing - hence all you see is the word instantly change.:
" instantly go with first spelling suggestion for word under the cursor
nnoremap <Leader>sp a<C-X>s<Esc>
N.B. The above remaps work better than:
nnoremap <Leader>sp z=1<cr><cr>
since with this one there's a brief flash as the suggestion window appears and is quickly closed again.
Yes, there is an options called spellsuggest. You can use the following setting:
" use only 9 suggestions
set spellsuggest=best,9
After that, the spell suggestion will take only a small portion of the window:

Using Ack.vim on visual selection

Currently I have this mapping in my ~/.vimrc
noremap <Leader>a :Ack <cword><cr>
which enables me to search for a word under the cursor.
I would like to search for a current visual selection instead, because sometimes words are not enough.
Is there a way I can send visual selection to ack.vim?
You can write a visual-mode map that yanks the highlighted text and then pastes it verbatim (properly escaped) onto the vim command-line:
vnoremap <Leader>a y:Ack <C-r>=fnameescape(#")<CR><CR>
This solution uses the <C-r>= trick that allows you to enter a kind of second-level command-line, which allows you to enter any vimscript expression, which is then evaluated, and the result is stringified and pasted onto the (original, first-level) command-line where the cursor is.
A slight disadvantage of this approach is that it commandeers the unnamed register, which you may not want.
While bgoldst's answer should work just fine, you could also consider my fork of ack.vim: https://github.com/AndrewRadev/ack.vim
It comes with a working :Ack command in visual mode, and a few other extras that I've summarized at the top of the README.
At the time of this writing this is the default behaviour of Ack.
Just do the following:
move your cursor on any word in normal mode (for instance, hit Esc button to enter in normal mode, you know...)
type :Ack with no argument
it will search for the word under the cursor
Usually I select text during a search in a file (for instance put cursor inside word and type * repeateadly) the type :Ack to look for that word in other files of the project.

how to leave search mode in VIM?

Given a file like the following:
blah
blah
collection = getCollection();
process(somethingInTheWay, target);
...after this short sequence of 'search' commands in vim...
/col<carriage return>
My cursor will be under the first appearance of "collection."
Now, what command(s) will remove the '/col' from my vim command line (in case I want to search afresh, for example)?
There are a couple of things that play a role here. Your input ("/col") is displayed in the command line for some extra time after search. Usually people don't care about this. After some time, some find it even helpful. You already left "search mode" when you pressed Enter and after vim put the cursor on the first match. vim will lazily remove the search string when redrawing screen or when the space is needed. There are some ways to remove it manually, if you want to:
Ctrl-L (redraw)
:redraw
any combination of / or : with Esc or Backspace
Now I wrote, that you already left "search mode" with Enter, but you may continue your last search at any time with n / N. These commands will just take whatever is in the special register / and use it for further searching. It would be possible to "disable" this behaviour by removing the last search pattern from /:
:let #/ = ""
You could manually put something into that register which would enable you to "continue search" without ever having started any search.
If you just want to get rid of the currently highlighted matches, type:
:noh
You can turn off or toggle highlighting matches in general:
:set nohls
:set hls!
The latter is a good candidate for a key binding. I use this to toggle highlighting of the last search (mnemonic: klear - not very accurate but works for me):
:nno <C-k> :set hls!<CR>

Omnicompletion search suggestions

Is there any way to configure Omnicompletion for / searches? So searching for /be would suggest other words in the text such as:
/be<tab>
Beatles
beer
Beethoven
personally, I think after typing / you can type a regex, auto-completion doesn't make much sense here... vim doesn't know what you want to have, how can it give suggestions? It is not like in Insert mode.
However there is way to achieve it.
you type /
you type Ctrl-F
you type i (go into insert mode)
you type beTAB
now you see the popup menu.
this works not only for /, but also for : (cmd mode)
Ctrl-F is handy when we write long commands
detail:
:h cedit
You can use the CmdlineComplete plugin.
It will be triggered with <C-n> / <C-p>, and won't show a completion menu (but you can cycle through candidates by repeating the trigger).
You can use a combination of 'incsearch' and command-line completion with CtrlR CtrlW (:h c_CTRL-R_CTRL-W) to achieve something quite close to what you want:
:set incsearch.
Start typing your search pattern, e.g. /Be. The cursor moves to the next potential match as you type.
As soon as the cursor lands on the word you want to complete, hit CtrlR CtrlW. This pulls the word down into your search prompt: it effectively "completes" your search pattern.
At stage 3 you could also use these variants instead:
CtrlR CtrlA (:h c_CTRL-R_CTRL-A) pulls down the WORD instead of the word.
CtrlL (:h c_CTRL-L) completes character by character.
I used the aforementioned CmdLineComplete plugin until I learned about
set incsearch

How to make words invisible in vim?

In vimwiki, I can input a link like this:
[[link]]
When I put cursor on the line, [[]] is visible:
>[[http://www.google.com/]]<
When the cursor is moved away, [[]] is invisible:
>http://www.google.com/<
I notice this behavior in vim's help manual(:help vim): *vim:*(*s are invisible until I type V).
I cannot figure out how it works. Thanks for your help.
This is a feature called "conceal" that was added in vim 7.3 (if I recall correctly). For a simple example, try this.
Open a buffer and type three lines, the middle one being "foobarbaz". Then enter the following ex commands:
set conceallevel=2
syntax match Todo /bar/ conceal
When your cursor is on the "foobarbaz" line, "bar" will be visible (and highlighted with the Todo highlight group if you have syntax highlighting on). Once you move off the line, "bar" will disappear.
For more information see :help conceal and :help conceallevel.
I think that hiding text can be a very helpful feature. Think about text folding or readability of links.
To hide text Vim 7.3 has introduced the "conceal" argument. Hiding text is a well defined Vim feature. It is not a dirty trick.
See
:help :syn-conceal
:help 'conceallevel'
:help 'concealcursor'
Please note that conceal works only for syntax regions, not for matches.
I have no experience with conceal, so I can't provide an example out of the box.
Habi

Resources