78

例如,我想合并这样的文本:

CATEGORIES = ['Books',
        'Business',
        'Education',
        'Entertainment',
        'Finance',
        'Games',
        'Healthcare & Fitness',
        'Lifestyle',
        'Medical',
        'Music',
        'Navigation',
        'News',
        'Photography',
        'Productivity',
        'Reference',
        'Social Networking',
        'Sports',
        'Travel',
        'Utilities',
        'Weather',
        'All',  ]

进入

CATEGORIES = ['Books', 'Business', 'Education', 'Entertainment', 'Finance', 'Games', 'Healthcare & Fitness', 'Lifestyle', 'Medical', 'Music', 'Navigation', 'News', 'Photography', 'Productivity', 'Reference', 'Social Networking', 'Sports', 'Travel', 'Utilities', 'Weather', 'All', ]
4

6 回答 6

117

在命令模式下:

[range]j[lines]

例如:在这里你想做整个缓冲区:

%j

如果您只想从当前光标位置执行 10 行:

j10

如果您不想用空格替换新行,请使用!after j

%j!
j!10

对于 uberfancy:

5j20

它将转到第 5 行,并加入接下来的 20 行。

于 2011-07-05T02:38:11.227 回答
48

最直观的方法是使用 Vim 视觉线模式Shift+ v。您所要做的就是选择要合并到一行的内容,然后按Shift+ j

于 2014-10-07T13:31:06.037 回答
14

使用J(大写)键。它将为您加入行列

检查线程以获取更多加入选项,并查看帮助页面。

于 2011-07-05T02:28:09.980 回答
6

对于该特定示例,以下命令将起作用:

:1, 21 j

或者

:%s/\n/ /g
于 2011-07-05T02:40:55.677 回答
3
:g/\[/,/\]/j

或者

/^CATEGORIES

:v//-1j

如果你有:

edit "Komputer" 
    ala 
    ala 
next 
edit "FortiGate" 
    ala 
    ala 
next

:g/edit/,/next/j
于 2018-03-02T22:06:47.343 回答
2

或者加入从左方括号到右方括号的所有内容(假设您的文件中有很多这些)并保持其他行不变,

:g/\[/,/\]/j

快速简单。

于 2014-11-19T15:53:32.953 回答