TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Merge multiple lines in Vim

30 点作者 vgnet将近 13 年前

4 条评论

SeoxyS将近 13 年前
I posted my solution on StackOverflow[1], but I like my way better than the top post:<p><pre><code> Here's how I'd do it (with the cursor on the first line): qama:5y$'a$p:5dd'ajq3@a You need to know two things: - The line number on which the first line of the second group starts (5 in my case), and the number of lines in each group (3 in my example). Here's what's going on: `qa` records everything up to the next `q` into a "buffer" in `a`. `ma` creates a mark on the current line. `:5` goes to the next group. `y$` yanks the rest of the line. `'a` returns to the mark, set earlier. `$p` pastes at the end of the line. `:5` returns to the second group's first line. `dd` deletes it. `'a` returns to the mark. `jq` goes down one line, and stops recording. `3@a` repeats the action for each line (3 in my case) </code></pre> [1]: <a href="http://stackoverflow.com/questions/10760326/merge-multiple-lines-in-vim/10762846#10762846" rel="nofollow">http://stackoverflow.com/questions/10760326/merge-multiple-l...</a>
评论 #4026680 未加载
评论 #4026990 未加载
mdonahoe将近 13 年前
I assume most people interested enough in vim to click on the comments with will have heard of Vimgolf.<p><a href="http://vimgolf.com/" rel="nofollow">http://vimgolf.com/</a><p>But if not, it is a great way to learn the less obvious tricks that Vim has to offer.
评论 #4027128 未加载
jakejake将近 13 年前
I can't imagine a situation where I'd need to join text this way, but it's impressive to see the powerful functions possible with vim. thanks for sharing!
评论 #4026570 未加载
评论 #4026120 未加载
tux1968将近 13 年前
Using a file with the same input of the top answer:<p>/harder&#60;enter&#62;1Gqa''dd''pkJ0jq3@a<p>Edit: notice that those are each 2 single quotes, not "