Skip to content

Sets the working directory of neovim based on nvim-lspconfig

Notifications You must be signed in to change notification settings

oberblastmeister/rooter.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 

Repository files navigation

rooter.nvim

rooter.nvim sets the working directory of neovim based on root patterns. Heavily inspired by vim-rooter except writen in lua and uses nvim-lspconfig to find the root directory.

Pros

  • Uses the same root patterns as language servers if using nvim-lspconfig
  • written in lua
  • fast

Installation

If using vim-plug:

Plug 'oberblastmeister/rooter.nvim'

Packer.nvim:

use 'oberblastmeister/rooter.nvim'

Configuration

Note: the configuration is written in lua, not vimscript

Initialize with default values and setup autocommand:

require'rooter'.setup()

To use different configuration values, call rooter.setup(cfg), to override default values

Example:

-- these are all of the default values
require'rooter'.setup {
    manual = false, -- weather to setup autocommand to root every time a file is opened
    echo = true, -- echo every time rooter is triggered
    patterns = { -- the patterns to find
      '.git',    -- same as patterns passed to nvim_lsp.util.root_pattern(patterns...)
      'Cargo.toml',
      'go.mod',
    },
    cd_command = 'lcd', -- the cd command to use, possible values are 'lcd', 'cd', and 'tcd'
    -- what to do when the rooter pattern is not found
    -- if this is 'current', will cd to the parent directory of current file
    -- if this is 'home', will cd to the home directory
    -- if this is 'none', will not do anything
    non_project_files = 'current',

    -- the start path to pass to nvim_lsp.util.root_pattern(patterns...)
    start_path = function()
      return vim.fn.expand [[%:p:h]]
    end,
}

You can also root manually. You can do :Root which is a wrapper around :lua require'rooter'.root()

About

Sets the working directory of neovim based on nvim-lspconfig

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published