GithubHelp home page GithubHelp logo

autocd.vim's Introduction

Autocd.vim

A cwd management tool for vim. Keep your cwd in sync with your workflow so that functions, plugins, and external commands can utilize getcwd() as a reliable current project directory.

Features

  • Highly configurable current directory setter.
  • NERDTree integration. Keep NERDTree in sync with the output of this command.

Installation

TEST

Use the plugin manager of your choice to install. Example using dein. If using NERDTree integration and vim-devicons, this plugin must be sourced after vim-devicons to prevent conflict.

call dein#add('paroxayte/autocd.vim')

Configuration

Below are some configuration examples. For a full list of configuration options see :help autocd.vim-configuration

Markers

Autocd works by processing various triggers each associated with a mark. When a trigger goes off, autocd searches up the directory heiarchy looking for a specified marker. For instance if creating a java project with maven there will be a pom.xml in the project root. To automatically change to the root of a maven java project with :Autocd

let g:autocd#markers = {
\  '*.java': ['pom.xml']
\}

To automatically cd to project root of vscode, eclipse, or git projects.

let g:autocd#markers = {
\   '*user/Dev*': ['.project', '.vscode', '.git']
\}

To create special rules for a specific file, the file's full path can be used with g:autocd#markers.

let g:autocd#markers = {
\   '/path/to/file': ['some_marker']
\}

Default

If search for markers fail, a default action can be preformed. To enable this g:autocd#markers_default = 1 must be set. By default, the behavior is the same as autochdir, switching to the current file's containing directory. To modify this behavior g:autocd#makers_get_default() may be overridden. The function is expected to return a string representing the desired directory, or a integer to represent failure. For more information see :help g:autocd#makers_get_default()

NERDTree Sync

To enable NERDTree synchronization g:autocd#nts_enable = 1 must be set at startup. Alternatively the functions autocd#nts_enable() and autocd#nts_disable() may be called to change the state of this feature post startup.

Commands & Autocommands

The sole command of Autocd is :Autocd. To run :Autocd automatically on BufEnter g:autocd#autocmd_enable = 1 must be set on startup.

Example Configuration

let g:autocd#nts_enable = 1
let g:autocd#autocmd_enable = 1
let g:autocd#markers_default = 1
let g:autocd#markers = {
\   '*.java' : ['pom.xml'],
\   '*/user/Dev/*': ['.project', '.vscode', '.git'],
\}

More Information

For more information see :help autocd.vim

Issues

See contributing.

Self Promotion

If this plugin is useful, give the repo a star!

autocd.vim's People

Contributors

fireflowerr avatar tdct12 avatar ascandella avatar

Stargazers

Daniel Fernandes avatar Shanghe Chen avatar Norton avatar  avatar Seth Messer avatar JamesLinus avatar Klas Segeljakt avatar ik5 avatar  avatar  avatar

Forkers

qianwch

autocd.vim's Issues

Can't get `markers_path` to work

I just installed your plugin (been looking for something exactly like this, thanks!). I've got markers_filetype to work how I expect it. However, I'd also like the plugin to set the current directory if I ever open a file whose parent directory contains a .git folder (e.g. is a git repo).

I've tried various permutations of setting g:autocd#markers_path but it doesn't seem to be working. Example:

cat ~/.vim/init/autocd.vim
let g:autocd#autocmd_enable = 1

let g:autocd#markers_filetype = {
      \ 'python': ['requirements.txt', 'setup.py'],
      \ 'rust': ['Cargo.toml'],
      \ }

let g:autocd#markers_path = {
      \ '/home/aiden': ['.git'],
      \ 'home/aiden/src': ['.git'],
      \ }
vim /home/aiden/src/bspwm/src/stack.c

Then call :pwd and it returns /home/aiden

ls -f /home/aiden/src/bspwm/.git
.   branches  info         refs     packed-refs  config  index
..  hooks     description  objects  logs         HEAD

However, if I open a rust project (with a Cargo.toml) file, it works fine.

I tried reading through the plugin source but don't know how to debug vim script. I'm guessing the sub-path detection isn't working properly, or I'm setting the configuration variable wrong.

What do you think?

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.