Skip to content

Instantly share code, notes, and snippets.

@DrSpeedy
Last active April 21, 2018 10:24
Show Gist options
  • Save DrSpeedy/9022d3bee63a7029570c7d3d43054329 to your computer and use it in GitHub Desktop.
Save DrSpeedy/9022d3bee63a7029570c7d3d43054329 to your computer and use it in GitHub Desktop.
Automatically change working directories in NeoVim via the terminal
# This function calls the script below when loaded by
# the shell inside of neovim. It must be placed somewhere in
# your default shell's rc file e.g. ~/.zshrc
neovim_autocd() {
[[ $NVIM_LISTEN_ADDRESS ]] && neovim-autocd.py
}
chpwd_functions+=( neovim_autocd )
#!/usr/bin/env python
# Automatically change neovim's working directory via
# the built in terminal.
#
# Full neovim configuration:
# https://github.com/DrSpeedy/nvimrc
#
# Original issue thread:
# https://github.com/neovim/neovim/issues/3294
import neovim
import os
nvim = neovim.attach('socket', path=os.environ['NVIM_LISTEN_ADDRESS'])
nvim.vars['__autocd_cwd'] = os.getcwd()
nvim.command('execute "lcd" fnameescape(g:__autocd_cwd)')
del nvim.vars['__autocd_cwd']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment