Last active
April 21, 2018 10:24
-
-
Save DrSpeedy/9022d3bee63a7029570c7d3d43054329 to your computer and use it in GitHub Desktop.
Automatically change working directories in NeoVim via the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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