Linux下面的常用编辑器使用总结
Linux下面常用的编辑器有:nano,vi,vim
nano编辑器
一般的Linux发行版都带有这编辑器,所以这个较万能,但是功能比较简单,像windows的txt。若系统没有自带的话也可以使用下面其中一条命令安装:
apt-get install -y nano 或者 yum -y install nano
使用方法:
1.打开或者新建文件命令: nano 文件名
2.进入后界面下面有命令提示,看着提示操作就可以了,但这里提示不全,需要看详细的提示可以使用Ctrl+G查看。这里需要提醒的是:命令中的^这个符号代表Ctrl键,字母不需要使用大写,-号代表Alt键。
3.常用命令总结:
搜索:^W ,多次搜索可以再按一次直接回车
剪切行:^K
复制行: ^6
粘贴:^U
vi编辑器
一般Linux也会带有这个编辑器,像windows的写字板。若系统没有的话,不建议安装vi,建议直接安装vim,功能和vi差不多,并支持多插件。
vi有两种模式:命令模式(所有按键都是命令),编辑模式(所有按键都作为输入)
模式互换:进入命令模式可以使用大写I键,推出命令模式可以使用Esc键
vi命令帮助分析:
root:~# vi -h
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jun 07 2019 15:35:43)
usage: vim [arguments] [file ..] edit specified file(s)
or: vim [arguments] - read text from stdin
or: vim [arguments] -t tag edit file where tag is defined
or: vim [arguments] -q [errorfile] edit file with first error
Arguments:
-- Only file names after this
-v Vi mode (like "vi")
-e Ex mode (like "ex")
-E Improved Ex mode
-s Silent (batch) mode (only for "ex")
-d Diff mode (like "vimdiff") 像git那样对比多个文件的变动,这个比较有用
-y Easy mode (like "evim", modeless)
-R Readonly mode (like "view") 这个可以防止误改文件
-Z Restricted mode (like "rvim")
-m Modifications (writing files) not allowed
-M Modifications in text not allowed
-b Binary mode 二进制模式
-l Lisp mode
-C Compatible with Vi: 'compatible'
-N Not fully Vi compatible: 'nocompatible'
-V[N][fname] Be verbose [level N] [log messages to fname]
-D Debugging mode
-n No swap file, use memory only
-r List swap files and exit
-r (with file name) Recover crashed session
-L Same as -r
-A start in Arabic mode
-H Start in Hebrew mode
-F Start in Farsi mode
-T <terminal> Set terminal type to <terminal>
--not-a-term Skip warning for input/output not being a terminal
-u <vimrc> Use <vimrc> instead of any .vimrc
--noplugin Don't load plugin scripts
-p[N] Open N tab pages (default: one for each file)
-o[N] Open N windows (default: one for each file)
-O[N] Like -o but split vertically
+ Start at end of file
+<lnum> Start at line <lnum>
--cmd <command> Execute <command> before loading any vimrc file
-c <command> Execute <command> after loading the first file
-S <session> Source file <session> after loading the first file
-s <scriptin> Read Normal mode commands from file <scriptin>
-w <scriptout> Append all typed commands to file <scriptout>
-W <scriptout> Write all typed commands to file <scriptout>
-x Edit encrypted files
--startuptime <file> Write startup timing messages to <file>
-i <viminfo> Use <viminfo> instead of .viminfo
-h or --help Print Help (this message) and exit
--version Print version information and exit
常用的命令(命令模式下):
定位相关
状态:Ctrl+G查看当前位置
光标移动 :gg文首,G文末,^行首,$行末,w下个词首,W上个词首,e下个词末,E上个词末,{{上一段开头,}}下一段开头,[[上一个函式,]]下一个函式
翻页:zz光标归中,Ctrl+F下页,Ctrl+B上页,Ctrl+Y下行,Ctrl+E上行
查找:/查找的文字(n下一个匹配,N上一个匹配)
编辑相关
撤销操作:u
重做操作:Ctrl+r
复制行:yy
剪切行:dd
粘贴行:p
进入编辑模式:a,o,i,A,O,I
删除字符:d+(数字)方向,
替换:r+(数字)要替换的字母;全局替换:%s/匹配的文字/要替换的文字/g
选择相关
选择模式V,可以使用o切换首尾光标位置,选择文本进行复制y,删除d,替换r等操作
选择模式Ctrl+V,可以使用o切换首位光标位置,主要用于对文本进行统一按行编辑,按I进入编辑的位置,按Esc应用与所有行。这个功能用来注释代码非常有用。

本文详细介绍了Linux下常用的编辑器,包括nano、vi和vim的使用方法及命令总结,涵盖了编辑器的基本操作、模式切换、文件定位、文本编辑、搜索替换等功能。
838

被折叠的 条评论
为什么被折叠?



