Code Monkey home page Code Monkey logo

neoroot.lua's Introduction

NeoRoot.lua

This project is now deprecated

Changing your project root (i.e. global current-directory, see :h current-directory) just for grepping files, showing less files on your file tree is not a good practice. If you once did this, you misused Vim. (To achieve the same result, you should always call :tcd instead.)

Besides this, I will recommend you trying my new project session plugin: https://github.com/nyngwang/suave.lua, which follows this good practice:

Never touch the global current-directory unless you want to change to another project.

and it's designed to help you restore your project with ease. (Now supports restoring colorscheme, too)

DEMO

demo.mov

New Intro. (updated 2022/04/19)

With NeoRoot.lua, you will be able to:

  • Before starting NeoVim, first navigate to your project root(can be modified later)
  • Run nvim . to start your NeoVim. Now NeoRoot will enter proj-mode(see below) with the path you run nvim . as the root
  • During development, you can temporarily change the cwd to your current buffer.
  • During development, you can temporarily re-define your project root. For example: ~/.config. (shorthand ~, ../s are supported!
    • if you want to change back to ../somewhere/MyProj/, just leave the prompt blank and hit Enter. Simple!

Old Promo.

Now you won't have a hard time :cd to the right place to see more files before executing commands that takes your current working directory into account (i.e. you need to go up some levels to make tools like rg/fd to "see" more files). You can also change your project root in the runtime, without typing any command, anymore!

Features

  • No dependencies
  • No requirements
  • free
  • Light-weight, ~100 lines

Compatibility

Setup

Packer.nvim

local NOREF_NOERR_TRUNC = { noremap = true, silent = true, nowait = true }
use {
  'nyngwang/NeoRoot.lua',
  config = function()
    require('neo-root').setup {
      CUR_MODE = 2 -- 1 for file/buffer mode, 2 for proj-mode
    }
  end
}
vim.cmd'au BufEnter * NeoRoot'
vim.keymap.set('n', '<Leader>p', function() vim.cmd('NeoRootSwitchMode') end, NOREF_NOERR_TRUNC)
vim.keymap.set('n', '<Leader>pre', function() vim.cmd('NeoRootChange') end, NOREF_NOERR_TRUNC)

Hint

To see your current working directory, simply call NeoRootSwitchMode twice.

TODO list

  • Add installation guide in README.md
    • packer.nvim
  • Customizable
    • keymappings
    • ignore list

neoroot.lua's People

Contributors

nyngwang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

neoroot.lua's Issues

Bug report: `NeoRootChange` got rekt on `./`-prefixed path

At acbc8cd, if you try NeoRootChange to go down to a child folder, this plugin will get rekt.

For example, this won't work: (pre is equivalent to run command NeoRootChange, you might set your own keymapping)

pre ./child_folder

while these will be fine:

pre ~/.config
pre ../foo/bar

Adding vim.LSP integration

vim.lsp.buf..list_workspace_folders()[1] returns nil if no LSP root is set and else the root directory.
May this can be used if NeoRootChangeDirectory gets an empty string, I find after multiple days of testing that this is a nice default.

Breaking Change: Do one thing well

As title. Maybe we don't need one of the current features that NeoRoot will elevate the pwd three levels up. NeoRoot should be a toggle:

  • When enabled, the pwd will be changed to the path of the parent folder of your current buffer.
  • When disabled, the pwd will be changed back to your project path.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.