Is there a function that can be called to open a file for editing? I know how to open and edit files in Vim, and I know I can use :e filename
, but is there a built in function I can call that does this?
If a function exists that does this, there probably is a reason for it to exist in addition to the :e
command and knowing about its existence and what it is called would enable me to look at it in the help and see the purpose of its existence.
One problem with using :e filepath
is it gets confused when there are spaces in the path. I tried surrounding the path in quotes, and this allows the command to run without error. But then I can't save, as it seems to think the file is inside a non-existent directory. If I escaped the spaces with a \
character, it works when the command is run directly, but it is causing problems inside a plugin test of mine. I haven't figured out a good way to ask for help with that exact problem yet, so I want to keep this question focused on how to consistently open a path for editing regardless of what characters may be in it. A built in function to do this would be nice, but now I see making my own would be good as well.
e filename
in the script. If you really need it for some reason you can write it a custom function that takes an argument called file and then callse a:file
.:h fnameescape()
can help, e.g. the example found right there::exe "edit" . fnameescape(fname)
may be what you are after.:h function-list
to see what (more) functions are available - they may further simplify your code.