text editor: 可以分为:graphical user interface (GUI) text editors and command-line editors.
GUI: such as TextWrangler, Sublime, and Notepad++, which allow you to write and edit plain text documents.
vim is a command_line editor
链接:http://www.runoob.com/linux/linux-vim.html
https://coolshell.cn/articles/5426.html
vim 以及在我们的opsin 里了。无需安装
#Vim Modes
Vim has two basic modes that will allow you to create documents and edit your text:
-
command mode (default mode): will allow you to save and quit the program (and execute other more advanced commands).
-
insert (or edit) mode: will allow you to write and edit text
一般情况下默认为command mode, 点击 i 即切换为insert mode. 即可输入编辑文档。输入完成,点击esc 即推出到command mode.
#Vim Saving and Quitting
To write to file (save), type :w. You can see the commands you type in the bottom left-hand corner of the screen.
Alternatively, we can write to file (save) and quit. Let’s do that by typing :wq. Now, you should have exited vim and returned back to your terminal window.
To edit your draft.txt
document, open up the file again by calling vim and entering the file name: vim draft.txt
. Change to insert mode and type a few more lines (you can move around the lines using the arrows on the keyboard). This time we decide to quit without saving by typing :q!
保存就是 :w, 或者我们可以:wq 退出。 如果想再次编辑,要先用vim 空格 文件名来调出文件,然后 i 切换到编辑模式, 输入完成后即:wq 保存退出。 或者直接 :q! 不保存直接退出。
#Vim Editing
为了更容易地区分行, 我们可以给以及编辑的文本加上行号。 即输入 : set number. Save the document.
相反,如果想去除行号就输入: set nonumber.
移动快捷键 While in command mode, try moving around the screen and familarizing yourself with some of these shortcuts:
key | action |
---|---|
gg | to move to top of file |
G | to move to bottom of file |
$ | to move to end of line |
0 | to move to beginning of line |
w | to move to next word |
b | to move to previous word |
In addition to shortcuts for navigation, vim also offers editing shortcuts such as:
key | action |
---|---|
dw | to delete word |
dd | to delete line |
u | to undo |
Ctrl + r | to redo |
/pattern | to search for a pattern (n/N to move to next/previous match) |
:%s/search/replace/g | to search for a pattern and replace for all occurences |
##Overview of vim commands
Vim modes:
key | action |
---|---|
i | insert mode - to write and edit text |
esc | command mode - to issue commands / shortcuts |
Saving and quiting:
key | action |
---|---|
:w | to write to file (save) |
:wq | to write to file and quit |
:q! | to quit without saving |
Shortcuts for navigation:
key | action |
---|---|
gg | to move to top of file |
G | to move to bottom of file |
$ | to move to end of line |
0 | to move to beginning of line |
w | to move to next word |
b | to move to previous word |
Shortcuts for editing:
key | action |
---|---|
dw | to delete word |
dd | to delete line |
u | to undo |
Ctrl + r | to redo |
:set number | to number lines |
:set nonumber | to remove line numbers |
/pattern | to search for a pattern (n/N to move to next/previous match) |
:%s/search/replace/g | to search for a pattern and replace for all occurences |