简体   繁体   English

如何在emacs组织模式中选择表的列

[英]How to select a column of a table in emacs org mode

I can't find my way around copying a column, or a series of them, from a table. 我无法找到从表中复制列或其中一系列的方法。

The only solution I found so far is to copy the whole table and then delete the columns I don't need. 到目前为止我找到的唯一解决方案是复制整个表,然后删除我不需要的列。

I suppose there must be another easier way for this. 我想必须有另一种更简单的方法。 Maybe I am just too tired to realize how to do it. 也许我太累了,不知道该怎么做。

I think the easiest way would be to take advantage of emacs rectangles 我认为最简单的方法是利用emacs矩形

  1. To create your rectangle, put your cursor at one of the corners of the rectangle you want to create. 要创建矩形,请将光标放在要创建的矩形的一个角上。

  2. Use C-SPC , or whatever you have set-mark-command set to. 使用C-SPC ,或任何set-mark-command设置为。

  3. Place your cursor at the diagonal corner of your rectangle. 将光标放在矩形的对角线上。

  4. Use Cx rr r to copy the rectangle to the register named r 使用Cx rr r将矩形复制到名为r的寄存器中

  5. Use Cx ri r to insert the rectangle that is being held in the register named r . 使用Cx ri r插入名为r的寄存器中保存的矩形。

Following this process will copy and insert the columns that you want. 执行此过程后,将复制并插入所需的列。 You may need to repeat this process if the columns are not adjacent. 如果列不相邻,则可能需要重复此过程。

NOTE 注意

I am using a bolded r to denote that this is technically a name of the register, and not some special input. 我使用粗体r来表示这在技术上是寄存器的名称,而不是一些特殊的输入。

If you specifically want to copy the column(s) into another org table (or indeed back into the original table), there's support for that. 如果您特别想将列复制到另一个组织表(或者实际上回到原始表中),那么就支持这一点。

See Ch f org-table-copy-region RET 请参见Ch f org-table-copy-region RET

It works much like the regular rectangle commands, so it's not a better interface for selecting the column; 它的工作原理与常规矩形命令非常相似,因此它不是选择列的更好界面; but the associated paste command is smart about what it does with the content. 但关联的粘贴命令对于它对内容的作用明智的。

I you are planning to use emacs rectangle command you avoid the use of registers by using the command copy-rectangle-as-kill bound Cx r Mw , execute the command after selecting a region this will copy the rectangle (see this for an example of how marking rectangles works). 我打算使用emacs矩形命令,通过使用命令copy-rectangle-as-kill绑定Cx r Mw来避免使用寄存器,选择一个区域后执行命令将复制矩形(请参阅示例标记矩形如何工作)。 Then you can paste the copied retangle by doing Cx r y . 然后你可以通过执行Cx r y来粘贴复制的侦听。

UPDATE UPDATE

The page org-mode hacks describes a way to copy columns using org-table formulas. 页面组织模式黑客描述了使用org-table公式复制列的方法。 You will need to name the table. 您需要为表命名。

Here is an example of using table formulas to copy columns from another table 下面是使用表公式从另一个表复制列的示例

Suppose you have following table named FOO , it is necessary to name the table for referring it from table formulas. 假设您有以下名为FOO表,则必须将该表命名为从表公式中引用它。

#+TBLNAME: FOO
| 0 | 2 | 1 |
| 1 | 3 | 2 |
| 2 | 4 | 3 |

You want to copy the columns 1 and 3 from table FOO to column 1 and 3 of the following table (lets call it B) 您想要将表FOO中的第1列和第3列复制到下表的第1列和第3列(将其称为B)

|  | 5 |  |
|  | 6 |  |
|  | 7 |  |

The following formula will do the trick, you will need to copy the formula below the table B and move cursor on the formula and do Cc Cc 下面的公式将起到作用,您需要复制表B下面的公式并将光标移动到公式上并执行Cc Cc

#+TBLFM: $1=remote(FOO,@@#$1)::$2=remote(FOO,@@#$3)

The table B will be converted to the following 表B将转换为以下内容

| 0 | 5 | 1 |
| 1 | 6 | 2 |
| 2 | 7 | 3 |

You can read about the syntax of the org table formulas here , basically $N refers to Nth column, @N refers to Nth row. 您可以在这里阅读组织表公式的语法,基本上$N表示第N列, @N N表示第N行。 @# and $# can be used instead of N to refer the row and column where the current value goes. 可以使用@#$#代替N来引用当前值所在的行和列。 remote(table-name, @N$N) refers to the Nth row and Nth column of the table table-name . remote(table-name, @N$N)是指table table-name的第N行和第N列。 :: concats multiple formulas. :: concats多个公式。

I too had trouble using the standard rectangle operations. 我也无法使用标准矩形操作。 When moving to the next column, all of all of the rows between the point and the mark were highlighted. 移动到下一列时,点和标记之间的所有行都会突出显示。 When I tried copying columns by formula as described above and in the org mode hacks, org threw errors if the column's values were non-numeric with more than one word. 当我尝试按照上面描述的公式和组织模式hacks复制列时,如果列的值不是带有多个单词的数字,则组织会抛出错误。

But a good hint about cutting and pasting revealed that the problem is the initial direction of motion of the cursor. 但是关于切割和粘贴的一个很好的暗示表明问题是光标运动的初始方向。 Moving first rightward to the next column, then down highlights the correct region. 首先向右移动到下一列,然后向下突出显示正确的区域。 Standard rectangle operations then work correctly. 然后标准矩形操作正常工作。

The "native" way in org mode is already covered in the answer by user2053036; 用户2053036在答案中已经涵盖了组织模式中的“本地”方式; I just wanted to add that in the simpler context, "to copy a column within a table": Let's say you have this table 我只是想在更简单的上下文中添加“复制表中的列”:假设你有这个表

| hello | world | | is | good |

And want to repeat column 2 in column 3. 并希望重复第3列中的第2列。

Steps: 脚步:

  1. Place the cursor after the bottom right | 将光标放在右下角后面 of the table 的表
  2. Open a new column to the right using keys Alt-Shift-<right> 使用Alt-Shift-<right>键打开右侧的新列

| hello | world | | | is | good | |

  1. Add the "row copy from" formula (for example by putting cursor to row 1 column 3 and typing =$1 Cc Cc ; or just type the TBLFM below the table and jump to step 4) 添加“行复制自”公式(例如,将光标放到第1行第3列并键入=$1 Cc Cc ;或者只需在表格下方输入TBLFM并跳转到第4步)

| hello | world | hello | | is | good | | #+TBLFM: $3=$1

  1. Place the cursor on the TBLFM and type Cc Cc 将光标放在TBLFM上并键入Cc Cc

| hello | world | hello | | is | good | is | #+TBLFM: $3=$1

That will copy column 1 to column 3. 这会将第1列复制到第3列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM