๐ My name's Aymeric, I'm a Software Engineer living in Paris, France.
๐ญ I have a keen interest in Rust. I also like Go.
โ๏ธ I sometime write on my blog.
:running: Automagically follow symlinks
License: MIT License
apologies for the vague title. this happens with neovim on ubuntu 20.04 when opening files from the command line, or from inside vim (:e
). i ran into this issue when using rust.vim which doesn't autosave formatted code correctly when the file path is still a symlink.
example:
mkdir test
echo "hello" > test/hello.txt
mkdir test2 && cd test2
ln -s ../test
vim test/hello.txt
:files
will show:
1 %a "test/hello.txt" line 1
.. which is still a symlink.
the problem seems to be:
autocmd BufRead * nested call s:on_buf_read(expand('<afile>'))
once i changed it to:
autocmd BufRead * nested call s:on_buf_read(expand('%'))
it expands correctly:
2 %a "../test/hello.txt" line 1
For example, if you keep your configuration files such as .bashrc in a Git repository and symlink ~/.bashrc -> ~/dotfiles/.bashrc, plugins like vim-fugitive will not realize the file is under version control as there's no ~/.git. But if you use this plugin, vim ~/.bashrc will edit ~/dotfiles/.bashrc instead, and you will be able to use vim-fugitive.
This means that if you edit a pathname that is a symlink, vim will instead open the file using the resolved target path.
Consider the following minimal vimrc file (vimrc_min
) which lives in a folder that is symlinked to $HOME/.config/nvim
:
let $DOTVIM = expand('$HOME/.config/nvim')
"set runtimepath+=$DOTVIM/bundle/repos/github.com/aymericbeaumet/vim-symlink
nnoremap ,em :e $DOTVIM/vimrc_min<CR>
augroup session
au!
au BufWinLeave vimrc_min mkview
au BufWinEnter vimrc_min silent! loadview
augroup END
Now, as in the GIF, do
nvim -u vimrc_min
(so as to load the minimal vimrc file configuration),em
to open/edit the symlinked filevim-symlink
plugin is disabled then the actual symlinked file is opened:q
nvim -u vimrc_min
and press once again ,em
to load the symlinked fileNow uncomment the set runtimepath
line so as to enable vim-symlink
plugin and repeat steps above (in 3. you'll obviously noticed that the original/target file is opened now instead of the symlink). After 6. you'll see that cursor position is not restored to the previous position but it's instead in the first line of the buffer. I naturally expect it to be restored to the "saved" position
Thanks for your work on symlink. Probably worth pointing out this doesn't seem to work with vimdiff
or vim -d
(which is equivalent). Ordinarily, these commands make vim open with two or more panes for the files being compared, but with the symlink.vim
plugin in place, only one pane is shown.
I currently work around this with:
if ! &diff
" Does not work correctly with diff mode
Plug 'aymericbeaumet/symlink.vim'
endif
(I use vim-plug)
However, this is not ideal. Ideally symlink.vim
would either do this check itself, or even better, resolve the symlinks and continue to work in diff mode.
Thanks very much for your great work on this plugin!
Hi, this plugin has been working for me perfectly for some years (so much that I had forgotten I had it installed :) ). But I think that the latest version of neovim introduced a problem:
Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /usr/share/nvim/runtime/lua/editorconfig.lua:210: Invalid buffer id: 1
stack traceback:
[C]: in function 'nvim_buf_get_name'
/usr/share/nvim/runtime/lua/editorconfig.lua:210: in function 'config'
/usr/share/nvim/runtime/plugin/editorconfig.lua:11: in function </usr/share/nvim/runtime/plugin/editorconfig.lua:4>
Do you think this is a problem with neovim or with vim-symlink? Do you think that this can be fixed easily? I tried today for a while, but I am not sure where the problem might be.
Hi,
I'd like to request a feature: can we disable / enable symlink following? I want to follow some symlinks but not others. The current behavior is to automatically follow all symlinks.
Thanks for all your hard work on this great plugin! Unfortunately, I've found an annoying corner case which I've hit which affects my usage of help files.
Recreation steps:
Use Neovim 0.4.3 (I suspect this will happen with other versions and regular Vim also, but I haven't tested).
Remove ~/.config/nvim
if exists. Create a directory elsewhere (e.g. /tmp/test
and symlink - cd ~/.config && ln -s /tmp/test nvim
.
Copy the contents of this file into ~/.config/nvim
as init.vim
:
echom system('git clone https://github.com/kristijanhusak/vim-packager ' . $HOME . '/.config/nvim/pack/packager/opt/vim-packager')
packadd vim-packager
call packager#init()
call packager#add('kristijanhusak/vim-packager', { 'type': 'opt' })
call packager#add('moll/vim-bbye') " needed for vim-symlink
call packager#add('junegunn/fzf', { 'do': './install --bin' })
call packager#add('junegunn/fzf.vim')
call packager#add('aymericbeaumet/vim-symlink')
call packager#install()
Load neovim and wait for package installation to complete. Quit and restart. Ignore error about existing directory, I don't think it's relevant.
Type :help fzf
. Expect that help loads. Instead see errors like this:
Error detected while processing function <SNR>29_on_buf_read[11]..<SNR>28_bdelete:
line 27:
E218: autocommand nesting too deep
E218: autocommand nesting too deep
E218: autocommand nesting too deep
Error detected while processing function <SNR>29_on_buf_read:
line 11:
E171: Missing :endif
Some observations:
I have created the above minimal setup to provide easier recreation; this happens with my full Neovim init.vim and other config also (I know the symlink is a bit unusual but I keep my config under source control so have symlinked it to elsewhere). I don't think it's that uncommon ;)
I don't think the fact that it's FZF is relevant; it appears this happens with any help file installed in ~/.config/nvim/pack
.
It does not happen if ~/.config/nvim
is not a symlink; if it's a regular directory the help is loaded as expected.
If you remove vim-bbye
from the recreation init.vim
, the help loads. However, this prevents vim -o
working correctly with multiple files; only one window is opened.
Hi!
First I want to say thank you for this really helpful plugin (especially when combined with vim-fugitive
).
When I search something recursively in Neovim 0.9.2 via the command
:vim /PATTERN/ /path/to/a/symlinked/dir/**/*
I get many E937: Attempt to delete a buffer that is in use: /some/path
error messages.
When I uninstall vim-symlink
the same command runs just fine and very quick.
BTW:
Installing the optional dependency moll/vim-bbye
does also help. At the same time I'd be happy to avoid installing an additional plugin.
I created a Dockerfile with which one can easily reproduce the error.
To build the Docker image place a file named Dockerfile
in some temp directory and run
docker build -t bug .
in that directory.
To run the Docker container run docker run --rm -it bug
afterwards.
FROM fedora:38
RUN dnf install -y git neovim
RUN mkdir -p $HOME/.config/nvim/lua
RUN echo 'lua require("init")' > $HOME/.config/nvim/init.vim
RUN echo -e 'return {{"aymericbeaumet/vim-symlink"}}' > $HOME/.config/nvim/lua/plugins.lua
RUN echo -e '\
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"\n\
if not vim.loop.fs_stat(lazypath) then\n \
vim.fn.system({\n \
"git",\n \
"clone",\n \
"--filter=blob:none",\n \
"https://github.com/folke/lazy.nvim.git",\n \
"--branch=stable", -- latest stable release\n \
lazypath,\n \
})\n \
end\n \
vim.opt.rtp:prepend(lazypath)\n \
require("plugins")\n \
require("lazy").setup("plugins", {\n \
ui = {\n \
border = "rounded",\n \
size = { width = 0.6, height = 0.9 },\n \
}\n \
})\n' > $HOME/.config/nvim/lua/init.lua
RUN nvim --headless -c'Lazy sync' -c'q'
RUN ln -s /usr/share $HOME
CMD nvim -c'vim /PATTERN/ $HOME/share/**/*'
When the optional dependency moll/vim-bbye
is being added (4th RUN
statement below) the search runs without any error:
FROM fedora:38
RUN dnf install -y git neovim
RUN mkdir -p $HOME/.config/nvim/lua
RUN echo 'lua require("init")' > $HOME/.config/nvim/init.vim
RUN echo -e 'return {{"aymericbeaumet/vim-symlink", dependencies = {"moll/vim-bbye"}}}' > $HOME/.config/nvim/lua/plugins.lua
RUN echo -e '\
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"\n\
if not vim.loop.fs_stat(lazypath) then\n \
vim.fn.system({\n \
"git",\n \
"clone",\n \
"--filter=blob:none",\n \
"https://github.com/folke/lazy.nvim.git",\n \
"--branch=stable", -- latest stable release\n \
lazypath,\n \
})\n \
end\n \
vim.opt.rtp:prepend(lazypath)\n \
require("plugins")\n \
require("lazy").setup("plugins", {\n \
ui = {\n \
border = "rounded",\n \
size = { width = 0.6, height = 0.9 },\n \
}\n \
})\n' > $HOME/.config/nvim/lua/init.lua
RUN nvim --headless -c'Lazy sync' -c'q'
RUN ln -s /usr/share $HOME
CMD nvim -c'vim /PATTERN/ $HOME/share/**/*'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.