Mapping <Shift>-Arrows to selecting characters/lines

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

I completed @escrafford mapping with insert mode's ones:

" shift+arrow selection
nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>
imap <S-Up> <Esc>v<Up>
imap <S-Down> <Esc>v<Down>
imap <S-Left> <Esc>v<Left>
imap <S-Right> <Esc>v<Right>

Also mapping usual copy/cut/paste like this you can return to insert mode after select+copy, for example.

vmap <C-c> y<Esc>i
vmap <C-x> d<Esc>i
map <C-v> pi
imap <C-v> <Esc>pi
imap <C-z> <Esc>ui

Now you can start a shift+arrow selection from any mode, then C-c to copy, and then C-v to paste. You always end in insert mode, so you have also C-z to undo.

I think this approaches more to the 'expected standard' behaviour for a text editor yu are asking for.


Slightly different from progo's answer - this gives the same feel as mac apps normally have:

nmap <S-Up> v<Up>
nmap <S-Down> v<Down>
nmap <S-Left> v<Left>
nmap <S-Right> v<Right>
vmap <S-Up> <Up>
vmap <S-Down> <Down>
vmap <S-Left> <Left>
vmap <S-Right> <Right>

The differences being switch to visual mode instead of visual line mode, and not losing the initial up/down etc keystroke.

Tags:

Vi

Vim