How do you open a file from within Vim?

亡梦爱人 提交于 2019-12-03 14:51:07

问题


I know how to open a file in vim from a terminal command line (vim fileName). What I can't figure out is how to open a file when I'm already within Vim. I tried :r fileName, but that appears to read (or append) the file into the unsaved buffer I have open. It creates a new file, because when I try to write it with :w, it asks for a filename.


回答1:


:e <filename>

or

:Ex <directory>

lets you browse for the file from the given directory.

:Ex on its own will open the pwd.

:enew

will create an empty buffer.




回答2:


this vim command you won't forget:

:Sex

if you want to point to certain dir, then :Sex <dir>




回答3:


Also, to open multiple files (or just one, so I tend to use this for opening a single file, since :e fails to open multiple files)

:n file1 file2

:n resets the argument list so it is as if you had entered them on the command line (so commands like :rew will work with this list), but :e does not.



来源:https://stackoverflow.com/questions/23680778/how-do-you-open-a-file-from-within-vim

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!