2. See definition of a function - copy name of function
3. Open new folder -> say 2 folders above the current file
4. Right click -> Find in Folder, paste name of function, enter
5. Get an overview with:
- a list of files where the function name is found
- for each line the surrounding code is also shown
- double clicking on a filename opens said file in a new tab
I have yet to find any vim/emacs tool that can do this so easily and effortlessly. Even with Emacs Projectile, you have to define a "project"? And then grep in that (but the user interface is just subpar).
Maybe I'm missing something, but for me, this is effectively stopping me using Vim/Emacs most of the time. I use Vim for editing individual files, but anything more than that, it is either IDEA (ok, I do Java dev a lot, so that's a must), or any Commander clone (which has a Find functionality).
There are a few components: 1) Some fancy keybindings, 2) A plugin, and 3) an optional wrapper script for launching commands inside a git project.
First, keybindings. You know about '#' and '*' in vim that search for the next occurrence of token under your carat? I have an additional binding that does the same, but doesnt move the carat. I bind it to <CR> (Enter), but you could bind it to whatever. If you bind it to <CR>, it will interfere with the minibuffer, which requires some shenanigans to work around (see the vimrc)
nnoremap <silent><CR> :let @/='\<<C-R>=expand("<cword>")<CR>\>'<CR>:set hls<CR>
This is nice for a few use cases. One, it is nice to see where a token is used in the current file, and two, it puts the highlighted word into a register, that you can later paste.I use mhinz/vim-grepper to execute searches, with my vimrc I can move the carat to the word I am interested in, press "enter", then type :Gr<TAB><ENTER> which will put me into grepper. Then I can press ^R/ (that is ctrl-r then /) which pastes the content of the '/' register. Grepper will then launch the selected search tool (ag, grep, git grep) and create a mini buffer of matches that you can click on, or highlight and press enter. Here is my vimrc if you want to give it a go. BE WARNED the first line of the vimrc calls git clone, if this is bad on your setup for some reason, dont use my vimrc.
https://gist.github.com/SeamusConnor/d7ebb747c91845055e069f0...
The last piece is executing the search from the correct directory, to do that, I use two methods. First, vim has a built in way to change its working directory (:chdir), so you could do a :chdir ../../. Second, if you are using git it is nice to run commands at the top level of the git directory sometimes. For that I have a script that translates commands from the CWD to the git top level. Some things you can do with it:
Rebuild cmake style project:
g make -C build && g ./build/my_program # you can execute this from anywhere inside the repo
Open a file inside vim: cd src/my/nested/folder/
g vim my_source_code.cpp # open vim at git top level directory, and translates the file to src/my/nested/folder/my_source_code.cpp
https://gist.github.com/SeamusConnor/645b66faff12ad5dbe3747f...Anyway, hope that helps you or someone else.
To be a bit more specific: I need to see the structure of what I'm searching in, so at minimum, that means neotree/nerdtree. I don't have photographic memory, or alphabetic memory, I always forget the names of folders, files, everything. I just couldn't care less. "../.." means nothing to me. What is that directory? Show me, and I will point to what I want.
Also, I don't want to search in a project. I want to search in a project OR in multiple projects OR in a subdirectory within a project, ad hoc. OR just select some files and search in them.
And in my opinion, for this specific use-case there is nothing wrong with using the mouse. When I'm searching for something in the way I described above I am usually browsing the code, reading it, trying to understand what is going on. This is different to when I'm actually coding something, then vi/emacs suddenly gets much more attractive, depending on the language used :)
You want cscope integration. Nothing compares to this in terms of ease of navigation - and I say that as a dedicated ST3 user. How to integrate cscope with vim:
http://cscope.sourceforge.net/cscope_vim_tutorial.htmlEmacs on the other hand provide very nice integration with various REPLs and functional languages have best tooling in it. Vim I use as terminal editor, and when I do work inside repo, reading diffs and programming in some languages (like C for example).
I really want to switch to only one editor, but whenever I try, I come to the point where I miss the feature of some other one of these 3. : ) I'm bit too weird when it comes to editors and configs...