在Vim中插入列的缩进 [英] Inserting indentation for columns in Vim

查看:210
本文介绍了在Vim中插入列的缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在箭头之后插入一些间距,

使用Vim我真的是一个可视化模式的粉丝,允许您在列前插入文本。 >

 >一个
>两个
>可以通过< Ctrl-V> jjI< Esc>来完成三个

;

 >一个
>两个
>三




  • 进入可视模式< Ctrl -V>

  • 扩展可视选择 jj
  • >插入一些空格 I __
  • 将变化传播到所有块状视觉选择的行< Esc> ;



现在我有一个需要格式化的文本文件。这是它的样子:

  start() -  xxx 
initialize() - xxx
go() - xxx

现在我想对齐这个文本的一部分,像这样:
$ b $ pre $ start() - xxx
初始化() - xxx
go() - xxx

我得到的问题是我无法在每行中插入不同数量的缩进仅缩进一定数量的空格/标签是不够的。
如何缩进所有缩进文本必须在同一列对齐





编辑:我只想出了一个相当冗长和笨拙的方法:

$ ul

  • 找到字符串位置缩进: \\在这之前插入n(比如20):


  • 将这些空格的一部分删除回某个列(比如15): d | 15

  • 将这些步骤保存为一个宏,并根据需要重复该宏,


    ...非常丑陋的,但!!

    解决方案

    我没有任何vim插件好多了。
    这是我的解决方案:

    < Shift-V> jj:!column -ts -



    然后将 - 插入多行,就像您在问题中写的一样。
    $ b




    您也可以在插入时附加一些评论。


    Using Vim I'm really a fan of the visual mode that allows you to insert text before a column.

    Insert some spacing after the arrows,

    > one
    > two
    > three
    

    can be done via <Ctrl-V>jjI <Esc>:

    >   one
    >   two
    >   three
    

    • go to visual mode <Ctrl-V>,
    • extend visual selection jj,
    • insert some spaces I__,
    • propagate the change to all the lines of blockwise visual selection <Esc>

    Now I have a text file that needs some formatting. This is what it looks like:

    start() -- xxx
    initialize() -- xxx
    go() -- xxx
    

    Now I want to align part of this text to arrange it into columns like this:

    start()       -- xxx
    initialize()  -- xxx
    go()          -- xxx
    

    The problem I have is that I cannot insert a different amount of indentation into each line and merely indenting a fixed amount of spaces/tabs is insufficient. How can you do an indentation where all indented text will have to be aligned at the same column?


    EDIT: I only figured out a rather verbose and unwieldy method:

    • find the string position to indent from: \--,
    • insert n (let's say 20) spaces before that: 20i <Esc>,
    • delete a part of those spaces back to a certain column (let's say 15): d|15,
    • save those steps as a macro and repeat the macro as often as necessary,

    ...very ugly, though!

    解决方案

    I'm much better off without any vim plugins. Here is my solution:

    <Shift-V>jj:!column -ts --

    Then insert -- into multiple lines just as you wrote in the question.


    You can also append a number of comments at insertion time.

    :set virtualedit=all

    <Ctrl-V>jjA-- xxx<Esc>

    这篇关于在Vim中插入列的缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆