Search in files and content in vim / neovim
TL/TR
👋 This post is about to how to easily find files and folders in a project with two plugins and a little configuration to improve your experience with them.
Note: The config file in vim is located in ~./vimrc
and the config file for neovim in ~/.config/nvim/init.vim
.
Find files in project
Use your favourite plugin manager to install the ctrlp plugin , I love to use Plug:
In case you don’t have any plugin manager install Plug following their repo installation guide.
I also add two custom configurations:
- Ignore folders in the search that are in the
.gitignore
(nobody wants to search insidenode_modules
🙃). - Show hidden files: I want to be able to search files like
.gitignore
,.env
and so on
Your config file should look something like this:
You should save your config file then type :so %
to reload it and then type :PlugInstall
to install the plugin.
Search inside a project’s content
To search content in a project I use the awesome ctrlsf plugin.
You need ack to use it so in case you dont have it its easy to install via hombrew by runing brew install ack
in your terminal.
Use your favourite plugin manager to install the ctrlsf plugin , I love to use Plug.
There are plenty of options in the docs but I find really useful what follows:
ctrl+f
andf
to open the search line and type what you want to search forctrl+f
andn
to search for matches of the word under the cursorctrl+f
andp
to search for the las search parten used in vim.
Finally your config file should look something like:
You should save your config file then type :so %
to reload it and then type :PlugInstall
to install the plugin.
Final thoughts
I work as a frontend developer so if your are interested in react snippets and some others feel free to check mines here 🙃.
You are ready to go and try it 🚀! I hope it helps and you found something useful here.
In case you liked it this is part of a serie of articles I wrote about useful vim configurations. If you are interested you can check the others here:
🍻