为什么小写[i]在可视块模式下不起作用?

时间:2015-02-05 10:11:55

标签: vim keyboard-shortcuts insertion

我经常忘记如何以视觉块模式插入并再次阅读the answer Shift+i

正如Honghe.Wu在评论中所说:

  

为什么小写 i 在可视模式下不起作用?

技术原因是什么?

2 个答案:

答案 0 :(得分:6)

因为 i a 在所有视觉模式下的行为都不像普通模式那样 i a < / kbd>用于将选择扩展到文本对象。正如您在:help visual-operators中看到的那样:

4. Operating on the Visual area

The operators that can be used are:
    ~   switch case                 
    d   delete                      
    c   change (4)                  
    y   yank                        
    >   shift right (4)                 
    <   shift left (4)                  
    !   filter through external command (1)     
    =   filter through 'equalprg' option command (1)    
    gq  format lines to 'textwidth' length (1)      

The objects that can be used are:
    aw  a word (with white space)           
    iw  inner word                  
    aW  a WORD (with white space)           
    iW  inner WORD                  
    as  a sentence (with white space)           
    is  inner sentence                  
    ap  a paragraph (with white space)          
    ip  inner paragraph                 
    ab  a () block (with parenthesis)           
    ib  inner () block                  
    aB  a {} block (with braces)            
    iB  inner {} block                  
    at  a <tag> </tag> block (with tags)        
    it  inner <tag> </tag> block            
    a<  a <> block (with <>)                
    i<  inner <> block                  
    a[  a [] block (with [])                
    i[  inner [] block                  
    a"  a double quoted string (with quotes)        
    i"  inner double quoted string          
    a'  a single quoted string (with quotes)        
    i'  inner simple quoted string          
    a`  a string in backticks (with backticks)      
    i`  inner string in backticks           

Additionally the following commands can be used:
    :   start Ex command for highlighted lines (1)  
    r   change (4)                  
    s   change                      
    C   change (2)(4)                   
    S   change (2)                  
    R   change (2)                  
    x   delete                      
    D   delete (3)                  
    X   delete (2)                  
    Y   yank (2)                    
    p   put                     
    J   join (1)                    
    U   make uppercase                  
    u   make lowercase                  
    ^]  find tag                    
    I   block insert                    
    A   block append                    

所以只需在可视块模式下使用block insert大写 I block append大写 A 命令。

答案 1 :(得分:4)

i命令在光标位置之前插入。在可视块模式下,光标位置(通常)代表选区的右下角角,光标位置包含在块中。

因此,i的语义不匹配,这就是为什么它被排除在Vim实现之外(添加它可能是对源代码的简单的单行更改)。语义匹配I(在任何文本之前插入)和A(在任何文本之后插入),这就是为什么这些在视觉中可用的原因阻止模式。