4

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

2 Answers 2

12

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>

Sign up to request clarification or add additional context in comments.

5 Comments

But using vim with no arguments
Does not open vim. It simply opens about and copyright window
:q to go back to terminal
That's vim's splash screen. You can start editing the file by going into insert mode: i, editing as you would a normal file, and then save the file with: :w <new file name>
Thanks that splash screen was reason for all of my confusion. My question is quite wayward from what I want ask. Please edit my question if you find time.
5

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).

enter image description here

We can see the new buffer here: enter image description 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:

enter image description here

Start the file explorer for NETRW:

enter image description here

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).

enter image description here

Next, I would type,%, once I have navigated to the desired location.

enter image description here

You will be notified to "Enter filename". Just enter "sampleName" and press enter.

enter image description here

Go into edit mode (e.g. i) and start typing.

enter image description here

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 (e.g. the ex command, :help netrw).

1 Comment

You are not getting what I am asking from. I am in terminal. From here I want to open vim document having no name. Now I want to name it using :w sampleName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.