Skip to content

lukasx999/syncwd.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

syncwd.nvim

Sync Neovims working directory with the one of your shell

Normally when you start a Vim instance and navigate to another directory and exit Vim, you return to your shells CWD.

If you'd like your shells working directory to be directly synced to Neovims working directory, then this plugin does just that.
This plugin is very useful if your goal is to use a file manager such as oil.nvim as your primary file manager.



Install

Neovim Plugin (via Lazy.nvim)

return { "lukasx999/syncwd.nvim" }

Shell script

  • Save the changecwd.sh script to somewhere on your system (eg: ~/Scripts/syncwd/changecwd.sh)
  • Add this line to your shellrc (~/.bashrc, ~/.zshrc)
# ~/.bashrc

source path/to/changecwd.sh  # (source is a bashism)
# or:
. path/to/changecwd.sh

NOTE: if syncwd is enabled within Neovim, but you have not configured your shell yet, your shell will exit after quitting vim!



Usage

  • Start Vim
  • Exit Vim

NOTE: Whenever your cwd gets synced when exiting, you can always use popd or cd - to go back to the previous directory before the vim session



Configuration

return {
    "lukasx999/syncwd.nvim",
    config = function()

        require("syncwd").setup({
            init = true,  -- Should syncing be enabled on startup?
        })

    end,
}


Commands

  • :SyncwdEnable
  • :SyncwdDisable
  • :SyncwdToggle


API

local syncwd = require("syncwd")
syncwd.state()
syncwd.enable()
syncwd.disable()
syncwd.toggle()


How does this work???

Right before quitting Vim, a autocmd is fired, which will write the current working directory to a temporary file. (/tmp/syncwd_cwd)
Then it will get the PID of its parent process. (which is the shell that it was started from)
After that, a signal, SIGUSR1 (user defined signal) is sent to said pid.
The shell script, sourced in your shellrc then sets up a trap for said signal, which will then pushd into the cwd from /tmp/syncwd_cwd.

About

Sync neovim cwd with shell cwd

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published