emacs 代码提示_Emacs提示和方法

emacs 代码提示

With Emacs, I feel happy. I love the rich functions of Emacs, such as compiling, quickly jumping to the lines with compilation error and debugging with gdb, and more. I ever wrote small tips posts about Emacs before. But it is a good idea to put them together and keep adding new ones. Here comes this post on Emacs tip and howtos, more or less like a cheat sheet and FAQ. This post is kept being updated with new tips and howtos.

有了Emacs,我感到很高兴。 我喜欢Emacs的丰富功能,例如编译,带有编译错误的行以及使用gdb进行调试等等。 我曾经写过有关Emacs的小技巧文章。 但是将它们放在一起并不断添加新的是一个好主意。 这是有关Emacs技巧和方法的帖子,或多或少像是备忘单和常见问题解答。 此帖不断更新,有新的技巧和方法。

您的Emacs配置文件是什么? (What is your Emacs configuration file? )

First thing first. I share my Emacs configuration file (‘~/.emacs’) on github. Please find it here: Zhiqiang’s Emacs configuration file.

首先是第一件事。 我在github上共享我的Emacs配置文件('〜/ .emacs')。 请在此处找到: Zhiqiang的Emacs配置文件

Emacs教程 (Emacs tutorials )

Emacs itself provides a tutorial to start with. To view it, execute this command in Emacs:

Emacs本身提供了一个教程作为开始。 要查看它,请在Emacs中执行以下命令:

C-h t

Many Emacs tutorials are online. I highly recommend the A Tutorial Introduction to GNU Emacs by Keith Waclena.

许多Emacs教程在线。 我强烈推荐Keith Waclena撰写的GNU Emacs教程简介

几个Emacs备忘单 (Several Emacs cheat sheets )

Here are several Emacs cheat sheets online:

这是几张Emacs在线备忘单:

Emacs Basics:
http://doors.stanford.edu/~sr/computing/emacs.html

Emacs基础知识:
http://doors.stanford.edu/~sr/computing/emacs.html

Emacs Commands List:
http://lpn.rnbhq.org/tools/xemacs/emacs_ref.html

Emacs命令列表:
http://lpn.rnbhq.org/tools/xemacs/emacs_ref.html

GNU Emacs Reference Card:
http://refcards.com/docs/gildeas/gnu-emacs/emacs-refcard-a4.pdf

GNU Emacs参考卡:
http://refcards.com/docs/gildeas/gnu-emacs/emacs-refcard-a4.pdf

Emacs写入只读文件 (Emacs Write to Read-only Files )

Emacs has the power of writing to read-only files as Vim (with “w!”). This is how to do it:

Emacs具有将只读文件作为Vim写入的能力(带有“ w!”)。 这是怎么做的:

We can clear the buffer text’s read-only flag with

我们可以使用以下命令清除缓冲区文本的只读标志

C-x C-q

Emacs中删除^ M从文件 (Emacs Remove ^M From Files )

‘^M’ characters are usually generated by a editor in Windows. This post introduces how to remove these ‘^M’ characters in Emacs.

“ ^ M”字符通常由Windows中的编辑器生成。 这篇文章介绍了如何在Emacs中删除这些'^ M'字符。

First go to top of buffer, then:

首先转到缓冲区顶部,然后:

M-x replace-string C-q C-m RET

Here,

这里,

M-%

can be used for

可用于

M-x replace-string

The control-q will allow typing control characters into the input buffer.

control-q将允许在输入缓冲区中键入控制字符。

生成并在Emacs再生的ETag (Generate and regenerate ETAGS in Emacs )

Add the following lines to ‘~/.emacs’

将以下行添加到“〜/ .emacs”


;; =================== etags =====================
(defvar tags-cmd "etags -R ./* 2>/dev/null")

(defun regen-tags ()
  "Regenerate the tags file for the current working directory"
  (interactive)
  (let ((tag-file (concat default-directory "TAGS")))
    (shell-command tags-cmd)
    (visit-tags-table tag-file)))
;; =================== end etags =====================

To regnerate ETAGS in the current directory, simply run these command in Emacs:

要在当前目录中注册ETAGS,只需在Emacs中运行以下命令:

M-x regen-tags

自动完成 (Auto completion )

Auto Complete Mode is the most intelligent auto-completion extension. Auto Complete Mode provides visual interfaces, reduced overhead of completion by using statistic method and extensibility. A Demo is available.

自动完成模式是最智能的自动完成扩展。 自动完成模式提供了可视化界面,通过使用统计方法和可扩展性减少了完成的开销。 演示可用。

On Fedora Linux, we can install Auto Complete Mode by:

在Fedora Linux上 ,我们可以通过以下方式安装“自动完成模式”:

# yum install emacs-auto-complete emacs-auto-complete-el

Auto Complete Mode is easy to use — just type your code!

自动完成模式易于使用-只需输入代码即可!

You can use ‘TAB’ to expand and select. You can also use ‘M-p’ and ‘M-n’ to select previous or next possible choice, and ‘RET’ to complete your selection. This should complete most of the auto completion usage. For more usage, please refer to Auto Complete Mode User Manual.

您可以使用“ TAB”展开并选择。 您还可以使用“ M-p”和“ M-n”选择上一个或下一个可能的选择,并使用“ RET”完成选择。 这将完成大多数自动完成用法。 有关更多用法,请参阅《 自动完成模式用户手册》

转到特定线 (Goto a specific line )

Emacs supports jumping to a specific line:

Emacs支持跳转到特定行:

M-g M-g

Then enter the line number and RET.

然后输入行号和RET。

跳到下一个和上一个误差 (Jump to next and previous error )

In the compile mode, you can jump to the next/previous error in the compile buffer by:

在编译模式下,可以通过以下方法跳转到编译缓冲区中的下一个/上一个错误:

M-g M-n

and

M-g M-p

跳转到函数的开头和结尾 (Jump to beginning and end of a function )

The functions beginning-of-defun and end-of-defun works with most programming modes in Emacs that jumps to the beginning and end of the function/class definition.

定义开始和定义结束功能可在Emacs中的大多数编程模式下使用,该模式会跳转到函数/类定义的开始和结束。

The commands are

这些命令是

C-M-a

and

C-M-e

This will make editing code much easier.

这将使编辑代码更加容易。

在括号结构中移动 (Moving in the Parenthesis Structure )

Move over groupings delimited by parentheses (or whatever else serves as delimiters in the language you are working with):

移动以括号分隔的分组(或其他任何以您使用的语言作为分隔符的分隔符):

C-M-n

Move forward over a parenthetical group (forward-list).

在圆括号组(前进列表)上前进。

C-M-p

Move backward over a parenthetical group (backward-list).

向后移到括号组(向后列表)上。

C-M-u

Move up in parenthesis structure (backward-up-list).

在括号结构(后退列表)中上移。

C-M-d

Move down in parenthesis structure (down-list).

在括号结构中向下移动(向下列表)。

Move between a brackets pair:

在括号对之间移动:

C-M-n for forward match and C-M-u for backward match.

CMn用于前向匹配,CMu用于后向匹配。

工作矩形 (Operating rectangles )

Rectangle commands operate on rectangular areas of the text: all the characters between a certain pair of columns, in a certain range of lines.

矩形命令在文本的矩形区域上操作:在一定范围的行中,一对特定列之间的所有字符。

To specify a rectangle for a command to work on, set the mark at one corner and point at the opposite corner. If point and the mark are in the same column, the region-rectangle is empty. If they are in the same line, the region-rectangle is one line high.

要为要执行的命令指定一个矩形,请将标记设置在一个角上,并将其指向相反的角。 如果点和标记在同一列中,则区域矩形为空。 如果它们在同一行中,则区域矩形为一行高。

C-x r k

Kill the text of the region-rectangle, saving its contents as the “last killed rectangle” (kill-rectangle).

杀死区域矩形的文本,将其内容另存为“最后杀死的矩形”(kill-rectangle)。

C-x r d

Delete the text of the region-rectangle (delete-rectangle).

删除区域矩形(delete-rectangle)的文本。

C-x r y

Yank the last killed rectangle with its upper left corner at point (yank-rectangle).

用点的左上角(yank-rectangle)拉最后一个杀死的矩形。

C-x r o

Insert blank space to fill the space of the region-rectangle (open-rectangle). This pushes the previous contents of the region-rectangle to the right.

插入空格以填充区域矩形(open-rectangle)的空间。 这会将区域矩形的先前内容推到右侧。

C-x r N

Insert line numbers along the left edge of the region-rectangle (rectangle-number-lines). This pushes the previous contents of the region-rectangle to the right.

沿着区域矩形(矩形数字线)的左边缘插入行号。 这会将区域矩形的先前内容推到右侧。

C-x r c

Clear the region-rectangle by replacing all of its contents with spaces (clear-rectangle).

通过用空格替换所有内容来清除区域矩形(clear-rectangle)。

M-x delete-whitespace-rectangle

Delete whitespace in each of the lines on the specified rectangle, starting from the left edge column of the rectangle.

从矩形的左边缘列开始,删除指定矩形上每行的空白。

C-x r t string 

Replace rectangle contents with string on each line (string-rectangle).

将矩形内容替换为每行上的字符串(字符串矩形)。

M-x string-insert-rectangle string 

Insert string on each line of the rectangle.

在矩形的每一行上插入字符串。

拼写检查 (Spell checking )

M-x ispell

Check and correct spelling of all words in the buffer. If the region is active, do it for all words in the region instead.

检查并纠正缓冲区中所有单词的拼写。 如果该区域处于活动状态,请改为对该区域中的所有单词进行操作。

M-x flyspell-mode

Enable Flyspell mode, which highlights all misspelled words.

启用Flyspell模式,该模式突出显示所有拼写错误的单词。

M-x flyspell-prog-mode

Enable Flyspell mode for comments and strings only.

为注释和字符串启用Flyspell模式。

Spell correcting

拼写校正

Skip this word—continue to consider it incorrect, but don’t change it here.

跳过此词-继续认为它是错误的,但请不要在此处更改。

a

Accept the incorrect word—treat it as correct, but only in this editing session.

接受不正确的词-将其视为正确,但仅在此编辑会话中进行。

撤消和重做 (Undo and redo )

Emacs has a powerful undo system. It allows you to recover any past state of a buffer.

Emacs具有强大的撤消系统。 它允许您恢复缓冲区的任何过去状态。

C-_

undo

撤消

C-g C-_

redo after a undo

撤消后重做

Performing some commands after a sequence of undo, all the undos are pushed to the operation stack, and the next undo undoes the last command. Multiple C-_ to redo what have been undone by C-_.

在一系列撤消操作之后执行一些命令,所有撤消操作将被推入操作堆栈,而下一个撤消操作将撤消最后一条命令。 多个C-_重做C-_撤消的操作。

显示行号 (Display line numbers )

Display line numbers:

显示行号:

M-x linum-mode

or

要么

M-x global-linum-mode

To enable it by default

默认启用

Add

(global-linum-mode t)

to ‘~/.emacs’.

到'〜/ .emacs'。

放置屏幕 (Position the screen )

We can position the screen by

我们可以通过以下方式定位屏幕

C-l

Invoking ‘C-l’ multiple times makes Emacs position the current line at the middle, top and bottom of the screen iteratively.

多次调用“ C-1”使Emacs迭代地将当前行定位在屏幕的中间,顶部和底部。

在Emacs更换 (Replace in Emacs )

Interactive find and replace

交互式查找和替换

M-x query-replace

or

要么

M-%

Batch replace

批量替换

M-x replace-string

设置Emacs的字体大小 (Set Emacs’s font size )

To set the font size to 12pt, put this line into ‘~/.emacs’:

要将字体大小设置为12pt,请将此行放入'〜/ .emacs'中:

(set-face-attribute 'default nil :height 120)

The value is in 1/10pt.

值是1 / 10pt。

Increase/decrease current instance of Emacs’s font size:

增加/减少Emacs字体大小的当前实例:

C-x C-+

and

C-x C--

隐藏Emacs的工具栏/菜单栏 (Hide Emacs’ toolbar / menubar )

To hide the toolbar completely, put this line into ‘~/.emacs’:

要完全隐藏工具栏,请将此行放入“〜/ .emacs”中:

(tool-bar-mode -1)

To hide the menubar:

要隐藏菜单栏:

(menu-bar-mode -1)

You can also toggle it by

您也可以通过以下方式切换

M-x tool-bar-mode

or

要么

M-x menu-bar-mode

在不移动光标位置的情况下杀死线 (Kill a line without moving the cursor position )

1. Using 2 ‘C-k’ with ‘C-a’ first can kill the current line. But there are easier methods as follows.

1.首先将2个'C-k'与'C-a'一起使用可以杀死当前行。 但是,有一些更简单的方法如下。

2. Use ‘kill-whole-line’

2.使用“ kill-whole-line”

C-S-Backspace

C-S-backspace (kill-whole-line) kills a whole line and its newline, no matter where the point within the line is.

无论行中的点在哪里,CS-backspace(kill-whole-line)都会杀死整条线及其换行符。

However, many text terminals will prevent you from typing the key sequence C-S-backspace.

但是,许多文本终端会阻止您键入键序列CS退格键。

3. Define your own key bindings

3.定义自己的键绑定

I prefer ‘C-c C-x’ to kill a whole line by putting this line into ‘~/.emacs’:

我更喜欢'Cc C-x'通过将这一行放入'〜/ .emacs'来杀死整行:

(global-set-key "C-cC-x" 'kill-whole-line)

复制在Emacs线 (Duplicate a line in Emacs )

Method 1. Using the keyboard

方法1。使用键盘

First, kill the current line (the line to duplicate)

首先,杀死当前行(要复制的行)

C-S-backspace

Then, yank it at the position where it should be duplicated

然后,将其拉到应复制的位置

C-y

Method 2. Define a function and bind it to ‘C-c C-k’:

方法2.定义一个函数并将其绑定到“ Cc C-k”:


    (defun copy-line (arg)
      "Copy lines (as many as prefix argument) in the kill ring"
      (interactive "p")
      (kill-ring-save (line-beginning-position)
                      (line-beginning-position (+ 1 arg)))
      (message "%d line%s copied" arg (if (= 1 arg) "" "s")))
   ;; optional key binding
   (global-set-key "C-cC-k" 'copy-line)

Script reference: http://emacswiki.org/emacs/CopyingWholeLines

脚本参考: http : //emacswiki.org/emacs/CopyingWholeLines

翻译自: https://www.systutorials.com/emacs-tips-and-howtos/

emacs 代码提示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值