How to edit files from your Linux VPS terminal

There is a constant need to read, edit and edit text files on any VPS, mainly after installing new packages. Learning, practicing and acquiring skills with command line text editors can mean a world of difference in your experience and results with VPS.

If your server encounters a problem, the only resource will be access to the system console and the only way to use it will be via a text editor. Vi or his descendant, Vim, are the only ones to have the guarantee to exist everywhere. In this tutorial, we will study nano and Vim, two popular text editors that you can run from a VPS terminal.

Vi editor

A problem for most newcomers in VPS is that vi, the only text editor present by default on all Linux distributions, is neither WYSISWYG nor intuitive. If you expect it to obey the commands of Windows Notepad or MacOS TextEdit editors, you will be frustrated and disappointed in no time. Let's say you follow a script to install a widely used program, says Nginx, and that it contains a command such as

sudo vim /etc/nginx/nginx.conf

If this is your first contact with viyou will discover that

A) you can not type in the editor (unless you accidentally tap I on the keyboard) and that

B) you do not know how to save the file and leave the editor (until you know that : wq will do the trick).

Vim Editor

Over time, an improvement in vi called vim, has become very popular with users with power. It's a super-tight set of vi but with dozens of additional features, such as protocols, plugins, task automation, working with multiple files at once, using its VimScript internal language, or more formal Python, Ruby, Perl, or Tcl protocols, and so on.

Vim is hard to learn completely, but it is worth it.

Nano Editor

The problems that newcomers have with Vi / Vim are why another publisher, nano, is so popular. It will display the commands available as a menu on the screen and, when you start typing, you will see text fill up. It is therefore not surprising that many users do their first tasks after installing a "droplet", an "instance" or a "server" on. their VPS boxes, will install nano.

What we are going to cover

For nano and Vi / Vim, we will show how:

  • Install the editor on Debian / Ubuntu and Centos
  • Explain the philosophical approach to publishing
  • Get help
  • Create a new file or open an existing file
  • View important orders in the editor
  • Save the file and exit


  • Debian / Ubuntu or Centos systems
  • SSH capability on the server
  • Since Vim is a superset of Vi, we will focus on Vim only.

Installing Publishers on Ubuntu 16.04 and Debian 9

Vi should be present on all servers, however, on some, it can actually envy Vim. We show commands for installation on all systems because there may be differences between the hosting providers and the server versions provided.

First update and upgrade of the current version of Ubuntu / Debian:

sudo apt update
sudo apt upgrade

Depending on the version of Debian, the sudo This command may not be recognized immediately after the server installation. If this is the case, simply omit sudo some orders.

On Ubuntu only, if you get the following prompt:

just press the Tab key on the keyboard, then press Enter.

You can then install the updates, if any:

sudo apt dist-upgrade 

Then install Nano:

sudo apt install nano

We see that it is already installed on Ubuntu 16.04:

Now, let's install Vim:

sudo apt install vim

It is also preinstalled.

Publisher installation on Centos 7

Orders are:

sudo yum update
sudo yum install nano
sudo yum installs vim

How to start the editor

To start an editor, you invoke it by name at the command prompt. If you add a file name, two things can happen. If there is no file at this address, the editor creates an empty file and, if it exists, it is opened in the editor.


When to use Nano

This is the ideal case for using nano: you are (relatively) new to VPS servers, but you have just acquired one to be able to run a specific program on it, or a few sites. So, you search and find a good recipe to install the software of your choice, you follow and you reach a time when a configuration file needs to be changed. Nano is an ideal editor for such small, quick, dirty jobs, in which you add a line or two, for example, change the site name for Nginx, etc., and then save and close the file.

Now move to a neutral folder such as / tmp and open a file called sometext.txt in:

cd / tmp
nano sometext.txt

We can start typing the new text immediately or paste a text that we already have on the clipboard. If it is a Windows terminal window (such as Kitty or Putty), you will paste text with the right mouse click and if it is under MacOS, a simple Cmd- V should suffice.

I've copied the paragraph above and here's what I've got:

The text is all in but you only see its end. By default, Nano does not package text because it is the expected behavior when you edit configuration files. To switch to wrapped text, press Esc, release it, then press $:

It was a flexible packaging, the rigid packaging is activated or deactivated with Esc + The.

The usual way to issue nano commands is to use the Ctrl key plus a letter, indicated by ^ G – meaning to press Ctrl then the key close g while holding Ctrl. In menus, nano uses capital letters g so it looks like you have to press the shift key and then g but in reality, you do not have to press Shift at all.

Instead of Esc followed by a touch, you can also use the key Alt by simultaneously pressing a key. If difficult, we should press Alt, holding it, then pressing shift, holding it, then pressing l. In general, Alt and Esc are called meta keys and – depending on your keyboard – this role can be assigned to another key.

Help screen in nano

Ctrl-G will show you the main text of the nano help:

Scroll with combinations of ^ Y and ^ V or, if you are using a normal PC / Mac keyboard, simply use PageUp and Footer key. You can also scroll with the cursor keys, from top to bottom.

We will now study a little more keyboard combinations:

Commands starting with M, for example, M- (, call to press the Meta key which, as we have already seen, can be Esc, Alt or something else. So you can go to the beginning of the paragraph by pressing Esc, release the pressure, then press shift and 9 at the same time. Or you can press Alt, press and hold, press shift, hold down both keys and press 9.

to push on Ctrl-X leave the screen help.

Save a file with nano

To save a file with nano, use Ctrl-O. The menu at the bottom becomes:

To save the file with changes, simply press Enter.

Pressing Ctrl-X leave nano if the file is saved; otherwise, you will be asked to confirm Y.

In the main menu, we see that Ctrl-W find the text, _Ctrl-_ is for the replacement operation and so on.

Vim Editor

Learn Vim with Vimtutor

The best way to learn Vim is to start a special version of Vim called vimtutor:


You are immediately in Vim and in its "normal" mode. This means that the keyboard keys will not enter text but will be interpreted as interactive commands. To move the cursor, press the keys h, j, k, and l. Pressing jfor example, move the cursor one line below. Continue to press j until you see the second screen vimtutor:

and then proceed from there.

Run Vim

Start the next command


and you will get this window:

It's easy to create or open a file with Vim:

vim anothertext.txt

Three modes of operation in Vim

Vim has several modes of operation, but these three are the most important:

  • NORMAL MODE – sliders, moving text, text buffers, text manipulation, etc.
  • INSERT MODE – text insertion: input and editing.
  • VISUAL MODE – a mode in which larger blocks of text can be defined, cut, pasted, etc.

press Esc twice to return to normal mode.


If you want to type text, press I in normal mode to turn on the Insert fashion. You will see the word – INSERT – in the lower left corner of the window and you can enter text.

In insert mode, I copied the paragraph above and clicked with the right mouse button – the text appeared in the Vim editor.

The command mode in Vim

You start issuing commands by typing two dots. For example, type : h for help, the following help screen will appear:

Type : q to return to the screen with the text.

To exit the file and exit the editor, enter:

: X[return]

To exit vim without saving the file, enter:

: q![return]

Here are the basic commands:

  • save: : w
  • save and leave: : wq
  • exit: : q
  • Obligate: ! (Example : w! : q!)
  • copy: there
  • copy a line: yy
  • paste: p
  • Cut: re
  • to cut a line: not a word

By typing a number in front of the command, this command will be executed as many times as necessary. It means that if w is a command to move the cursor to the beginning of the next word, 15w will move the cursor 15 words to the right.


Typing V in normal mode will activate the visual mode.

Note the label VISUAL LINE in the lower left corner of the terminal window.

In this mode, pressing keys such as j and k will move the cursor up and down, but will also mark a block of white text. Since we pressed V, the entire lines with the cursor will be marked. press v to allow the visual selection of text based on characters, in which case the lower left corner will only show the word VISUAL.

Now, to delete some text, press re (delete) and press there (copy) to copy the marked region. Then move the cursor to the desired paste location; pressing p will then stick after the cursor, while P will stick in front of her.

press c to change text … and for the following commands, be sure to devote more time than expected to learning Vim!

What can you do next?

We showed the basic editing capabilities of two almost universal text editors, nano and vi or vim. They may not be your cup of tea at all, but you should at least know enough about Vi / Vim to read a file, edit it and save it. Other famous publishers for which we have no room for maneuver include Emacs, Micro, NE, and many more to choose from for your VPS!

Dusko Savic is a technical writer and programmer.

Nearly terminal object

Is there an integer $ n> $ 2 so that there is an integral schema such that it exists exactly $ n $ distinct morphisms from any separate integral Noetherian scheme?

Color problem in the terminal (Mojave)

I use macOS Mojave 10.14.5 and I am having color problems when accessing a CentOS workstation.

Initially, after connecting via ssh, I would like to get the following welcome message:

enter the description of the image here

Then I added the following commands to the bash file:

export LC_CTYPE = en_US.UTF-8
export LC_ALL = en_US.UTF-8

and I commented on the following line / etc / ssh / ssh_config:

# SendEnv LANG LC_ *

After all this, the welcome message I receive is error free but still distorted:

enter the description of the image here

What I should get is the following (I got it with iTerm2 3.2.9):

enter the description of the image here

How can I fix the colors?

Linux terminal size

How can you determine the number of lines in the Linux terminal (currently open)?
And at this value assign a variable so that you can use it in a function. Thank you

I installed lubuntu desktop through the terminal but my laptop always reboots with Ubuntu

However, when I turn it off, the lubuntu logo appears. When I turn it on, it's back to Ubuntu

terminal – command cp: Overwrite the confirmation with the diff file

When running cp To copy files, I would like to receive a replacement confirmation and, if possible, display the confirmation file as confirmation.

Is it possible? and if yes, how?

Ideal example:

$ cp file1.txt file2.txt
> 1.
> 2.
> 3.
Replace file2.txt? [Yes/No/Keep both] (Y by default): 

terminal – What is the directory "ls" in my home directory?

This directory "ls" is not standard on Mac, so it's something that you or another Mac user has created (directly or indirectly by being created by a third party program).

This has nothing to do with the ls order. However, this could have been done reasonably by someone in the middle of a mkdir order thinking that they should just list the directory first – then run by mistake mkdir ls.

By the way, the "/ Users / xxxx" directory is not called the "root" directory, but rather the user's home directory.

applescript – Automatically open a terminal window and launch a command, robustly

I am looking for a way to automatically open a new window and execute a command there.

I had used to do that with AppleScript, in a way similar to this one:

tell the application "Terminal"
make a script ("an-order")
end say

Julia's official distribution opens the terminal windows in the same way.

However, if is configured to run a command at startup (a convenient method often recommended for defining a new shell without changing the login shell globally), this method simply fails.

Is there a robust method that works even when an alternative shell is used?

enter the description of the image here

Mathematica 11 in Ubuntu 18.04 does not display many characters in the terminal. How can I change that?

The "special" character, such as pi (esc p esc), does not appear. Instead, they are replaced by a dashed gray square:
enter the description of the image here

How can I change that? Mathematica worked well before I upgraded Ubuntu to 18.04. I thought that this could be solved by uninstalling it and then installing it again. I finally came to do it and it did not work.