In TextMate you can drag one or more files onto the icon and use "Find in Project" to search those files, can this be replicated for the current open buffers in Vim?
grep
lgrep
vimgrep
lvimgrep
These commands might help you.
Check here, If this is what you are looking for.
http://vim.wikia.com/wiki/Find_in_files_within_Vim
I like LustyExplorer which has a very fast and easy to use "search in buffers" function.
Ack.vim works in a sort-of-similar way but is file-system based.
Out of the box, Vim does not have project management features, but as mentioned by sat you can use various grep command to find something in files or sub-directories.
However you can install project.vim which is a plugin providing the management of multiple files (including search a la Textmate)
Related
There are a couple of things I do not yet understand the VIM way.
One of these is searching in a project like so (using VIM in Atom):
I use CtrlP currently for file names, but what about the contents?
How can I search with a string, and then look through a list of all occurrences using VIM and/or VIM plugins?
I've found an even better solution for this: FZF
It simply searches through everything in your project asynchronously using the :Ag command.
Use :grep or :vimgrep to search file contents. The results are put onto the "location list" which you can open by typing :cw Enter.
Syntax for :grep is, by default, the same as the grep(1) command:
:grep 'my pattern.*' /path/to/dir
By default it will search the current directory (:pwd). I added set autochdir to my .vimrc so my PWD always follows the file I'm editing.
The major difference between :grep and :vimgrep is that :vimgrep (:vim for short) uses Vim-compatible regular expressions, whereas :grep uses whatever regular expressions your &grepprg uses.
You can use a custom program by setting &grepprg to something different. I personally like ack which uses Perl-compatible regex.
Apart from fzf, there are also other excellent plugins for fuzzy finding.
telescope.nvim (neovim only): after install, just use Telescope live_grep to search through your project.
Leaderf: another fuzzy finder with good performance. After install, use Leaderf rg to search through your project.
To open a file, I highlight the row (Shift-v) in the location list and hit Enter.
What is the best way/plugin to explore filesystem and to open files and directories?
The best way to explore filesystem/directories in Vim is the one that best suits your needs. As it is phrased, this question can't get an answer because there's no "way" universally agreed upon.
On the other hand, if you want to have an overview of the many ways to explore the filesystem in Vim then, yes, that is a question that can be answered. In a non-exhaustive way, though.
NERDTree and netrw are already covered. These plugins show you a tree-like list of files and directories that you can act on. Before trying NERDTree, I'd suggest you try your hands on netrw as it comes with Vim by default and offers a much wider range of features than NERDTree. You should look around on http://www.vim.org because there are a bunch of similar plugins.
On the opposite side of the spectrum, you have Vim's own file handling capabilities. Here is a sample of commands you can use from Vim to open files:
:e filename edits filename
:sp filename edits filename in an horizontal split
:vs filename edits filename in a vertical split
:tabe filename edits filename in a new tab
You have tab-completion, just like in the shell:
:e <tab> goes through all the directories/files in the working directory
You can use wildcards, of course:
:e **/*.js<tab> shows all the js files in the working directory and its subdirectories
Assuming you have set wildmenu in your ~/.vimrc, you can make tab-completion even better with an horizontal menu which can be customized further…
You can also use "args"… but that will be for another time.
Somewhere between Vim's default commands and netrw/NERDTree you can find a bunch of "fuzzy" and less fuzzy file openers more or less modeled after a feature introduced in TextMate a while ago: FuzzyFinder, LustyExplorer, Command-T, CtrlP and many other variations on the same theme. The core concept is to provide you with a list of choice that you narrow down by typing more characters in a prompt until the file ou want to edit is selected.
If you decide you want to go down the plugin road, I'd suggest you visit http://www.vim.org, compare what's there, try a few plugins and decide for yourself.
Anyway, you should get used to the basics before looking for a plugin.
Try NERD Tree, besides the tree tab it also enhances the classical directory listing as suggested by #ATOzToa.
On Windows, I find :!start explorer %:p:h to be the way to go, or :!start explorer . if I'm in the directory I want opened.
On MacVim you could probably do something similar with :!open . to open a Finder window on the current directory but I don't have a Mac handy to try it out.
Not sure what you'd use in GNU/Linux; it probably depends on your desktop manager.
I'm looking for a vim plugin similar to http://www.vim.org/scripts/script.php?script_id=1325 with a directory list in which you can select a file to open. Does this exist somewhere? Wasn't able to find it myself.
NERDTree is the second best ranked plugin on vim.org and it perfectly fits your description.
There are many other variations of the same principle:
FuzzyFinder
LustyExplorer (the one I used before)
Command-T (famous among TextMate switchers, I never liked it, though)
CtrlP (the one I use now)
…
And I second :Explore.
Have you tried the :Explore command that comes with the standard vim distribution since (roughly) version 6?
See http://vim.wikia.com/wiki/File_explorer for basic help on that command.
See http://vimdoc.sourceforge.net/htmldoc/pi_netrw.html#netrw-quickhelp for detailed help on what the Explorer can do.
If you want to open an explorer without replacing the current buffer, you can use the :Sexplore command. A puerile mnemonic for that is to execute :Sex.
What are some options for getting really fast 'Find in Files' searching in VIM?
Our codebase is large enough that searching needs to work off an index. grep/vimgrep/etc are too slow.
Indexing doesn't need to be particularly fast; I can index overnight.
Thanks,
[EDIT] I'm also working in a Windows environment.
If it's source code (rather than full text search), then ctags with the TagList plugin should work well for your needs. See, for example:
http://www.thegeekstuff.com/2009/04/ctags-taglist-vi-vim-editor-as-sourece-code-browser/
EDIT: TagList and ctags will work on Windows as well (that's what I use). See the TagList install page and FAQ. The following links might prove useful:
http://www.vim.org/scripts/script.php?script_id=273
http://vim-taglist.sourceforge.net/installation.html
http://vim-taglist.sourceforge.net/faq.html
There's also a TagList forum where you can get further help:
http://tech.groups.yahoo.com/group/taglist/
I set it up on my windows machine a while back, but I don't remember encountering any problems.
Something that I use, but not through vim, is ack: http://betterthangrep.com/
It is a perl based tool, and it should be usable in Windows.
If you're working with a large codebase, then it might be time to look for a more powerful solution than conventional tools. OpenGrok is a very fast source code search and cross-reference engine. On top of its great performance, it integrates with Subversion, Mercurial, and ClearCase, among other source revision control software. It sounds a lot like something you could use.
If you want support to use OpenGrok from within Vim, you could easily write a vim function that would call system() to start the search for you. To read more about writing new vim commands, look up :help 40.2 within vim.
I hope that's what you were looking for.
I don't know how I found this, but looks like someone has written a plugin for google desktop
Try to install https://github.com/mileszs/ack.vim, http://beyondgrep.com/ ,
then make a link
ln -s /usr/bin/ack-grep /usr/bin/ack
and add
noremap <C-f> :copen<CR>:Ack -aQi --ignore-dir someignoringdir
to your .vimrc, after you can find in files through Ctrl+F, enjoy
_ /|
\'o.O'
=(___)=
U
You can try this
:vimgrep /something/ */
and dont forget to open search result window after
:cw
When using Vim, and given a directory filled with code (e.g. ~/trunk/) with a number of sub-directories, is there a way to grep/search for instances of text/regexes across the entire source code?
At the moment I use:
:lcd ~/trunk
:grep "pattern" *.py */*.py */*/*.py */*/*/*.py
(Obviously I'm limiting this to Python files, which is a different issue, but it's noteworthy that ideally I'd like to limit the searches to files with specific extensions.)
:vimgrep "pattern" ~/trunk/**/*.py
:copen 20
If you have quite a big project I'd recommend to you to use cscope and vim plugins. Here is one designed to handle big projects: SourceCodeObedience
There is a brief description of how to grep text using SourceCodeObedience.
I use grep directly for that.
grep -IirlZ "pattern" .|xargs -0 vim
-I: ignore binary
-i: ignore case
-r: recursive
-l: print file name only
-Z: print \0 after each file name
You may want to check out :vimgrep and :grep in the vim documentation. :vimgrep uses vim's own pattern searching functionality and reads all files into vim buffers. :grep by default links to an external grep utlity on your system, but you can change the behavior by setting the grepprg option. Here's a link to the online docs:
http://vimdoc.sourceforge.net/htmldoc/quickfix.html#grep
There's more info on that and also some other options in the tip on "Find in files within Vim" at the Vim Tips Wiki:
http://vim.wikia.com/wiki/Find_in_files_within_Vim
Set grepprg to Ack, then use :grep to search with Ack.
Or use ctags.
Ag is good option to search the pattern recursively.
https://github.com/rking/ag.vim
You could use :vimgrep i.e.:
:vimgrep /pattern/ **/*.py
Check this Vim Tip:
Find in files within Vim
Also give a look to grep.vim, it's a plugin that integrates the grep, fgrep, egrep, and agrep tools with Vim and allows you to search for a pattern in one or more files and jump
to them...
You can generate a source code index using ctags and then VIM can use this to navigate seamlessly through your code base. It's source code aware in that you can jump directly to method declarations etc.
You need to regenerate the ctags files every so often, but you can do that as part of your make process. It should be pretty fast unless your code base is sizeable.
Nobody's mentioned it, but I use tend nowadays to use ripgrep