I'm currently using superTab for completions in Vim. However, I'd like the completions to be more like bash. For example, if I'm typing
st
and the possible completions are
struct, string
I'd like it to be completed to
str
if I press tab, and ideally display a menu of possible completions.
Plugins are OK.
EDIT: completeopt+=menu, longest does most of what I want, but after the menu pops up and I narrow it down some, pressing tab again does a full completion instead of giving the next longest common prefix.
:set completeopt+=longest
should do the trick.
A great resource for tweaking the completion is Make Vim completion popup menu work just like in an IDE.
Related
In vim, when using an autocomplete plugin (or just vim's built-in omnifunc), a window will pop up next to the cursor with completion suggestions:
Vim tries to be smart about where to put this menu, putting it below the cursor most of the time, but above the cursor if you're near the bottom of the window and don't have space to see the window.
I recently updated to a new version of vim (and YouCompleteMe, the autocomplete plugin that I use), and it seems that vim (or YCM, not sure which is responsible) is now overly aggressive in putting things above the cursor instead of below, where basically if you're in the top half of the window, the popup menu is below the cursor, while if you're in the bottom half, the popup menu is always above the cursor.
My question is, how do I control this behavior? It seems like it's probably a vim setting, but in all of my searching I couldn't find anything that would hint at how vim decides whether to put the popup menu above or below the cursor.
The only completion-related options are 'complete' and 'completeopt'. The placement of the complete popup menu is hard-coded in Vim's source code.
If you think this has changed for the worse in a recent Vim version, please open an issue at the bug tracker, or directly discuss this on the vim_dev mailing list.
In my Vimrc, I have this set:
set wildmenu
set wildmode=full
set wildignorecase
When you are typing like NERDTree, and press Tab you see the suggests results in your statusline. Looks awesome, right?
I would like to have a function, that every time you press a character in the command, the Tab is automatically pressed. So every time, you type a character, you see the suggested commands in the statusline. Like Emacs M-x.
I looked in help in the autocommands, but none of the events described the event (pressing characters in command line).
Anyone have a idea which event I mean?
There is no such event. You're probably thinking of InsertCharPre, but that's limited to insert mode. You would need to override every printable character in command-line mode via :cmap, but that could have other side effects, or interfere with some plugins.
Better think hard whether you really need this. The wild menu is modeled after shell completion, and that has to be explicitly triggered via <Tab>, too.
Perhaps you want wilder.nvim.
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.
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.
To open a file in vim, I usually type ":e " and then hit tab until the file I want appears.
However, I always get in a rhythm and inadvertently go ONE past the desired file. Without knowing how to move backwards, I end up tabbing all the way to the end and repeating the whole process.
Is there a way to perform the filename completion in reverse order?
Shift-Tab goes backwards.
You can also use set wildmenu to get a list of matching file names above the status bar when you do file name completition with Tab. Then you can select the file name with the arrow keys from this list.
Shift+Tab and Ctrl+P both go backward.
However Shift+Tab only works with the GUI [1]. Since I am using vim and not gvim, Shift+Tab would not work. Ctrl+P works perfectly.
[1] And on the Amiga and MS-DOS. See ":help cmdline-completion" for more info.
If you got here because your vim autocompletion starts with the last item when you use "Tab", cycles backward from there AND you're using the Supertab plugin, here is your solution: https://stackoverflow.com/a/17105393/332451
let g:SuperTabDefaultCompletionType = "<c-n>"