Is it possible to get access for built-in completion sources like keywords in the current buffer or omnicompletion? I am trying to make my own completion manager based on completefunc. I know there is \k character class and I can simply search through the whole buffer but it is such an overhead to deal with on each key presses.
If not, do you know the way to copy all keywords into the list? Keep in mind, I need cursor ordinary atom \%# so the family of match functions is unacceptable.
No, currently there's no such function available in Vim. My CompleteHelper plugin has generic functions to extract arbitrary patterns from buffers; I use it to implement several custom completions. Additionally, I've written emulations of the local keyword and tag completions in this (unpublished) library. Feel free to reuse or derive your own code from it!
Related
Does anyone know of a vim plugin that allows to look up struct members/elements of structures in C or classes in case of C++?
I'm thinking something similar to jumping to a definition of a struct using cscope/ctags, but ideally I would want something similar to moving a cursor over the desired variable and a keystroke will pull up a table akin to when you use omni-complete?
I've been trying to find something but to no avail.
The requirement is: should be exclusively for vim.
99% of my development is sshing to a remote linux machine.
Normally my workflow is, git clone the project, setup ctags and cscope, open up the desired file and load up my cscope db and that's where I stay for the majority of the day, moving around the directory I have the nerd-tree plugin.
So far I use a combination of ctags/cscope, and calltree plugins to look up function callees.
I'm missing a plugin that allows me to simply look up struct elements.
I don't really use omnicompletion because it is notoriously slow and I've given up to make it faster.
Any ideas?
With universal-ctags, given you've used the right options, you can always obtain the members of a class/struct type.
If you read in between the lines, this means there is no efficient way to do it on a C++ variable if you stick to vimscript. I've tried do it, but I've given up on this path eventually ; path that has no way to support auto.
Now, I've started using (/implementing) another approach to analyse C++ code and exploit the information from vim: I rely on libclang. The catch is that it needs to operate on the current translation unit (TU), and if the TU is long (e.g if it includes many long files), it's takes time to parse it for the first time since the last time it has changed (I expect the solution to change with C++20 modules) -- the analysing is done on demand, and not in the background. Note: my plugin is currently under development and I haven't yet provided an high level Vim function that returns the type of a variable and its associated information (type, members, possible enum values...)
If your ultimate objective is completion of members, clang based tools provide a dedicated API for this purpose that'll be more efficient than completely analysing the current TU. The plugins you don't wish to use exploit this API. LSP servers even try to cache as much information as possible (for navigation and completion purpose only).
Note that there exist a few plugins, like tagbar, that tries to organize information extracted with ctags and present it in a hierarchic view. Note that it won't help with disambiguation nor with auto.
I'm learning vim bindings.
Is there a feature (or a tool) that, for a given command, will flag up any optimized/shorter way to perform it, when there is one?
For instance,
if I do (while in normal mode) i + →, I want a warning to be triggered saying that a is shorter to perform the same action.
You should understand that vim is highly customizable. It's so that is prone to do that mistakes that you mention. But, the only way to know that there is better shortcut for an operation: It's first check the vim documentation and then check your owns functions.
There is no such algorithm, plugin or function in vimscript that could enable detect that as far as I'm concerned.
You should read all chapters of learnvimscriptthehardway.stevelosh.com, understanding how vim works as a result you should know how to handle your owns functions, mappings, etc.
I found that arguments list is more useful than buffers list. With vim-airline plugin you can see all current buffers in the topbar. I wonder if there is a similar plugin or function to always display argument list? It would be useful if it could work together with vim-airline.
No, this is a bad idea. The argument list is frequently used for mass-editing many (hundreds) of files, and those wouldn't fit anywhere in the UI. That's why I'm also no fan of permanently displaying the buffer list. [1]
With tabs, windows, and buffers (and dozens of related commands), Vim has very powerful means to deal with multiple files. Each person's workflow is unique; you need to find your very own, personal one by learning the available commands (the :help is very comprehensive), and trying out different approaches.
[1] From a functional standpoint, buffer and argument lists actually are very similar. Both can be added to, removed from, and used for mass operations. It's only that the adding to the buffer list is done automatically.
For my particular cases, Vim's autocomplete often isn't that smart. Is there a way to switch to e.g. a bigram model (which predicts based on the previous word), or something even better? Would it be hard to write it myself (supposing I know how to write / use a n-gram histogram in an external program)?
As far as I know, the most powerful autocomplete plugin for vim is neocomplcache: https://github.com/Shougo/neocomplcache.
It has a lot of configuration option and it is easily extensible. It has word, snippet, filename, register and omni (syntax) completion. It's the most definitive solution I have found in vim, even if I know I should learn more about it to use more efficiently.
I have been getting very frustrated recently in dealing with a massive bulk of legacy code which I am trying to get familiar with.
Say I try to search for a particular function call, I get loads of results that turn out to be completely irrelevant; some of them are easy to spot, eg a comment saying
// Fixed functionality in foo() so don't need to handle this here any more
But others are much harder to spot manually, because they turn out to be calls from other functions in modules that are only compiled in certain cases, or are part of a much larger block of code that is #if 0'd out in its entirety.
What I'd like would be a search tool that would allow me to search for a term and give me the choice to include or exclude commented out or #if 0'd out code. Then the search results would be displayed alongside a list of #defines that are required in order for that snippet of code to be relevant.
I'm working in C / C++, but other than the specific comment syntax I guess the techniques should be more generally applicable.
Does such a tool exist?
Not entirely what you're after, but I find this quite handy.
GrepWin - A free visual "grep" tool for searching files.
I find it quite helpful because:
Its a separate app (doesn't lock up my editor)
Handles Regular expressions
Its fast
Can specify what folder to search, and what filetypes (handles regex's here too)
Can limit by file size
Can include subdirs (or exclude by regex)
etc.
Almost any decent source browser will let you go to where a function is defined, and/or list all the calls of that function and take you directly to a call site. This will normally be based on a fairly complete parse of the source code so it will ignore comments, code that's excluded by the preprocessor, and so on (in fact, in at least one case, the parser used by the source browser is almost certainly better than the one used in the compiler itself).