I have written a simple function to invoke edit command with a path followed by the given filename.
However it looks like edit l:path
invokes edit for file named "l:path"
instead of l:path
variable value. I guess this is a trivial issue, but it's hard to get search results for calling edit command in function, not from the vim editor.
Following code show the proper value of l:path when I change edit
to echon
.
command! -nargs=1 E call EditAtCurrentPath(<f-args>)
function! EditAtCurrentPath(filename)
let l:path=expand('%:p:h').'/'.a:filename
edit l:path
endfunction
You have to use :execute
to pass variables to commands:
execute 'edit' l:path
There are some good examples in :help :execute
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With