Mapping -Arrows to selecting characters/lines

前端 未结 8 1060
再見小時候
再見小時候 2020-12-29 03:55

I started to use vim recently, but I miss the character/line selection methods from other text editors. By default vim maps ,

相关标签:
8条回答
  • 2020-12-29 04:43

    Vim doesn't bend to that easily in my opinion. The terminal one doesn't even recognize Shift-Up in my case! I thought the v (character-wise selection) or V (line-wise selection) was among the easier concepts to learn about vi/vim.

    If this works (can't test right now), this is something you'll want:

    " activate visual mode in normal mode
    nmap <S-Up> V
    nmap <S-Down> V
    " these are mapped in visual mode
    vmap <S-Up> k
    vmap <S-Down> j
    " 
    " etc...
    " similarly <S-Left>, <S-Right> for v
    
    0 讨论(0)
  • 2020-12-29 04:53

    There's an specific option for this: keymodel:

    'keymodel' 'km'     string  (default "")
                global
                {not in Vi}
        List of comma separated words, which enable special things that keys
        can do.  These values can be used:
           startsel Using a shifted special key starts selection (either
                Select mode or Visual mode, depending on "key" being
                present in 'selectmode').
           stopsel  Using a not-shifted special key stops selection.
        Special keys in this context are the cursor keys, <End>, <Home>,
        <PageUp> and <PageDown>.
        The 'keymodel' option is set by the |:behave| command.
    

    TL;DR: To enable the behavior you want, use:

    set keymodel=startsel
    

    If you also want to leave visual mode when using <Up> or <Down> without <Shift> pressed, you can use:

    set keymodel=startsel,stopsel
    
    0 讨论(0)
提交回复
热议问题