Favorite folders for Neovim
Author: | Alex Vie |
Title: | Simple favorite folders feature for Nvim using Telescope and Neotree |
Language: | en-US |
Number of words: | 198 |
Created: | 16:43 on Friday, 30. December 2022 |
Modified: | 16:43 on Friday, 30. December 2022 |
Keywords: | neovim, lua |
Excerpt: | This is a simple way to implement favorite folders in Neovim. It makes use of the Telescope plugin and Neotree. Favorites are stored in a simple text file and presented with a fuzzy-searchable Telescope picker. |
Tags: | neovim |
Page layout: | no_sidebar |
One feature I was missing from the old NERDTree plugin was the ability to quickly define favorite folders. Since neither Neotree nor Nvim-Tree offer such a feature, I decided to add it my own. After all, it’s easily doable with only a few dozen lines of code, because the majority of the required functionality is provided by plugins.
Neotree can be passed a dir
parameter to change its current folder. So, basically, when you type
Neotree dir = /home/foobar
on the command line, the file-tree will change to this folder.
Requirements
- Neovim 0.8 or later
- The Telescope plugin and all its requirements.
- The Neotree plugin, otherwise the favorites folder feature would not make much sense at all.
Usage
Create your favorites as simple text file and save it to your Neovim configuration folder under the name
favs
(where init.vim
is normally located. The file is a simple format, one line per favorite and must
look like
Name|folder
example:
My Projects|~/Projects
Executing the lua function Neofavs()
will create a telescope picker with your favorites. Selecting one
will open the folder in Neotree. It’s best to bind the function to some key.
Code
This is hosted as a GitLab snippet. You can put this in your init.lua
or somewhere else and require
it
in init.