Outline view with autocompletion in Vim - vim

Eclipse has a feature (under Ctrl+O) that lets you choose a method or a variable, with autocompletion.
I am aware of the tagbar plugin for Vim but I'm looking for something that would show a pop-up (similar to what Eclipse does) and be able to get me to certain method after I choose it.

No need for plugins, that is built into vim.
You could do , that's CTRL+X followed by
: File completion
: Line completion
: Omni completion
: Dictionary completion
You could customise the pop-up window the way you like.
The 'complete' option controls where the keywords are searched
(include files, tag files, buffers, and more).
The 'completeopt' option controls how the completion occurs (for
example, whether a menu is shown).
See for details: http://vimdoc.sourceforge.net/htmldoc/options.html#'completeopt'

This is the usual workflow:
Index your project with ctags, cscope or some compatible program. Using ctags as an example:
$ ctags -R .
Query that index from Vim:
:tselect /expan
Choose from the list:
Note that Vim also comes with a more lightweight solution:
:dlist /foo
that will search through the current buffer and included files for foo.

The plugin which has the functionalities I was looking for is ctrlp-funky.
It works only with functions and methods but its enough for my needs and works with every language without having to configure anything (like ctags/cscope).

Related

Filter vim's quickfix window per file

I'm using the cquery language server in my Neovim instance. In conjunction with the Languageclient-neovim plugin. This automatically also checks the code for errors in the file that I'm working. However, this also means it checks all the files in my workspace.
I was wondering if there was a possibility to only show errors that are specific to the file that I am working in. See the example below:
I'm working in the file src/bag_rotation.cpp and I only want to filter the quickfix window to only show errors from that file.
yes, I wrote a vim plugin, can do ":Keep" and ":Reject" on quickfix window (among other things).
https://github.com/romainl/vim-qf
You can just give the suitable pattern to do your filtering.
yes, I wrote a vim plugin, can do "grep" on quickfix window.
https://github.com/sk1418/QFGrep
You can just give the suitable pattern to do your filtering.
yes, I wrote a vim plugin gist, can do :Cfilter and :Cfilter! (invert search)
https://gist.github.com/PeterRincker/33345cf7fdeb9038611e4a338a0067f3
You can just give the suitable pattern to do your filtering.
:Cfilter /foo/

plugin to vim that shows definition of function/macro/struct in a popup box?

Im using vim with ctag+tagbar plugin to navigate through kernel code and its amazing ! Thanks to a guide I saw here.
I read here about some nice shortcuts for ctags that helps a lot, but I couldnt find a way that a definition(of structs/function etc) would show in popup box - something like eclipse ide.
Is there a way to do so with ctag? is there a plug-in I can add to vim that would that ? so when the mouse cursor(or also keyboard cursor) on function a popup box next to it will show?
Thanks!
Generally, you should avoid trying to use Vim as an IDE. It's meant to be a modular text editor.
Having said that, if you are looking for eclipse functionality inside of Vim, you may want to consider eclim. Another good set of plugins are the Clang based tools, like clang-format and YouCompleteMe.
ctags is very useful plugin, but if you also use ctags you can then copy file http://cscope.sourceforge.net/cscope_maps.vim to your ~/.vim/plugin directory and this will add keymappings that will allow you to jump to definition or show it in horizontal or vertical split.
I also added to my cscope_maps file an extra set of mappings like so:
nmap <C-h>g :tab cs find g <C-R>=expand("<cword>")<CR><CR>
to open my search in a new tab.
Example above allows you to use Ctrl+h and then g to "find global definition(s) of the token under cursor" and open it in a new tab.
Consider using cscope- it can also work with ctags (I always use both).
I know that this is not a pop-up window, but vim is not an IDE.

TextMate's Jump to Function in VIM?

Recently I've been trying my hand at using vim instead of TextMate and one of the features that I've missed most in VIM is TextMate's jump to method function (CMD + Shift + T for those who don't know). From looking around I havn't seen any particular way to emulate this functionality and was wondering if anyone here has had experience with this sort of functionality in VIM.
Thanks in advance for any answers
Patrick
You're looking for vim's 'tags' functionality ... I answered a similar question about tags here: How to implement own tag jump in VIM with CTRL-]?
This functionality has been implemented in fuzzyfinder using :FufBufferTag. See the ticket
I'd love to hear good suggestions as I use Vim all the time but haven't used TextMate. I do the following things which slightly overlap.
Search for d-e-f-space-<first few letters of function name>. So to go to function foo (in Python or Ruby, and within the same file of course), I type /def fo and I'm there. I also have incremental search enabled in Vim.
Use marks for functions which I visit often. So I'll ma at the function definition and then 'a back to it later. I know it's not function definitions but it is a crutch.
you can create a tags file with ctags http://ctags.sourceforge.net/
basically $ctags -R
Then once you're in vim :set tags=/path/to/tagsfile
this will also be any tag so not just class names, methods, etc. In normal mode ctrl-] on the method/class/ and it will jump to that position.
You can also use the taglist plugin which will display current tags in a side window. ctags
I had pretty much the same problem and I found a quick and dirty solution (paste this in your .vimrc and call by typing :LS)
function! s:ListFunctions()
vimgrep /function/j %
copen
endfunction
command! -bar -narg=0 LS call s:ListFunctions()
If you require more functionality then Exuberant Ctags will do better for you
I'm using CommandT for file searching, then / to search for a particular function. However, the real issue is with CSS. Cmd Shift T in Textmate enable quick jumps to a particular CSS class, and that is a huge time-saver.
CTags doesn't support CSS parsing, unless you re-compile with a patch (found via google), but I'm not even sure if we can do fuzzy searching for CSS classes like in Textmate. I really miss the Cmd Shift T feature.
I've written a TextMate Bundle command (you can easily assign it to Ctrl+] for example) that lookup for the definition of the class or method under the caret and displays it in a tooltip, along with the file name and the line where it was find.
Check it out: Add a shortcut to TextMate to lookup a class or method definition in a tooltip
Hope you'll find it useful!
The feature described in this question has many different names depending on the IDE/Editor:
In Resharper it's called "Goto File member"
In Sublime Text 2 it's called "Goto Symbol"
In PyCharm it's called "Goto Symbol"
The feature is essentially the same though in all of the above implementations (and I assume it's very similar in TextMate as well). The feature brings up an interactive list of methods/functions (and potentially also includes member variables/properties).
The list allows interactive filtering by typing the name of a methods/functions/etc. The list also usually allows the use of arrow keys to select a method/function/etc. Hitting the enter key with a method/function/etc selected navigates to the line in the current file where the selected method/function/etc is defined.
Of all the existing answers in this question the only one that I see which seems to provide a reasonably similar implementation of this feature is to use the command:
:FufBufferTag
in vim's FuzzyFinder plugin.
The answer which suggests using the taglist plugin is not a good solution, because the functionality offered by the taglist plugin is quite different from the feature. The taglist plugin offers similar functionality - the ability to view an outline of methods in the currently file, but it does not offer an interactive way to filter that list in realtime. The taglist plugin does allow you to search the tag buffer, but that's not nearly as convenient as the "Goto symbol" functionality offered in other editors.
I wanted to provide an alternative suggestion here, which is to use the command:
:CtrlPBufTag
in the excellent Ctrlp vim plugin. In my opinion this by far the best implementation of the "Goto Symbol" feature currently available in vim.

How to navigate in large project in VIM

How do you manage big projects (hundreds of files) using only VIM?
I personally start having problems in any larger than small project.
is there any way to quickly 'go to file', preferably with name completition?
same for 'go to class definition', when it is in another file
I kinda know all the VIM basics, so I don't have problem using it for writing scripts or quick editing some source code. But it gets really messy for me when I have to navigate between files.
VIM has excellent support for tags. Once you have created a tags file for your project, you can jump to a definition or declaration of a method, class, etc., including jumping across files, all inside the same editing session.
Try
:help tags
To generate a tags file for C/C++, go to your shell prompt (I'm assuming your system is *nix/Cygwin) and type
info ctags
or
ctags --help
I like simple solutions, my favorite way to navigate at the moment is:
Add to ~/.vimrc.local
set path=$PWD/**
Then type this in the editor to find the file anywhere in the current working directory (pwd)
:find user_spec.rb
You can use tab-completion on the filenames to find multiple choices as well, making this TextMate convert very happy.
I use a combination of NERDTree (directory sidebar), FuzzyFinder Textmate (go-to-file like TextMate's CMD+T), and Sessions (:h sessions) to help me deal with large projects.
I would suggest using some sessions helper plugin. I would mention what I use, but I'm not satisfied with it yet. Just Google "vim sessions".
One thing to note with getting FuzzyFinder Textmate to work is that it depends on an old version the FuzzyFinder plugin, specifically v2.16. Anything higher and you'll get errors. But it's definitely worth the trouble. While it doesn't have name completion, its search is smart so if I search for fro/time/actionsphp it will pull up the file apps/(fro)ntend/modules/(time)_tracking/actions/(actions).class.(php) (parenthesis denote what it's matching). It makes it very easy to pick out files that are only unique by their folder name.
As well as the invaluable ctags and the various associated commands. I also couldn't live without the project plugin, which allows you to have the files of interest associated with a project in a separate pane. I can't remember how much of my setup is customised, but if I want to open a source file called Debug.c, I hit:
<F12> " Opens the project pane
/De " Searches for "De", which is likely to be enough to find Debug.c or possibly Debug.h
<ENTER> " Opens the selected file and closes the project pane
I often then do:
:vsp " Vertically split the window
<F12> " Reopen project pane
# " Search back to find previous entry with the same name (to find
Debug.h if I was on Debug.c: my headers are in Headers/ and
my source is in Source/, so the headers come earlier in the list
than the source). I use * to go the other way, obviously.
<ENTER> " Open the header file in the other window and close the project window.
With this relatively short sequence, I can open any file and it's header in a vertical split. Since the project plugin window is just a text file, completion is achieved by using Vim's searching capability.
Starting in Vim 7.3, the :find command has tab-completion of filenames.
So if you set your 'path' option to contain your entire project (probably using the ** wildcard to allow recursively searching subdirectories), then you can use the :find, :sfind, :tabfind, etc. commands with completion to get to any file in your project. This also allows jumping to files directly with gf and friends if the file name is in your text, for example in an include directive.
With this method, no external tools or plugins are needed for navigating to specific files. Although, it may admittedly not be as fast or easy to use, and doesn't address the need for jumping to definitions. For definitions, I use ctags as other answers suggest.
If you are using ctags as other posters have recommended, then make sure you look at the taglist plugin.
Make sure you take the time to read the docs and learn the key bindings. Here are a few to get you started (from the TList window):
o - open file in new window
t - open file in new tab
[[ or backspace - previous file in list
]] or tab - next file in list
Exuberant ctags.
Use Ctrl-] to jump to the tag under the cursor.
Opening vim from root of your source file and extending path option to include all sub-directories therein.
For example set path+=/usr/include/c++/** for C++ headers and set path+=** for your source directory.
This ,then, opens a plethora of following possibilities.
1) Opening file by name or parts of it
:find file_name
You can use auto-completion and wildcard expansion with :find reliably. You type the name, it will locate the name. This works language agnostic.I am sure you will like it.
2) Navigating to files under cusror:
if you want to go a file path like #include "project/path/classA.h.
gf or gF - go to file under cursor.
Ctrl-6 - to come back to last cursor position after gf or gF
3) API lookup and navigating to the API location
[i or [I can be used to look up your function signature for word under cursor without leaving your workspace. [<Tab> to actually go to declaration. Use Ctrl-6 to come back to last location.
Without extending path, you can start navigating files by :Ex command and navigate and open your file. I prefer NerdTree over this though.
I use FindFile. If you open vim at the root of your project and run :FC . the plugin will cache all the filenames beneath your cwd. You can then do :FF to open a completion menu and type the name of the file you want (or rather, the first few letters).
Although I'm kinda hoping someone will point out a better solution so I can learn something, NERDTree has been good to me for getting to specific files with name completion as long as I have the tree expanded. The command when I need to get to a file is something like:
,d/foo.pyo (where foo.py is a file name)
,d to open the tree, / to enter search mode, the name (or partial name, or regex, or whatever) of the file, and then o to open.
Of course you may have to hit 'n' a few times if you didn't type enough of the filename or there are duplicates.
I admit it feels like a bit of a hack using NERDTree like this although it has gotten so far into my muscle memory by now that I don't even think about it.
Of course I use ctags too but those are only useful when you have a function near the cursor and need to get to its definition in another file or something. A lot of times I say "OK, I need to work on feature x now" and need to navigate to another file without any references nearby that ctags would really help with.
I'm using two plugins of mine:
searchInRuntime that completes filenames on command line. It is somehow similar to fuzzyfinder and lookupfile,
lh-tags which is completely experimental and undocumented. It offers two features: automatic and quick update of the tagfile on file save(ing?), and a tag selector plugged to <c-w><m-down> by default. You may want to check the renowned taglist plugin instead.
Both require my viml library lh-vim-lib.
Try SourceCodeObedinece. This one I developed to handle C++ 1Gb source files project.
I use it in pair with 0scan.
These two plugins are wrappers around the most popular Vim browsing tools: ctags and cscope.

show function parameters in vim

Is there a way in vim to get a popup window with function parameters? (like in visual studio / slick edit)
e.g. when i type "function_name(" vim will open a popup window (like when doing ctrl-n in new versions) and show me the function parameters and which one of them I'm currently typing.
p.s.
I'm looking for something a bit more comfortable than ctrl-w ctrl-]
I'm also looking for a similar functionality that will show me list of available members when typing "var->" or "var."
I'm using C
Do check out the autocomplpop and TTrCodeAssistor plug-ins.
As was already suggested, install the autocomplpop plugin. Then,
to trigger omincompletion as you type for C files, you could add the following to your .vimrc:
let g:AutoComplPop_Behavior = {
\ 'c': [ {'command' : "\<C-x>\<C-o>",
\ 'pattern' : ".",
\ 'repeat' : 0}
\ ]
\}
If you don't want to trigger omnicompletion for every character typed, change the pattern value to suit your needs. For information on how to further customize, look at the documentation in the comment header of autocomplpop.vim
Moreover, to get a popup window with function parameters also add the following to your .vimrc:
let g:AutoComplPop_CompleteoptPreview = 1
To make it work make sure you generated a tags file with ctags.
YouCompleteMe is a nice alternative that offers fuzzy autocompletion and uses clang to deal with the semantics.
Check cream - it seems to have some C support. You'll need ctags.
A modern configuration of the powerful and famous Vim, Cream is now available for Microsoft Windows, GNU/Linux, and FreeBSD
... (Programmer Features)
Pop up prototype and information menu ( Alt+( ). View the function's prototype under the cursor without having to open the file with the definition.
Or you can try vim-assistant script.

Resources