I am using linux.
In terminal I can type
vim sample
A vim window for the file 'sample' opens
Here any change can be saved with :w
But I want to open a new vim file having no name and save it with the name sampleName using
:w sampleName
But I am unable to do so.
Typing only vim in terminal gives me a window with about and copyright information
I am not using gvim
but vim
You should be able to just run vim
with no arguments. It will open vim by itself. To save it to a file, execute the command: :w <new file name>
Issue the Command, :enew
and Also Learn about How Vim Manages File Editing
I would recommend reading up on file and buffer usage in Vim in the help file, usr_22.txt.
As architrex has indicated, by default, if one does not have a file(s) listed in the argument list when starting Vim, a new buffer is created. See :help starting
.
If you started vim with one file in the file argument list like you described, vim sample
, a common way to work with an empty buffer is to issue the :enew
command (typically after you would have written changes to the file named, sample, :w
).
We can see the new buffer here:
Once one is done modifying the new buffer, you can issue the write command, :w sampleName
, with the expected result of writing the file.
Vim's use of buffers is intuitive and you will become more skillful as you use it.
When I started using Vim, I leveraged using NETRW which is a seeded file navigation plugin with Vim for file creation (and placing those new files in buffers).
What follows is one way to leverage NETRW to do this.
If you have already started Vim, I would type :Exp
or :e.
which are ex commands which will start the file explorer which is a feature of the seeded file navigation plugin, NETRW.
One could start Vim:
Start the file explorer for NETRW:
I would then use the file explorer to navigate to the desired file to create a new file you wish to edit ( k
is up, j
is down, enter key means select).
Next, I would type, %
, once I have navigated to the desired location.
You will be notified to "Enter filename". Just enter "sampleName" and press enter.
Go into edit mode (eg i
) and start typing.
NETRW is a robust file navigation tool. Creating files in the file locations desired is an essential skill to have to utilize Vim well.
You could also read the help files concerning NETRW (eg the ex command, :help netrw
).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.