Vim edit a symlink
Asked Answered
D

1

5

I want to edit a file with (:e) which is a symlink and make vim follow it. I dont want this to be the default behavior or anything.

I know that using resolve and expand I can get full link.

:echo resolve(expand("~/.vimrc"))

prints the full link.

I want to be able to do something like this

:e resolve(expand("~/.vimrc"))

Note: I want it to follow the symlink because of context, like quickly editing other files in that folder and stuff like that.

Dromedary answered 8/8, 2013 at 12:58 Comment(0)
M
7

You can insert any Vimscript expression into the command-line via <C-r> and the expression register =:

:e <C-r>=resolve(expand("~/.vimrc"))<CR><CR>

Alternatively, for files, there's the rather obscure backtick expansion of Vimscript:

:e `=resolve(expand("~/.vimrc"))`<CR>
Maryellen answered 8/8, 2013 at 13:10 Comment(2)
exactly what I need. curiously it does not work in when i type it as a command in the editor. However when i mapped it to something in my vimrc it worksDromedary
I've used the mapping syntax; of course, you need to press Ctrl + R instead of <C-r> and Enter instead of <CR>!Maryellen

© 2022 - 2024 — McMap. All rights reserved.