So why do we need text editors?
Well, working in Linux mostly happens from the command line, and that means that you need a command line text editor.
Nano is easy to use and available on many Linux installations by default.
Even stronger, it has become the default text editor on many Linux distribution.
But if you really want power and advanced features, you should use vim.
VIM is VI improved.
That's a very powerful editor with features that you won't find in Nano.
That's also why I would recommend you learn how to use VIM also, because on some systems you will only find
VI for the simple reason that VI is a minimal editor. It has been around for a long time, and that
is why you might find yourself behind a system that does not have Nano, but it does have vi.
Now, the bad thing is that VIM is more difficult to use, but you should learn it anyway.
It's always available, even on very old Unix systems.
It's powerful and programmable to perform text file operations in an easy way.
And if you want to set your favorite editor as
a default, you can use export editor is $with Vim.
I'll demonstrate.
So let me first show you how to work with Nano.
Nano, my new VAL that's opening my new file. And the convenient
thing is that I can just start typing. Hello, Start typing.
How are you?
Even if it's just a demo, let's do it without any errors.
Now, the nice thing about Nano is that in the lower part of the screen you see all of your controls.
So the control that I'm going to need is control X, Control X for exit. But you can also
find using control F or replace using control backslash and more in the controls on the lower part of
the screen. If it starts with a caret, the caret is a control character. And if it starts with
an M, the M is the metakey and the meta key is typically the alt key on your keyboard.
I'm going to use control X to write my file and then it's asking save modified buffer.
That means that all changes in the file are currently in memory only and
only when I've committed them using Yes, I have saved my modified buffer.
It's asking for the file name and the file name, my new
file. That's okay. So I'm entering and then we are done.
Now how do we do that with vim? Well, I will show you later, but the first thing that
I want to show you is how to make sure that you use VIM as your default editor.
That would be by using export editor is followed by dollar width vim and what will that
do? Well, that will make sure that if ever I'm using a command that needs an editor,
it will use vim as default editor and that is how the world should be.
Now if you want this to be persistent then even
make it a little bit stronger and use echo export
editor is $which Vim greater than etc bashrc?
I'll tell you about this later, but oh no, this is not working. You have any idea why?
Permission denied.
I don't have write permissions to etc bash RC and and I'm glad I
don't because I'm using a single redirect which would have overwritten the entire bashrc.
You need a double redirect to override in append mode and then I need to
put this entire command between single quotes and I make that sudo sh c.
If ever you have a command that has one of these shell metacharacters like pipes or redirects
in it and you want to run the entire thing with sudo privileges, then you start your
command using sudo sh c in this way and then it prompts for your root password and
it just makes sure that this editor variable is also in the etc bashrc which is one
of the startup files for the bash shell. I'll tell you in much more detail about that
later, but for now it's already good that you have seen this convenient command at least once.
All right, let's continue with the next video.