emacs as work environment

本文介绍了Emacs文本编辑器的高级使用技巧,包括如何运行shell命令、使用Dired模式批量操作文件、压缩与解压文件以及比较文件等内容。适用于希望提高Emacs使用效率的用户。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Shell Buffer

Running one command at a Time

In Emacs session -> M-! -> prompt "shell command" -> cat /home/ryu/test -> display in *Shell Command Output*

C-u M-! 与 M-!不同的是,它直接显示结果在当前buffer中鼠标所在位置后面


region Command

有一些命令跟我们在终端时候的情形不太一样,比方说我们可以对一个region使用Command命令。

M-h     命令mark-paragraph ->M-| -> prompt " shell command on region" -> type 'sort RET'


Using Shell Mode

M-x shell RET   create *shell* buffer

Emacs 实际上就相当于一个shell的命令接口,只是现在我们可以对这些进行直接的复制,修改等操作。但是他们还是有些不同的操作要注意。我们在terminal中可以执行C-c来终止一个命令

M-p     bring back earlier commands 在mini-buffer中会显示History item

Enter   在shell-mode中它会执行光标所在行的命令,同时你可以先修改这个命令然后再确认;这个相当与重复执行以前命令。

Tab     进行自动补全,其中包括文件名,系统命令等,Emacs跟windows 有的时候不是太顺畅。

C-c C-o 自动删除上一个命令的输出comint-kill-output 命令

C-c C-r comint-show-output 如果命令的输出太长,造成最前面的输出出界。你可以通过这个命令把光标移动到最开始输出的位置

C-c C-e comint-show-maximum-output 来查看命令的最底部输出


Multipul shell buffer

M-x rename-uniquelyrename current buffer, then you can typeM-x shellto create another shell buffer.


Using Dired

Dired is one of the most interesting features of Emacs. For example, you can work with groups of files, deleting, moving, compressing, or even query-replacing strings in them.


编辑目录方式

1:C-x C-f 我们一般都是指定一个文件名,现在你只需指定一个文件夹名就行了。

2:C-x d  

当显示的时候他会支持颜色设置,如果你发现它都是一样颜色的话,可以输入命令M-x font-lock-mode,或者直接在.emacs中加入(global-font-lock-mode t)

你会发现显示的方式是按字母排序(Dired by name)这个时候你可以通过输入s(for dired-sort-toggle-or-edit)将它们按日期排序。

因为它显示的形式就好像ls -al 命令得到的形式差不多,然后类比我们处理buffer-list时候的各种快捷键,同样在这里适用。


v dired-view-file Emacs display the file in view mode,q to return to directory listing. 当你在视图模式的时候可以输入s进行incremental search.输入enter的话会一行一行的向下滚动。

f find

e edit

d delete file you can mark as many files as you want

u unmark flag

x execute

# delete file's auto-save file,end up with #

C capital C, 会提示你输入目的文件,3C会复制当前文件及下面2个文件

R rename


Compressing and Uncompressing files

Z dired-do-compress Emacs ask "compress or uncompress",Emacs只会压缩成gzip格式.gz,但是如果你解压缩的时候他也能够正确认识.z .Z or .gz,

M-x auto-compress-mode RET 可以使Emacs编辑压缩文件


Comparing Files

=

M-= 比较文件和备份文件以~结尾,直接在备份文件行输入该命令就会转到*diff* buffer


Running shell command on files

首先输入一个感叹号!然后你就可以对file进行各种文件操作命令sort, grep, find, chmode

! Prompt "! on filename: "

* asterisks 意思时用光标所在位置文件或我所标记的。

? question mark如果很多个文件都被标记了,它会让每个文件都分开执行该命令

比如"! on file: sort * > file-out" 他就是把标记或者所在位置的文件经过排序以后输出到file-out.


Mark

m     mark file with an asterisk,Emacs assumes that you want to operate on these files. 3m mark the file and the next two files.


Delete mark

M-Del 你会发现即使把所要处理的文件都处理了,标记仍存在,这个时候你可以用命令dired-unmark-all-files来移除标记 del是键delete


Invert mark

t     toggles the marks, 标记为标记的,取消已经标记的


select files

#     #filename# auto-saved files created when a session terminates abnormally

~     filename~ backup file which Emacs creates periodically

**    select executable files

*/    select directories

*@    select symbolic links


Using regular expression to choose files

%m ^c mark all the file start with c

%g    用与标记,谁的内容符合某一条件

在这里它跟grep中正则表达式一样,find/ls命令都会把^当成一个普通字符


Operating on group of files

+    dired-create-directory 创建subdirectories.

R    like mv command in unix. renaming file and moving file.当发现文件都已经标记了以后,他就会移动这些文件,而不是改名字。


searching in group of files

A    dired-do-search  do a regular expression on marked files,stop at first match, M- finds next match.

Q    dired-do-query-replace 他会顺序查询搜索search string.注意如果你用recursive edit中止的话,你必须再回到Dired buffer 才能够开始














评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值