一千萬個為什麽

搜索

將區域附加到相同長度的另一個區域的行的末尾

以下是我感興趣的兩種情況:

案例1:相同長度的線條

鑒於一些線條

const int name1
const int name2
const int name3
const int name4  

和其他一些行

= 1
= 2
= 3
= 4

我想將其他行移到第一行的末尾。

const int name1 = 1
const int name2 = 2
const int name3 = 3
const int name4 = 4

是否有捷徑可尋?

案例2:不同長度的線條

在這個cae中,第一個區域的線條長度不同:

const int someName
const int anotherName
const int yetAnotherName
const int name  

我仍然希望將其他行移動到第一行的末尾,如下所示:

const int someName = 1
const int anotherName = 2
const int yetAnotherName = 3
const int name = 4

是否有捷徑可尋?

最佳答案

There is an easy 解 to your updated question too, but you will need to install the Multiple Cursors package, also available through Melpa.

步驟1.殺死/剪切矩形 (same as before)

▮= 1
 = 2
 = 3
 = 4▮
  • Select the region shown above between the two points.
  • C-x r k - Kill/cut that rectangular region between the two points.

第2步。將剛剛殺死的矩形拉到您選擇的位置

const int someName       ▮
const int anotherName
const int yetAnotherName
const int name
  • Bring the point at the above shown location
  • Note that this location needs to be at any point in the column that's not occupied by any of the below lines. If you can imagine a vertical line closest to the left which does not cut any of those 4 lines, bring the point to the right of that line.
  • C-x r y- Yank/paste the killed rectangle

這將產生以下結果

const int someName       = 1▮
const int anotherName    = 2
const int yetAnotherName = 3
const int name           = 4
  • 現在我們需要刪除 = 符號的變量名之間的額外空格。

第3步。刪除額外空間

對於此步驟,首先將指向第一個 = 符號,如下所示(該點隱藏在其下面的 = 符號)。

const int someName       ▮ 1
const int anotherName    = 2
const int yetAnotherName = 3
const int name           = 4
  • Create Multiple Cursors at all = signs: M-3 C->. C-> is bound to mc/mark-next-like-this.

那會給你這個; = 標誌仍隱藏在遊標下方。

const int someName       ▮ 1
const int anotherName    ▮ 2
const int yetAnotherName ▮ 3
const int name           ▮ 4
  • C-SPC M-b M-f BKSPACE SPC RET - Delete any space between the multiple cursors and the words before them and instead insert a single space.

結果

const int someName = 1
const int anotherName = 2
const int yetAnotherName = 3
const int name = 4

老回答

使用 rectangle 是我想到的第一件事。

步驟1.殺死/剪切矩形

▮= 1
 = 2
 = 3
 = 4▮
  • Select the region shown above between the two points.
  • C-x r k - Kill/cut that rectangular region between the two points.

第2步。將剛剛殺死的矩形拉到您選擇的位置

const int name1 ▮
const int name2
const int name3
const int name4
  • Bring the point at the above shown location
  • C-x r y- Yank/paste the killed rectangle

結果

const int name1 = 1
const int name2 = 2
const int name3 = 3
const int name4 = 4

學習

轉載註明原文: 將區域附加到相同長度的另一個區域的行的末尾