Vim simple tutorial (1)
I used vim a long time ago, but the basic operations would be the best if I had a good level of food. And often hesitate to jump to the Emacs camp. After all, the legendary Emacs is so powerful that it can kill everything in seconds. However, Emacs seems to be more difficult to learn. In the end, let's decide to join vim. I accidentally found the VI iMproved book written by Steve Oualline. After reading it, I really thought I was a beginner. My blog series is actually my notes for studying VI iMproved. I hope you will be able to learn VIM.
Www.2cto.com
(Vim and Emacs seem to be a little different. It is difficult to learn another one after learning one. Therefore, if you decide to learn vim, don't think about Emacs.) compared with other text editors, VIM's learning curve is steep. I try my best to introduce only one small topic in each blog so that it is easy for everyone to digest and learn. (This series of blogs are preparing to write 81 articles, which means learning vim can be successful only after 81. I don't know if I can keep writing .) Vi is a widely used full-screen text editor in the Unix world. VIM is short for its IMproved version Vi IMproved, and is tied with Emacs to become the favorite editor for Unix-like users. Almost any Unix machine provides this software. Vim is widely used by programmers because it provides convenient programming functions such as code completion, compilation, and error jump.
A Brief History of www.2cto.com VIM vi was written by Bill Joy, who was still in Berkeley. Ken Thompson took his incomplete Pascal system when he went to Berkeley, and Bill Joy got a job to fix it during the summer vacation, he is not satisfied with the editor ed used to fix the code. Exactly. They got em code from a guy named George Coulouris, which is better than ed. They modified em, invented en, and eventually changed to ex (even Bill Joy did not know how to change to ex ). Later, he spent a few months writing vi. When Bram Moolenaar purchased his Amiga computer at the end of 1980s, there was no frequently used editor vi on Amiga. Bram started to copy Stevie from an open-source vi and developed Vim 1.0. The initial goal was to completely copy the vi function. At that time, Vim was short for Vi IMitation (simulation. 1992 version 1.22 of Vim was transplanted to UNIX and MS-DOS. From that time on, the full name of Vim was changed to Vi IMproved (IMproved. Afterwards, Vim has added countless new features, including multi-window editing mode (split windows) and highlight (syntax highlighting) features, code folding, plug-ins, multi-language support, spell check, context-related completion, Tab editing, and other new features. Lesson 1 the most basic operation is to run gvim: gvim in command line mode to open a file: gvim file.txt if file.txt does not exist, a new empty file is created. Figure 1 create an empty file file.txt Figure 1 shows a Tilde (~) before each line (~), This indicates that this line is not in the file. Because it is an empty file, of course there is no data in a row. The working mode of VIM is different from the general text editor. VIM has three working modes: Command mode, insert mode, and VISUAL mode. When vim is started, it is in command mode. Press the keyboard I to enter the insert mode. Note that "-- INSERT --" is displayed in the lower-left corner of the window where the file name is originally displayed --". In the insert mode, you can enter text and edit it like a normal editor. Press <Esc> when you want to return to the command mode. Move the cursor in command mode. You can use the arrow keys on the keyboard to move the cursor. But the quickest way is the following four keys: Left: h Right: l upper: k lower: j because moving the cursor is the most common operation, therefore, assign them the four keys that are most easily pressed in the right hand. Delete a character and a row Delete the character of the current cursor: x key delete a row: dd undo and restore undo the most recent operation: u recovery the most recent Undo operation: ctrl-R exit and save the current file and exit: ZZ (note that it is two uppercase Z) exit but not save: q! (Colon q, followed by an exclamation point, with three characters) If you only read the file and haven't made any changes, you can save the last exclamation point of the above command (!) Other basic editing commands insert characters at the end of the current row (entering the insert mode and moving the cursor to the end of the current row): a Key (append) insert an empty line in the next line of the cursor and move the cursor to the next line: o key (open) for help: help subject. For example, you want to see the help of the x command :: help x look at the help of CTRL-A fame: help CTRL-A sometimes, the same shortcut keys in different modes of time table different commands, vim by default think that the query is the command in command mode. You can add a prefix to differentiate different modes. I _ indicates the insert mode. V _ indicates the VISUAL mode.: Indicates the ex mode. For example, the following example: help I _CTRL-H: help: quit repeat a command multiple times you can add a number before the command, for example, I want to insert 10 a at the current position. 10ia <Esc> the final <Esc> is used to return to the command mode. If the executed command does not allow vim to enter the other mode from the command mode, the last <Esc> is not added. For example, move the cursor three characters to the left: 3 h OK. You can perform the most basic operations by knowing the above. Practice these skills before starting the second lesson.