[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[For Linux beginners] Done! Edit and save with vi command

Hello!
This is Inoue, a Persian cat from Beyond Shikoku Office.

This time we will talk about the “vi” command for editing files!
There were so many options that it was difficult to verify.

What is the vi command?

is
a command that says "Start the editor!" First of all, "vi" refers to the text editor used in Unix-based OS.
At the same time, if the file does not exist in the directory, it will also create the file.
When I first joined the company, I was wondering, "What is an editor anyway?", but
it's easier to understand if you think of it as "Notepad" in Windows.

Create and edit a file using the vi command

First, use the vi command to specify the file name ``haruka'' in the ``test'' directory and edit it.

[code][root@test-aws-harukainoue test]# pwd /root/test[/code]
[root@test-aws-harukainoue test]# vi haruka

Executing the above command will move you to normal mode of "haruka".
At this time, no file has been created yet.

-rw------ 1 root root 12288 Jun 23 01:21 .haruka.swp

A SWAP file like this will be created temporarily.
is

a temporary recording file that is created when vi is opened and is automatically deleted after editing in vi to prevent the application from crashing and data being lost This prevents unsaved data from being lost even if vi is forcibly terminated due to a system error.
Therefore, the file "haruka" is created only when ":w" is executed.

If you want to edit the contents of a file in vi, press the i to enter
INSERT Once in insert mode, you can write it in the "haruka" file.
I'll write about it on my profile as well.

Akika Inoue (Persian cat)<font></font> Hobby: Cooking<font></font> Likes: strawberries and cats<font></font><font></font> <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">-- insert --[/code]</font></font></pre> While " <strong>-- INSERT --</strong> " is displayed, it is in insert mode. To exit edit mode, press the " <strong>Esc</strong> " key.<pre> <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[code]:wq[/code]</font></font></pre> When you write the content in the editor in insert mode and save it, a file called "haruka" is also created! The vi command allows you to type characters by switching from normal mode to insert mode. If an existing file is opened in vi, it will be overwritten and saved; if a new file is opened, a new file will be created.<pre> <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">[code][root@test-aws-harukainoue test]# ll</font></font><font></font> <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">Total 4</font></font><font></font> <font style="vertical-align: inherit;"><font style="vertical-align: inherit;">-rw-r--r-- 1 root root 83 June 21st 07:42 Haruka</font></font>

return to command mode with " : overwrite with wq add q to view the saved file and exit, or ! to forcefully exit vi For example, if you want to discard and exit without saving the changes edited with vi,

[code]:q![/code]

use.

Useful to know!

■Cursor movement commands
You can also use the arrow keys to move the cursor, but here are some useful cursor movement commands you should know.
*Be sure to press the "Esc" key and confirm that the editing mode is finished before executing.

0 (zero) Move the cursor to the beginning of the line where the cursor is.
$ Move the cursor to the end of the line where the cursor is located
Gugu Move the cursor to the beginning of the file.
G Move the cursor to the end of the file.
Mr. Move the cursor to the end of the file.

■Delete command

x or dl Delete character at current cursor position
DD Delete the line under the current cursor
d$ Delete from current cursor position to end of line
d0 Delete from the current cursor position to the beginning of the line
Dawa delete one word
dig delete up to first line
dG delete to last line


If you want to yank copy (yank), use y.
Use by specifying a cursor movement command after y.

Hi Yank the line at the current cursor position

Finally

I had a hard time writing about the vi command on my blog.
I thought I knew about the vi command, but I didn't.
The correct way to change the editor from edited insert mode to command mode and exit the editor.
In addition, I was wondering how to explain it in a way that a Linux beginner like me could understand...
After much trial and error, this blog was finally born! ! (`・ω・´)

I also have a blog that explains Linux in an easy-to-understand manner, so be sure to check it out!
https://beyondjapan.com/blog/2022/02/linux/

[Know this if you want to work for an IT company! ] What is Linux that you can't ask about now? (For beginners)

Growing every day, moving forward every day.
I have to update myself every day! ! !
Thank you for reading to the end.

If you found this article helpful , please give it a like!
28
Loading...
28 votes, average: 1.00 / 128
76,961
X facebook Hatena Bookmark pocket
[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Akika Inoue

Belongs to the System Solutions Department.
He joined Beyond as a founding member of the Shikoku office.
I jumped into the IT industry with no experience. As an education team, we create curriculum and conduct training for new graduates, mid-career, and existing members.
The main business is server operation and maintenance.
Either way, we value your content.
Also belongs to the Web Content Division and YouTube Team.