Vim 多行编辑就像在 sublimetext 中一样? [英] Vim multiline editing like in sublimetext?

查看:66
本文介绍了Vim 多行编辑就像在 sublimetext 中一样?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用 gvim,我不太明白 gvim 中的多行编辑是如何工作的.

I started to use gvim, and I can't quite understand how the multiline edit works in gvim.

例如:

原文:

asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;

ctrl+q, jjjjjj , $一切都被选中,然后我按 I 进行多行插入.

ctrl+q, jjjjjj , $ everything is selected, then i press I to do a multiline insert.

我的目的是像在第一行一样插入引号,然后按 Esc:

My intention is to insert quotes like in the first line, and then to press Esc:

asd "asd asd" asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;

发生了什么?我期望一种类似于 sublimetext 的行为:

What happened? I expected a behavior similar to sublimetext's one:

如果您不知道它是如何工作的,它只是对每一行重复操作.怎样才能做到这一点?vim 在这里做什么?

If you don't know how that works, it just repeats the actions for every line. How can achieve that? And what is vim doing here?

推荐答案

删除 Windows 兼容层,帮自己一个忙.

Do yourself a favor by dropping the Windows compatibility layer.

进入 Visual-Block 模式的常规快捷方式是 .

The normal shortcut for entering Visual-Block mode is <C-v>.

其他人已经处理过录制宏,这里有一些其他想法:

Others have dealt with recording macros, here are a few other ideas:

仅使用视觉块模式.

Using only visual-block mode.

  1. 将光标放在第二个单词上:

  1. Put the cursor on the second word:

asd |a|sd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;
asd asd asd asd asd;

  • 点击 进入 visual-block 模式并向底部展开您的选择:

  • Hit <C-v> to enter visual-block mode and expand your selection toward the bottom:

    asd [a]sd asd asd asd;
    asd [a]sd asd asd asd;
    asd [a]sd asd asd asd;
    asd [a]sd asd asd asd;
    asd [a]sd asd asd asd;
    asd [a]sd asd asd asd;
    asd [a]sd asd asd asd;
    

  • 点击I"获得:

    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    

  • 将光标放在第三个单词的最后一个字符上:

  • Put the cursor on the last char of the third word:

    asd "asd as|d| asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    asd "asd asd asd asd;
    

  • 点击 进入 visual-block 模式并向底部展开您的选择:

  • Hit <C-v> to enter visual-block mode and expand your selection toward the bottom:

    asd "asd as[d] asd asd;
    asd "asd as[d] asd asd;
    asd "asd as[d] asd asd;
    asd "asd as[d] asd asd;
    asd "asd as[d] asd asd;
    asd "asd as[d] asd asd;
    asd "asd as[d] asd asd;
    

  • 点击A"获得:

    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    

  • 使用 visual-block 模式和 Surround.vim.

    With visual-block mode and Surround.vim.

    1. 将光标放在第二个单词上:

    1. Put the cursor on the second word:

    asd |a|sd asd asd asd;
    asd asd asd asd asd;
    asd asd asd asd asd;
    asd asd asd asd asd;
    asd asd asd asd asd;
    asd asd asd asd asd;
    asd asd asd asd asd;
    

  • 点击 进入 visual-block 模式并向底部和右侧扩展您的选择:

  • Hit <C-v> to enter visual-block mode and expand your selection toward the bottom and the right:

    asd [asd asd] asd asd;
    asd [asd asd] asd asd;
    asd [asd asd] asd asd;
    asd [asd asd] asd asd;
    asd [asd asd] asd asd;
    asd [asd asd] asd asd;
    asd [asd asd] asd asd;
    

  • 点击 S" 用 ":

    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    

  • 使用 visual-line 模式和 :normal.

    With visual-line mode and :normal.

    1. 点击 V 选择整行并将其向底部展开:

    1. Hit V to select the whole line and expand it toward the bottom:

    [asd asd asd asd asd;]
    [asd asd asd asd asd;]
    [asd asd asd asd asd;]
    [asd asd asd asd asd;]
    [asd asd asd asd asd;]
    [asd asd asd asd asd;]
    [asd asd asd asd asd;]
    

  • 执行这个命令::'<,'>norm ^wi"eea"得到:>

  • Execute this command: :'<,'>norm ^wi"<C-v><Esc>eea"<CR> to obtain:

    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    asd "asd asd" asd asd;
    

    • :norm[al] 允许您在一系列行('<,'> 部分由 Vim 自动添加,意思是作用于选定区域")

      • :norm[al] allows you to execute normal mode commands on a range of lines (the '<,'> part is added automatically by Vim and means "act on the selected area")

        ^ 将光标放在该行的第一个字符上

        ^ puts the cursor on the first char of the line

        w 移动到下一个单词

        i" 在光标前插入一个 "

        是 Vim 在此上下文中输入控制字符的方式,这里是 用于退出插入模式

        <C-v><Esc> is Vim's way to input a control character in this context, here it's <Esc> used to exit insert mode

        ee 移动到下一个单词的末尾

        ee moves to the end of the next word

        a" 在光标后附加一个 "

        执行命令

        使用Surround.vim,上面的命令变成

        Using Surround.vim, the command above becomes

        :'<,'>norm ^wvees"<CR>
        

      • 这篇关于Vim 多行编辑就像在 sublimetext 中一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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