Emacs——基本操作入门
Emacs——基本操作入门
环境: Ubuntu20.04 内核 5.4
安装: 使用包管理工具sudo apt-get install emacs
主要依赖 Ctrl(CONTROL key)和 Alt (META or EDIT or ALT key).、
Master Emacs in 21 Days 后面可以跟随学习一下。
Basic cursor control
C-v下翻页,M-v上翻页。
光标移动,C-p,C-n配合M-f,M-b使用(可以移动光标所在单词的开头结尾)。
C-fMove forward a characterC-bMove backward a characterM-fMove forward a wordM-bMove backward a wordC-nMove to next lineC-pMove to previous lineC-aMove to beginning of lineC-eMove to end of lineM-aMove back to beginning of sentenceM-eMove forward to end of sentenceM-<Move to the begining of the whole test (Shift +M-comma)M->Move to the end of the whole text (Shift +M-dot)
建议上述 Emacs 风格移动的原因:
- 在任何终端适用
- 不用移动出打字区,更高效
便于理解更高级的控制方式
C-u num C-*指定数量参数(numeric argument).
C-gStop the command safely.
Disabled commands
一些防误触的指令指定为 Disabled,调用会报警告。敲 Space 会临时使用一次。
Windows
窗口相关操作
C-x 1维持单窗口,kill others(比如需要使用该指令删除 help 窗口)C-h k C-f貌似是打开帮助界面解释后面的指令
Inserting and deleting
插入,自动换行的,输入插入,Delte 键删除。换行< Return >会根据上下文调整换行后的前进字符数,称“electric”.
Inseting 可以使用C-u num来重复添加。
<DEL>Delete the character just before the cursorC-dDelete the next character after the cursorM-<DEL>Kill the word immediately before the cursorM-dKill the next word after the cursorC-kKill from the cursor position to end of lineM-kKill to the end of the current sentence
选中(Mark set),最简单的方式使用C-<SPC>开启 Mark set 提示,然后配合光标移动操作选定。
Kill and yank,或许习惯上使用C-k(剪整行)或者单 wordM-<DEL>(前)或者M-d(后),贴的话就是C-y. Emacs Kill 是有队列的,可以 kill 很多行再按序 yank,另外M-y可以切换上一次 Kill 的内容。
Undo
C-/ 不会 Undo 光标移动的操作。
Files
先要找到文件C-x C-f,找到文件,搜索过程Tab会在子窗口列出所有符合搜索条件的文件。敲击<Return>进行确认(操作不存在的文件等于写新文件)。
对于文件的修改应该是类似缓冲区,都没有直接物理修改(持久化)本身文件(为了避免出现 half-change 的情况)。应使用C-x C-s存储文件。
Buffer
C-x C-b列出 buffers。C-x b <FILENAME>切换到另一个 bufferC-x sSave some buffers
有关 Message 和操作日志,可以通过C-x b *Message*查看(也是一个 buffer)。
Extending the command set
使用X进行指令的扩展,如C-x(Character eXtend.)和M-x(Named command eXtend),下面列出一些常见的扩展指令:
C-x C-fFind fileC-x C-sSave fileC-x sSave some buffersC-x C-bList buffersC-x bSwitch bufferC-x C-cQuit EmacsC-x 1Delete all but one windowC-x uUndo
M-x使用场合很少,输入切换到底部,需要输入指令全称(比如replace-string).
Auto Save
- auto save file: 用“#”开头结尾
- recover: 找到原始文件(非“#”文件),执行
M-x输入recover-this-file.
Mode
没有太细致研究。
Searching
C-s开启搜索,输入搜索内容后再C-s,则转向下一符合搜索的内容,<Return>终止搜索。
Multiple windows
同时开启多个窗口(多屏操作),emacs 习惯用“frames”来表示其他应用中的“windows”(即多个带控制 bar 的视窗),window 指光标分处的不同屏幕。
C-x 2开启两个 windows,光标在上C-M-v下窗口向下滑.C-x o切换光标所在的屏幕
Multiple frames
C-x 5 2: See a new frame appear on your screen.C-x 5 0: This removes the selected frame.
More Features
实践中体验,使用 Help menu,C-h r.
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!