Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open VIM [no name] file from terminal

Tags:

terminal

vim

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

like image 757
Suraj Avatar asked Sep 02 '25 02:09

Suraj


2 Answers

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>

like image 84
architrex Avatar answered Sep 04 '25 16:09

architrex


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

like image 42
Patrick Bacon Avatar answered Sep 04 '25 14:09

Patrick Bacon