Time: Thursday, August 24, 2017
Note: some of the contents of this article are taken from the book “complete collection of Linux command line and shell script programming”, and the copyright belongs to the original author. ***
Chapter 10: using the editor
Contents of this chapter
VIM editor Namo editor Emacs editor Kwrite editor Kate editor Cnome editor
10.1 VIM editor
10.1.1 check VIM package
Command format: readlink - F / usr / bin / VI Command description: view the link of VI file. When entering VI command, use VIM editor Command format: sudo apt get install VIM Command description: install the VIM package of the basic version in the Ubuntu distribution
10.1.2 VIM Foundation
Command format: VIM file_ name Command description: start VIM editor to edit the specified file Command Demo: VIM myprog. C Command description: use VIM editor to edit myprog. C file in memory cache
The VIM editor has two modes of operation
Normal mode: when opening the file to be edited, enter the normal mode, and VIM will interpret the key as a command Insert mode: in the insert mode, you can enter characters. Mode switching: press the I key to enter the insertion mode, press the ESC key to exit the insertion mode and return to the normal mode
In normal mode, move the cursor related commands
h: Shift left one character j: Move down one line (next line in text) k: Move up one line (the previous line in the text) l: Shift right one character Pagedown (or Ctrl + F): scroll down Pageup (or Ctrl + b): scroll up G: Move to the last line of the buffer Num G: move to line num in buffer GG: move to the first line of the buffer
In normal mode, there is a special function called command line mode. In normal mode, press the colon key to enter command line mode.
In command line mode, there are several commands that can save the buffer data to a file and exit vim
q: If the buffer data is not modified, exit q!： Cancel all modifications to the buffer data and exit W filename: save the file to another file WQ: save buffer data to a file and exit
10.1.3 editing data
In normal mode, VIM is a common command used to edit data in the buffer
x: Deletes the character at the current cursor position DD: delete the current cursor line DW: deletes the word at the current cursor position D $: delete the content from the current cursor position to the end of the line J: Delete the line break (splice line) at the end of the line where the current cursor is located u: Undo previous edit command a: Append data after the current cursor A: Append data at the end of the current cursor line R char: replace the single character at the current cursor position with char R text: overwrite the data of the current cursor position with text until ESC key is pressed
Some editing commands allow the use of numeric modifiers to specify how many times the command is repeated
Command Demo: 2x Command description: two characters starting from the current position of the cursor will be deleted Command Demo: 5dd Command description: 5 lines starting from the current line of the cursor will be deleted
Note: be careful when using backspace and delete keys in the normal mode of vim editor. VIM editor usually recognizes the delete key as the function of X command to delete the character at the current cursor position. The VIM editor usually does not recognize backspace keys in normal mode.
10.1.4 copying and pasting
Command Demo: v Command description: enter visual mode and move the cursor to overwrite the text you want to copy Command Demo: y Command description: after overwriting the text to be copied, press the Y key to copy the text and automatically exit the visual mode and return to the normal mode Command Demo: P Command description: paste the copied text
10.1.5 find and replace
Press the slash (/) key in normal mode, enter the text to be found, and press enter. VIM will respond in one of the following three ways
1. If the text to be found appears after the current position of the cursor, the cursor will jump to the first position where the text appears. 2. If the text to be found does not appear after the current position of the cursor, the cursor will bypass the end of the file, Appears in the first position of the text (indicated by a message) 3. Output an error message indicating that the text to be found is not found in the file
When multiple results are found, (press the slash key and then enter) or (press the N key), the next (next) is displayed.
The replacement command can only be used after entering the command line mode
Command format: S / old / New/ Command description: the VIM editor will jump to the place where old first appears and replace it with new
You can make some changes to the replace command to replace multiple text
S / old / new / G: replace all old with one line command n. MS / old / new / G: replace all old between line numbers N and m %S / old / new / G: replace all old in the entire file %S / old / new / GC: replace all old in the whole file, but prompt each time it appears
10.2 nano editor
Command format: nano mygrop. C Command description: open the mygrop. C file and read the contents of the file into the buffer, If the file does not exist, a new buffer will be opened for editing.
Nano control command
CTRL + C: displays the position of the cursor in the text editing buffer CTRL + G: displays the nano's main help window CTRL + J: adjust current text paragraph CTRL + K: cut the text line and save it in the cut buffer CTRL + O: writes the contents of the current text editing buffer to a file CTRL + R: reads the file into the current text editing buffer CTRL + T: starts the available spell checker CTRL + U: put the contents of the clipping buffer into the current row CTRL + V: flip to the next page in the text editing buffer CTRL + W: search for words or phrases in the text editing buffer CTRL + X: close the current text editing buffer, exit nano and return to shell CTRL + Y: flip to the previous page in the text editing buffer
10.3 Emacs editor
10.3.1 check emace software package
Command Demo: wich Emacs Command description: check whether emace is installed Command Demo: Yum list Emacs (red hat based distribution) Command description: check whether emace is installed Command demonstration: sudo apt cache show Emacs (based on Ubuntu distribution) Command description: check whether emace is installed Command Demo: sudo apt get install Emacs (based on Ubuntu distribution) Command description: install Emacs editor Command Demo: sudo Yum install Emacs (based on CentOS distribution) Command description: install Emacs editor
10.3.2 using Emacs in the console
Command format: Emacs mygrop. C Command description: edit mygrop. C file
Unlike the VIM editor, Emacs has only one mode. If you enter a printable character, Emacs inserts it into the current position of the cursor. If you enter a command, Emacs executes the command.
When the tip: Emacs editor is used, the commands are difficult to understand and remember. Not recommended.
10.3.3 using Emacs in GUI environment
Using Emacs on the graphical interface is relatively simple. It is similar to using EDITPLUS, Notepad + + and other editing software on windows.
10.4 KDE system editor
10.4.1 kwrite editor
The basic editor of KDE environment is kwrite. It provides a simple text editing function of word processing type, and also supports code syntax highlighting and editing. Is a graphical software. It is similar to editing software such as sublime and UltraEdit on windows.
10.4.2 Kate editor
Kate editor is the flagship editor of KDE project. It uses the same text editor as kwrite, so most of their functions are the same, but they integrate a lot of other features.
10.5 Gnome editor
10.5.1 start GEDIT
Most GNOME desktop environments place GEDIT in the accessories panel menu entry. Of course, it can also be opened by the command getdit mygrop. C.
10.5.2 basic GEDIT functions
GEDIT uses the menu bar and toolbar to set functions and configure settings.
10.5.3 set and compile settings
Menu path: Edit – > Preferences
The editor is available for various preferences
When creating shell scripts, you need some type of text editor. Here we introduce the commonly used editors VIM, nano, Emacs, and some graphical editing tools. This chapter describes the VIM, nano, Emacs commands.
The personal summary of the learning commands in this chapter is as follows
VIM: use the VIM editor for file editing Nano: use the nano editor for file editing Emacs: use the Emacs editor for file editing