如何在 Vim 中特定列的所有行中插入特定字符?

发布于 2024-11-09 00:49:33 字数 791 浏览 0 评论 0原文

 Dates
=======

 Name                                   | Date
-------------------------------------------------
* Battle of the Plains of Abraham       | September 13, 1759
* Proclamation Act                      | October   07, 1763
* Stamp Act                             | March     22, 1765
* Guy Carleton becomes Governor         | April     07, 1766
* Boston Tea Party                      | December  16, 1773
* Quebec Act                            |
* Declaration of Independance           | <====== # How do I insert this bar character
* Treaty of Paris                                 # along the whole column?
* Constitutional Act                
* French Revolution                 
* War of 1812

我希望能够插入该条形字符,而不必手动插入它。 虽然这在语法上不正确,但这应该是降价的。

 Dates
=======

 Name                                   | Date
-------------------------------------------------
* Battle of the Plains of Abraham       | September 13, 1759
* Proclamation Act                      | October   07, 1763
* Stamp Act                             | March     22, 1765
* Guy Carleton becomes Governor         | April     07, 1766
* Boston Tea Party                      | December  16, 1773
* Quebec Act                            |
* Declaration of Independance           | <====== # How do I insert this bar character
* Treaty of Paris                                 # along the whole column?
* Constitutional Act                
* French Revolution                 
* War of 1812

I want to be able to insert that bar character without having to manually go and insert it.
While this is not syntactically correct, this is supposed to be markdown.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

路还长,别太狂 2024-11-16 00:49:33

我只是一个初学者,但我是这样做的:

  • Cv进入Visual Block(在Windows上使用Cq
  • 选择列(运动键hjkl)
  • I
  • 输入文本
  • Esc

I'm only a beginner, but here's what I do:

  • C-v to enter Visual Block (Use C-q on windows)
  • Select column (motion keys hjkl)
  • I
  • Enter text
  • Esc
早茶月光 2024-11-16 00:49:33
%s/$/                                        /
v/|/s/^\(........................................\)/\1|/
%s/  *$//

一些注意事项:

  • 如果您处于 vi 的正常可视模式,则每行前面需要一个 :
  • 或者,您可以将这些命令放入命令文件中并键入 $ ex file : 。 cmds 但在这种情况下添加一个 x 作为第四行
  • 这可以通过在每一行附加空格,然后将右侧更改为 | 来实现。对于还没有 | 的行,然后删除所有尾随空格
%s/$/                                        /
v/|/s/^\(........................................\)/\1|/
%s/  *$//

Some notes:

  • You will need a : in front of each line if you are in vi's normal visual mode
  • Alternatively, you can put those commands in a command file and type $ ex file < cmds but in that case add an x as the fourth line
  • This works by appending blanks to each line, then changing the right one to a | for lines that don't already have a |, and then deleting any trailing blanks
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文