1 00:00:06,870 --> 00:00:09,901 - In this video, we are going to talk about text editors. 2 00:00:09,901 --> 00:00:14,901 So working in Linux mostly happens from the command line. 3 00:00:15,390 --> 00:00:17,370 And that means that you also 4 00:00:17,370 --> 00:00:19,260 need a command line text editor. 5 00:00:19,260 --> 00:00:21,960 Of course the graphical user interface is text editors 6 00:00:21,960 --> 00:00:24,630 but these are useless if you're not 7 00:00:24,630 --> 00:00:26,400 in a graphical interface. 8 00:00:26,400 --> 00:00:28,020 Nano is very easy to use, 9 00:00:28,020 --> 00:00:31,263 and it's available on many Linux installations by default. 10 00:00:32,130 --> 00:00:33,810 Vim is vi improved, 11 00:00:33,810 --> 00:00:36,240 and vi improved is a very powerful editor 12 00:00:36,240 --> 00:00:39,030 with advanced programming features. 13 00:00:39,030 --> 00:00:40,950 Now, the thing is that on some systems 14 00:00:40,950 --> 00:00:43,560 you will only find vi or vim. 15 00:00:43,560 --> 00:00:45,810 And for that reason, you should invest 16 00:00:45,810 --> 00:00:49,290 your time learning vim if you wanna go deeper with Linux. 17 00:00:49,290 --> 00:00:51,210 If you're not interested in going deep 18 00:00:51,210 --> 00:00:53,580 and knowing all about the Linux operating system 19 00:00:53,580 --> 00:00:55,980 feel free to use the nano editor. 20 00:00:55,980 --> 00:00:58,200 But if you really want to master Linux 21 00:00:58,200 --> 00:01:00,780 and have access to a powerful text editor, 22 00:01:00,780 --> 00:01:04,211 vi or vim is unavoidable. 23 00:01:04,211 --> 00:01:07,560 The downside is that vim is more difficult to use, 24 00:01:07,560 --> 00:01:10,779 but as I told you, you should learn how to use it anyway 25 00:01:10,779 --> 00:01:14,370 for the simple reason that it is always available, 26 00:01:14,370 --> 00:01:17,797 even on very old UNIX systems. 27 00:01:17,797 --> 00:01:20,940 Vim is invented in 1984. 28 00:01:20,940 --> 00:01:23,910 So even if you get to a real old UNIX system, 29 00:01:23,910 --> 00:01:27,240 you type, vi, it will work. 30 00:01:27,240 --> 00:01:30,870 And in case you are confused, what is it, vim or vi? 31 00:01:30,870 --> 00:01:34,200 Well on most Linux distributions, it's exactly the same. 32 00:01:34,200 --> 00:01:36,780 We don't care about the small differences 33 00:01:36,780 --> 00:01:38,940 between the two of them in this course. 34 00:01:38,940 --> 00:01:41,240 I just want you to learn how to work with them 35 00:01:42,960 --> 00:01:45,750 because you will appreciate, as it is a powerful 36 00:01:45,750 --> 00:01:47,970 and programmable editor that allows you 37 00:01:47,970 --> 00:01:51,900 to perform text file operations in an easy way. 38 00:01:51,900 --> 00:01:53,250 Now, you might notice that 39 00:01:53,250 --> 00:01:55,470 your distribution is not running the editor 40 00:01:55,470 --> 00:01:56,580 that you want to use. 41 00:01:56,580 --> 00:01:58,098 And if you want to change that, 42 00:01:58,098 --> 00:02:02,530 you can use this command, export EDITOR=$(which vim). 43 00:02:04,230 --> 00:02:07,367 I will show you that command in just a little bit, 44 00:02:07,367 --> 00:02:11,343 but first I wanna have a quick look at nano. 45 00:02:13,560 --> 00:02:15,060 So here we go. 46 00:02:15,060 --> 00:02:19,713 I'm typing, nano, my file. 47 00:02:21,000 --> 00:02:22,920 And this is the nano interface. 48 00:02:22,920 --> 00:02:26,460 Now nano has been created to be intuitive. 49 00:02:26,460 --> 00:02:28,443 So you can start typing, 50 00:02:31,440 --> 00:02:35,220 and you don't need to do anything complex. 51 00:02:35,220 --> 00:02:36,810 So no complex stuff. 52 00:02:36,810 --> 00:02:39,660 The only thing that is complex is what you do when 53 00:02:39,660 --> 00:02:41,370 you are done with nano. 54 00:02:41,370 --> 00:02:42,870 Well, everything that can be done 55 00:02:42,870 --> 00:02:47,870 when you are done is in the lower part of the screen. 56 00:02:47,880 --> 00:02:50,970 You can see on the left, there is key strokes 57 00:02:50,970 --> 00:02:52,957 that start with a caret. 58 00:02:52,957 --> 00:02:55,810 The caret is the control key. 59 00:02:55,810 --> 00:02:59,190 So if you use control-X, for instance, then you will exit. 60 00:02:59,190 --> 00:03:02,853 - And there are more options that start with the caret. 61 00:03:04,050 --> 00:03:06,330 The other options are to the right 62 00:03:06,330 --> 00:03:08,190 on the bottom of your screen. 63 00:03:08,190 --> 00:03:09,780 They start with M. 64 00:03:09,780 --> 00:03:10,740 Now what is M? 65 00:03:10,740 --> 00:03:12,927 M is what we call the meta key. 66 00:03:12,927 --> 00:03:16,890 And the meta key or most keyboards is the alt key. 67 00:03:16,890 --> 00:03:19,658 So control and alt is what you need. 68 00:03:19,658 --> 00:03:21,390 So I'm going to use control-X, 69 00:03:21,390 --> 00:03:24,420 and control-X is asking me, save modified buffer? 70 00:03:24,420 --> 00:03:26,730 Yes, I want to save modified buffer. 71 00:03:26,730 --> 00:03:29,010 And file name to write? 72 00:03:29,010 --> 00:03:32,220 Oh, I noticed that I made an error when I created my file, 73 00:03:32,220 --> 00:03:35,100 so I can still change it here. 74 00:03:35,100 --> 00:03:38,400 Also nice, is that it is asking me for the format. 75 00:03:38,400 --> 00:03:41,730 Am I writing in DOS format or in Mac format? 76 00:03:41,730 --> 00:03:43,620 Well, I don't care about format. 77 00:03:43,620 --> 00:03:44,700 This is Linux, right? 78 00:03:44,700 --> 00:03:46,380 So we don't care about DOS and Mac. 79 00:03:46,380 --> 00:03:48,900 So I'm just going to press Enter 80 00:03:48,900 --> 00:03:51,480 and save file on the different name. 81 00:03:51,480 --> 00:03:52,680 Why is it asking that? 82 00:03:52,680 --> 00:03:54,270 Because I just changed the name. 83 00:03:54,270 --> 00:03:57,630 So yes, I want to save file under a different name, 84 00:03:57,630 --> 00:04:01,290 and oh no, error writing my file, permission denied. 85 00:04:01,290 --> 00:04:03,180 Why am I getting permission denied? 86 00:04:03,180 --> 00:04:04,980 Well, it's only one way to figure out, 87 00:04:04,980 --> 00:04:07,800 I'm going to not save the modified buffer. 88 00:04:07,800 --> 00:04:09,210 And where am I? 89 00:04:09,210 --> 00:04:12,150 I am in tmp files, and apparently 90 00:04:12,150 --> 00:04:15,030 I don't have permissions to write there. 91 00:04:15,030 --> 00:04:16,650 No permissions to write there? 92 00:04:16,650 --> 00:04:20,460 Well, that is something that we need to talk about later. 93 00:04:20,460 --> 00:04:22,260 I don't wanna talk about permissions now. 94 00:04:22,260 --> 00:04:26,070 So let me go to my home directory and try again. 95 00:04:26,070 --> 00:04:27,761 Nano new file, 96 00:04:27,761 --> 00:04:32,083 hello world, 97 00:04:32,083 --> 00:04:34,260 control-X, same sequence again. 98 00:04:34,260 --> 00:04:36,660 Yes, I want to modify, I'm just pressing enter 99 00:04:36,660 --> 00:04:39,420 to write a new file and here we go, 100 00:04:39,420 --> 00:04:42,450 new file has been created, as you can see. 101 00:04:42,450 --> 00:04:46,080 That is nano, and nano, as I said, is easy. 102 00:04:46,080 --> 00:04:48,450 The vi is not, but you should learn how to work 103 00:04:48,450 --> 00:04:51,093 with vi anyway, and that's in the next video.