vim word complete, how to make the first one always as default - vim

I am using several word complete plugins in vim (word_complete.vim, autocomplpop, omnicppcomplete-0.41). So far so good. It will pop up menus to let you choose which word to use, while I am typing the first characters
When I only type 2 characters, vim will set the first word in the popup menu as the default one, then you can directly press enter to use that word.
But the problem is usually 2 characters are not enough to narrow down the words to be complete. I need to type more. After my typing more than 2 characters, the default chosen word will disappear, then I have to use CTRL-N or CTRL-P to choose the word, although it is the first one in the popup menu.
Below is shows what I have:
The first is when I only type 2 characters
But after the third character is typed in, it appears as:
although "airline_detect_whitespace" is what i what to choose, I still need to type CTRL-N to choose it.
I am asking is there a way to configure the way vim chooses its default matcher?
for example, I want to type 5 characters before the default chosen word disappears.
Or is there a way to always make the first one in the popup menu to be chosen by default?
Thanks.

Have a look at the Make Vim completion popup menu work just like in an IDE page on the Vim Tips Wiki. It describes the setup to achieve this. Especially these mappings should create the behavior you want: Always have one menu entry pre-selected.
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
\ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
\ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'

Those three plugins have overlapping features and certainly conflicting mappings for the pop-up menu and autocommands and stuff.
For example, AutoComplPop does everything wordcomplete does in a smarter and more automated way. OmniCPPComplete, has an obviously better C++ completion algorithm than the default one in Vim (and thus AutoComplPop's one) and can be set to not perform autocompletion.
I'd suggest you remove wordcomplete from your config, disable OmniCPPComplete's "may complete" feature and let AutoComplPop deal with the "autocompletion" side of the problem.

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:

Mapping TO ctrl+[something] doesn't work in gvim

I am using GVim 7.4 and I would like to do some really simple mapping to use CtrlP fuzzy matching of tags when a key combination is used.
I tried 2 approaches and they all seem to fail when vim calls Control + [x] combination. While I do understand that there are restrictions when it comes to mapping Ctrl+[x] codes, I haven't found any information on why ctrl mapping wouldn't work.
noremap \t :CtrlPTag<CR><C-\>w
This one enters CtrlP tag mode but then it doesn't enter word from under the cursor.
noremap \t <C-p><C-\>w
Here we don't even get to CtrlP window (I even omit going into tag mode here for simplicity).
As far as I understand (I'm no CtrlP user), the plugin is triggered via some command / key combination, and then presents interactive selection and filtering. It even has different "source" modes.
Now, this is a pretty heavy integration into Vim, probably using scratch buffers and its own input loop. That's why you cannot simply append keys to the mapping and get them interpreted by the plugin "as typed".
Typically, these plugins offer mode selection and so on via (optional) command arguments. Check the plugin's help, and if you cannot get the plugin into the state you need, best contact the plugin's author and ask for such enhancement.

How to map keys for IdeaVim's normal mode to editor's action?

I am using JetBrains' phpstorm with the IdeaVim plugin.
I am wondering if I can bind keys in normal mode to editor actions.
For example, I used to have mapped Ctrl+B to Navigate > Declaration. Yet Ctrl+B is a vi motion to go one page backwards and that is ok.
I know I can configure a keyboard shortcut to a different one, e.g. Ctrl+Shift+B , yet to keep things simpler I want to have a key in ideavim's command mode mapped to that functionality, e.g. ;.
So that pressing ; in command mode would trigger the action of Declaration witin phpstorm.
How can I achieve this?
To give a specific answer for exactly what you asked to map: put this into your ~/.ideavimrc:
nnoremap ; :action VimGotoDeclaration<CR>
To find the action name, I typed :actionlist declaration which gives a subset of action names that include the word "declaration" in the action name.
As others have noted, you might also prefer to use one of the existing mappings rather than adding a new one.
what you wanted go to declaration is built in command in vim. You don't have to use IDEA's actions.
gd (goto declaration) is the thing you are looking for.
So you just press (normal mode) gd, to see what is gonna happen.
In a normal vim, do :h gd to check details.
You can use <C-]> (Ctrl+]) for following references (jumping to the declaration is an example of a reference) and <C-O> for going back. You can also map these Vim-style shortcuts using the map commands similar to the original Vim.

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

Is there a way to change the behavior of the vim omnicomplete menu?

Omnicompletion is working, but it automatically inserts the first result.
What I'd like to do is open the omnicomplete menu, then be able to type to narrow down the results, then hit enter or tab or space or something to insert the selected menu item.
Is this possible?
The command you are looking for is:
:set completeopt+=longest
It will insert the longest common prefix of all the suggestions, then you can type and delete to narrow down or expand results.
set wildmenu
set wildmode=list:longest,full
Found here.
There is also a great plugin for all of your completion needs called SuperTab continued.
This plugin might do what you are after: autocomplpop
Or you can try and make Vim completion popup menu work just like in an IDE.
This is the general Vim completion behaviour. For a complete overview, you can do
:he compl-current
But for your specific case (which you require the completion to be in state 2 or 3 (described in the document above). You can simply use Backspace, or Control-H to jump from state one to state two. In state 2 you can narrow the search by typing regular characters. So to complete completion with narrowing:
compl<C-X><C-P><BS>letion
It is totally backwards, I know, but that's how it works.
Edit: You can use the Down arrow key too isntead of Control-H or Backspace, and it has the benefit of not deleting a character.

Resources