Emacs 在开发项目中的实际应用(一)

我使用的是 Mac OS 上的 Aquamacs。

 

 

以项目目录为开发阵地

由于使用的是 GUI 版,我需要进入 Python 的项目目录,以方便我每次打开文件时,不需要每次都输入长长的路径前缀。

方法是:

以打开文件的方式,打开目录

Ctrl-x Ctrl-f <目标目录>

 

当前 Tab 的显示内容就变成了 ls -la 的输入内容。

再次 Ctrl-x Ctrl-f ,下面的提示信息显示,已自动加上了路径前缀。

 

 

关闭一个 Tab 页

先用手动点击小叉叉好了,目前还没到 block 我操作的地步 :)

 

 

执行 shell 命令

例如我想在当前目录的所有源码文件中查找 startswith 这个字符串,通常大家需要执行 shell 命令

grep startswith *.py

VIM 最大的缺点是,我找不到方便的方法在 VIM 与 Shell 之间切换的方法。而这恰好是 Emacs 的优势。

Meta-x shell (Mac 上的 Meta 键使用 alt/option 键代替)

在新的 tab 中输入

grep startswith *.py 即可

 

M-p 上次执行的命令(类似正常 shell 下的上箭头键)

M-n 下个执行的命令(类似正常 shell 下的下箭头键)

 

 

文件内查找字符串

Ctrl-s

在 i-search 提示栏输入要搜索的关键字。

按 Ctrl-s 查找下一个匹配。

按下 Enter 键结束搜索。

 

 

运行 python 代码,并查看输出结果

Ctrl-c Ctrl-c 

此时,屏幕会一分为2,右侧显示运行结果 

 

 

使用代码模板

 参考: http://www.emacswiki.org/emacs/AutoInsertMode

 修改 ~/.emacs 文件之后,需要重启 Aquamacs 才能生效

 

 

根据上下文已存在的变量名,半自动补全当前正在输入的变量名

(类似于 VIM 中的 Ctrl-n)

M-/

 

 

连续多行赋值语句对齐

http://stackoverflow.com/questions/60367/the-single-most-useful-emacs-feature

 

A not so well known feature that I find very useful is M-x align-regexp. If you mark a region and execute it, you will be asked for a regular expression, and emacs will then line up the first match of that expression on every line, by padding with spaces (or tabs, if you like). For example, say that you have a list of variables in your code:

int a = 2;
int a_longer_variable_name = 73;
int i = 0;
Then you can mark those lines and to M-x align-regexp and specify = as the expression, and it will align it like:

int a = 2;
int a_longer_variable_name = 73;
int i = 0;
Maybe not the most important feature in the world, but I use it regularly, and it sometimes impresses non-emacs people. :)
 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值