ctags: prevent jump to first result for ctrl + ] - vim

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]

Related

Insert a specific string instead of tabs or spaces in gVim

Since I'm working with LaTeX documents in vim, I want to be able to insert \quad instead of a tab space whenever I press tab (instead of having to replace/insert them manually). Is there any setting that could do this? If not, are there any plugins that work like this?
While you can use inoremap to change Tab to \quad in insert mode, that means
that you lose the original Tab functionality...
This might be worth it if you're sure that you'll never want to use Tab, but
what will you do when you face a similar problem of wanting some
latex-specific text? You could try and find a second key to map... but each
addition will take up a new key that already had some function.
The way I would handle this would be to use iabbrev to map some unlikely
sequence of keys like ;q to \quad:
iabbrev ;q \quad
This has the advantage that you can build up a whole set of insert mode
abbreviations, all consistently starting with ; followed by a letter or two
that you can choose to be easily remembered. And you get to keep all the
original functionality.

vim supertab, toward a best way to insert a tab

I really like the supertab plugin. Reaching <C-x><C-p> is a bit too long and mapping it to tab gives me a better workflow. However, sometime I just want to insert a regular tab and for this I need to insert a space first, i.e. foo<Space><Tab>bar.
This pollute my sources with useless spaces before each tab char (this assuming I don't use expandtab).
I am wondering is there is a smarter way to use auto-completion ?
Going back to <C-x><C-p> which is much slower
Using another key mapping like
Using supertab with a wiser feature:
i. Automatically insert a <Tab> if I press a char that doesn't match any of the possible completions.
ii. Inserting a real tab with
???
Any ideas?
You can suppress the Supertab trigger and insert a literal tab by pressing <C-v><Tab>. (On Windows, that frequently is <C-q><Tab>.)
Supertab also provides a mapping for direct input, by default <C-Tab>; see :help supertab-mappingtabliteral. That default key combination probably only works in GVIM, though.
Just another try.
You can have a global substitute after editing work like:
:%s/ \t /\t/g

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

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.

How do I make Vim do normal (Bash-like) tab completion for file names?

When I'm opening a new file in Vim and I use tab completion, it completes the whole file name instead of doing the partial match like Bash does. Is there an option to make this file name tab completion work more like Bash?
I personally use
set wildmode=longest,list,full
set wildmenu
When you type the first tab hit, it will complete as much as possible. The second tab hit will provide a list. The third and subsequent tabs will cycle through completion options so you can complete the file without further keys.
Bash-like would be just
set wildmode=longest,list
but the full is very handy.
The closest behavior to Bash's completion should be
set wildmode=longest:full,full
With a few character typed, pressing tab once will give all the matches available in wildmenu. This is different to the answer by Michael which opens a quickfix-like window beneath the command-line.
Then you can keep typing the rest of the characters or press tab again to auto-complete with first match and circle around it.
Apart from the suggested wildmode/wildmenu, Vim also offers the option to show all possible completions by using Ctrl + D. This might be helpful for some users that stumble across this question when searching for different autocompletion options in Vim like I did.
If you don't want to set the wildmenu, you can always press Ctrl + L when you want to open a file. Ctrl + L will complete the filename like Bash completion.
I'm assuming that you are using autocomplete in Vim via Ctrl + N to search through the current buffer. When you use this command, you get a list of solutions; simply repeat the command to go to the next item in the list. The same is true for all autocomplete commands. While they fill in the entire word, you can continue to move through the list until you arrive at the one you wish to use.
This may be a more useful command: Ctrl + P. The only difference is that Ctrl + P searches backwards in the buffer while Ctrl + N searches forwards... Realistically, they will both provide a list with the same elements, and they may just appear in a different order.
set wildmode=longest:full gives you a Bash-like completion with:
suggestions in a single line
Tab completing only what is certain
Right/Ctrl-n | Left/Ctrl-p to select suggestions.
From the help:
If you prefer the <Left> and <Right> keys to move the cursor instead
of selecting a different match, use this:
:cnoremap <Left> <Space><BS><Left>
:cnoremap <Right> <Space><BS><Right>
Try using :set wildmenu. Apart from that, I'm not sure what exactly you're trying.
Oh, yeah, and maybe try this link: link

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