Emacs Q&A

来源:互联网 发布:怎么分享淘宝店铺 编辑:程序博客网 时间:2024/06/05 08:08

Q: Windows下Emacs配置文件在哪里?
A: 设置环境变量HOME变量,比如:HOME=”C:\Users\username\”,然后在C:\Users\username\下创建文件”.emacs”,重启emacs。

Q: 文件名末尾带’~’的文件是什么文件?
A: 是emacs自动生成的备份文件,每次打开文件后第一次保存文件时,emacs会自动将保存前的文件重命名为文件名结尾带’~’的文件。

Q: 如何不产生备份文件?
A: 在.emacs文件中添加(setq make-backup-files nil)。

Q: 如何设置打开文件的默认路径?
A: 对于Windows系统,创建一个快捷方式,在其起始位置中填入想要设置的默认路径。

Q: 如何设置背景颜色?
A: 在.emacs文件中添加(set-face-background ‘default “LightCyan3”) ;;;背景颜色设置为浅青色3

Q: 如何分屏?
A: Ctrl+x 2 上下分屏
Ctrl+x 3 左右分屏
Ctrl+x 0 只显示一屏
Ctrl+x o 切换到另外一屏

Q: 如何显示文件列表?
A: 参见网址https://www.emacswiki.org/emacs/SrSpeedbar
首先下载配置文件:https://www.emacswiki.org/emacs/sr-speedbar.el
将配置文件保存至:Emacs\share\emacs\24.5\lisp\下,
在配置文件中加入:(require ‘sr-speedbar),
输入:M+x sr-speedbar open

Q: 如何设置字体?
A: 在.emacs文件中添加
(set-default-font “Consolas-12”)

Q: 如何显示行号?
A: (global-linum-mode t) ;;显示行号

Q: 如何设置颜色主题?
A: 下载color theme扩展包:http://download.savannah.gnu.org/releases/color-theme/
解压文件,将color-theme.el和themes文件夹拷贝至Emacs\share\emacs\24.5\lisp\。
在.emacs文件中添加:
(require ‘color-theme)
(color-theme-initialize)
(color-theme-deep-blue)
输入:M+x color-theme-xxx可以浏览不同的主题效果。

Q: 如何使用etags?
A: 需要用到shell的find命令,因此先安装mingw32。
cd到工程目录;
find . -regex ‘.*\.cpp\|.*\.h\|.*\.hpp’ -print | etags -
在当前目录下回生成TAGS文件。

Q: mingw32的find命令与windowsfind命令冲突怎么办?
A: 在环境变量Path中,将mingw32的bin目录移到最前面。

Q: 如何使用cscope?
A: 从
https://sourceforge.net/projects/mslk/files/Cscope/
下载最新的zip包,解压其中的可执行文件和动态库到Path目录下;
从https://sourceforge.net/projects/cscope/files/ 下载源码,将contrib\xcscope目录下的xcscope.el文件拷贝到emacs加载路径下;
在配置文件中添加 (require ‘xcscope)

Q: 在Windows下如何生成cscope的索引文件?
A: 首先需要用find工具生成源文件索引文件,文件名为cscope.files,然后再emacs中通过C-c s a设置索引文件路径为刚才生成文件所在路径。后面就直接使用cscope相关命令就可以了。

Q: 如何查找文件
A:

Dired and find
You can select a set of files for display in a Dired buffer more
flexibly by using the find utility to choose the files.

find-name-dired
To search for files with names matching a wildcard pattern use M-x
find-name-dired. It reads arguments directory and pattern, and chooses
all the files in directory or its subdirectories whose individual names
match pattern.
The files thus chosen are displayed in a Dired buffer in which the
ordinary Dired commands are available.

find-grep-dired
If you want to test the contents of files, rather than their names, use
M-x find-grep-dired. This command reads two minibuffer arguments,
directory and regexp; it chooses all the files in directory or its
subdirectories that contain a match for regexp. It works by running the
programs find and grep. See also M-x grep-find, in Compilation.
Remember to write the regular expression for grep, not for Emacs. (An
alternative method of showing files whose contents match a given regexp
is the % g regexp command, see Marks vs Flags.)

find-dired
The most general command in this series is M-x find-dired, which lets
you specify any condition that find can test. It takes two minibuffer
arguments, directory and find-args; it runs find in directory, passing
find-args to tell find what condition to test. To use this command, you
need to know how to use find.

others
M-x locate provides a similar interface to the locate program. M-x
locate-with-filter is similar, but keeps only lines matching a given
regular expression.
The format of listing produced by these commands is controlled by the
variable find-ls-option, whose default value specifies using options
-ld for ls. If your listings are corrupted, you may need to change the
value of this variable.

Q: 如何像source insight中shift+F8那样显示高亮?
A: http://nschum.de/src/emacs/highlight-symbol/

Q: 如何实现括号的自动补全功能
A: (electric-pair-mode t)

Q: 如何修改文件名?
A: 在文件列表buffer中C-x C-q,对buffer进行修改,修改之后C-x C-s保存。

Q: Emacs如何实现书签功能?
A:
快捷键 完整命令 功能
C-x r m bookmark-set 新建一个书签
未定义 bookmark-delete 删除一个书签
C-x r l bookmarks-menu-list 列出当前书签
C-x r b bookmark-jump 跳转到指定书签
未定义 bookmark-save 保存书签至~/.emac.bmk

Q:如何替换?
A:按M - %启动查找替换,输入要被替换的词,回车,然后输入要替换的词,再回车。
被替换的词会高亮起来,这时,输入y替换并跳到下一个,输入n忽略并跳到下一个,输入q结束,输入!替换剩下的全部。
一些常用的选项:
  C - g 中断查找替换过程。
  ^ 返回上一个替换点,按y继续下一个,如果不想替换上一个的话,用^返回到上一个,然后按 C - r 进入编辑,修改完后按C - M - c退出继续下一个。
  C - l 使当前匹配显示在文档中间。
  C - r 进入修改。

0 0
原创粉丝点击