How to i show omnicomplete's autocomplete list without autocompleting current text - vim

I am learning vim with omnicomplete. I am wondering whether I can show the omnicomplete list without autocompleting current text. For example,
If I type "str.c" and then invoke omnicomplete, it will show a list containing possible words starting with "c", and autocomplete the current text to, say "capitalize".
If, for example, the method I am looking for is count, I have to scroll all the way down the list to find it, or delete the "apitalize" part, and then type o, etc. Is it possible to just show the list, so that if I invoke it after c, it will show the list without autocompleting to capitalize? For example to something like below, where I can still type o to quickly go to count

Thanks to #romainl comment, I looked up completeopt, and I found the answer Make Vim completion popup menu work just like in an IDE. It has a bunch of other related tips. To make the behaviour as described in the question,
:set completeopt=longest,menuone

You can also just stick with the basic vim functionality, and use C-e while in completion to have vim remove the list and go back to the point you initiated the completion.

Alternatively, you can press <C-P> right after <C-X><C-O> to go back to what you typed while keeping the completion menu open.
Check out :h ins-completion-menu for more information.

I think that the initial problem was the lack of noinsert in completeopt option.

Related

enter button insert a new line instead of choosing an alternative

Recently when I tried to use the ctrl+n or ctrl+p to auto-complete, when there are multiple alternatives, tapping the enter button will insert a new line instead choose the alternative I want.
This did not happen before, maybe because I installed too many plugins and caused the conflicts. It would be horrible to check all these plugins' shot cuts and find out the source. So mapping the built-in auto-complete to some other keys could be a solution, but I don't know how to do that.
This is not a big problem but really made coding not "smooth". Anybody has met this situation before and how did you deal with it.
Short answer: You don't need to use <cr> to accept a match.
Snippet from the vim help :h popupmenu-keys
The behavior of the <Enter> key depends on the state you are in:
first state: Use the text as it is and insert a line break.
second state: Insert the currently selected match.
third state: Use the text as it is and insert a line break.
In other words: If you used the cursor keys to select another entry in the
list of matches then the <Enter> key inserts that match. If you typed
something else then <Enter> inserts a line break.
I would suggest you use <c-n> and <c-p> to switch to the correct mapping and then continue on with your typing. Typically this means I type a space or some other punctuation key and the menu closes. I never use <cr> to select a menu item. If however you really want to accept a match use <c-y>. Think "yes" to the selected menu item.
I just fixed a very similar problem caused by the vim-autoclose plugin by replacing it with the Auto-Pairs plugin. I doubt that yours is exactly the same culprit but it's actually not too bad hunting down the guilty party if you use pathogen for your plugins - just move half of your plugins from ~/.vim/bundle (or wherever they are) into a different folder, restart vim and test the autocompletion. If it works as expected, you know that one of the plugins you have moved out is responsible, so you can do the same again until you have narrowed it down.
Before that, you can also try running vim -u NONE which ignores your .vimrc file - it may be that you've snuck something in yourself and this is the fastest way to rule it out.
Good luck anyway. This took me about ten minutes and after probably a year of occasional annoyance I wish I had taken the time earlier.

ctags: prevent jump to first result for ctrl + ]

I wanted to prevent jumping to the first result without user intervention upon ctrl +] (or left click) in vim. In effect, when I click (ctrl +]) on an identifier, it should list all the occurance (like tag search) and should jump to the selection (1,2..) when user input 1,2 etc. I remember using it by setting an option in .vimrc (something like cscope mode), but couldn't recollect now.
Are you looking for tag-matchlist?
Sounds like you want g]. It shows the matching tags.
While I don't think there's an option to make Ctrl+] show a list if there's only one result, if you set cscopetag and set cscopetagorder=0, then you'll search your cscope database which will likely show more results than your tags. (Especially if you're using C++ and have --c++-kinds=+p which will include function prototypes and the implementations -- you almost always have two of the same thing. I use that setting because it's required by omnicppcomplete.)
You still won't get a list if you only have one result. For that, you'd have to make maps to swap Ctrl+] and g].
You can add the following line in .vimrc
map <C-]> g]

Vim: Making Auto-Completion Smarter

I use ctags, taglist, etc., to have auto completion in Vim. However, it is very limited compared to Visual Studio intellisense or Eclipse auto-completion. I am wondering whether it is possible to tune Vim to:
Show auto-completion whenever . or -> are typed. But only after some text that might be a variable (e.g. avoid showing auto completion after a number).
Show function parameters when ( is typed.
Stop removing the auto completion list when some delete all characters after . or ->: When I enter a variable name, then press . or -> to search for a certain member, I frequently have to delete all the characters I type after the . or ->, but this makes Vim hide the auto completion list. I would like to keep it visible unless I press Esc.
Showing related auto completion: When I type a variable and press ^X ^O, it usually shows me all the tags in the ctags file. I would like to have it showing only the tags related to the variable.
Thanks for the help.
EDIT: Some people are voting for this question, but no body seems to know the answer. So just wanted to mention that you don't have to provide a complete answer; partial answers to any of the mentioned points would be good also.
AutoComplPop is what you need.
For (1) when working with C++ or C clang complete is a really nice option
To make vim trigger a certain behavior when a key is pressed you need to map the key to a function.
For instance to map the key . to call some type of completion when in INSERT mode you would need to do:
:inoremap <expr> <buffer> . MyFunction()
and then the function would need to evaluate the context where it was called and present an appropriate answer to the user.
Edit: This is the basis of how clang complete mentioned by #honk works.
I'm not sure if you can customize the behavior of omnifunc to meet your needs but on my experience, I never went too far. As #Mikhail said, you would need to keep track of things which in practice means interpreting or even running the code to some extent.
I use vim every day, and I'm not aware of any existing script that may do this. This action would require understanding of classes and keeping track of variables. someObject-> means that VIM would know what class the variable someObject is, and then be able to search methods/variables within that class.
Writing scripts for vim is relatively easy, though like you've commented - no one has answered this yet. Up vote from me.
I would love to have that same functionality that you are looking for and just came across a promising plugin:
https://github.com/Shougo/neocomplcache looks like it could be the new autocomplpop, and seems to work quite well during my initial trials... now to configure the omni completion to work with scala~
I've recently discovered YouCompleteMe, it behaves similarly to the Visual Studio autocomplete tool. A demonstration can be seen here:
https://www.youtube.com/watch?v=YuMyHAHF0xs
In any case, I recommend YouCompleteMe (YCM). It provides (fuzzy) matching of identifiers of your current file, as well as path-completion, integration with external completion engines,...
ad 1)
If you like the semantic completion of eclipse, use eclim to integrate vim with eclipse. (alernatively use another semantic engine for YCM)
ad 2)
These 2 play nicely together btw.,: YCM can even provide the function definition (= parameter list) of the recently completed function!
ad 3)
that's what YCM does anyways
ad 4)
not quite sure, what you mean by that one. never used ctags!
P.S.: I strongly recommend using UltiSnips and Tagbar (and if you like UndoTree) additionally, what makes vim a perfect IDE for me.

Using the quickfix window with vim+jslint

I'm using the vim+jslint combo described here, and am having problems figuring out how to use the two together. I'm guessing that the list of errors is supposed to show on the top half and the second half has the actual page? If so, how do I go about doing this? (Caution, I am completely new to the quickfix window, and the documentation isn't exactly the best at describing how to use it).
The quickfix documentation in the user manual section of Vim's help is good. You have to remember, that Vim's help has both a user manual and a reference manual. The latter is more terse.
The general run down is, after running :make the quickfix list is populated with anything the 'errorformat' option has been configured to parse. You use the :cn and :cN commands to move forward/backward through the quickfix list, respectively.
In the end I hacked the jslint script to output in the format for the quickfix window. I replaced:
//print((e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));print('');
with
print(a[0]+':'+e.line+':'+e.reason)
I think

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