Why lowercase [i] does not work in visual block mode?

后端 未结 2 511
小鲜肉
小鲜肉 2021-01-13 21:34

I often forget how to insert in visual block mode and read again the answer Shift+i.

As Honghe.Wu wonders in his comment:

Why lowercase i

相关标签:
2条回答
  • 2021-01-13 22:03

    The i command inserts before the cursor position. In visual block mode, the cursor position (usually) represents the bottom right corner of the selection, and the cursor position is included in the block.

    So, the semantics of i wouldn't match, and that's why it was left out of the Vim implementation (adding that would probably be a simple one-line change to the source code). The semantics do match for I (insert before any text) and A (insert after any text), that's why those are available in visual block mode.

    0 讨论(0)
  • 2021-01-13 22:19

    The reason because i and a are not behave like in normal mode in all visual modes is that i and a are used to extend the selection to text objects. As you can see in :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                    
    

    So just use the block insert uppercase I or the the block append uppercase A commands in visual block mode.

    0 讨论(0)
提交回复
热议问题