I'm trying to deconstruct a .vimrc file to learn. I'm at a loss to determine what this does. Typing the ] and _$ mapped keys in visual mode doesn't seem to do anything useful. Maybe I'm missing something.

vmap <silent>       ]   $"yygv_$
vmap <silent><expr> _$  Under_dollar_visual()

function! Under_dollar_visual ()
    " Locate block being shifted...
    let maxcol = max(map(split(@y, "\n"), 'strlen(v:val)')) + getpos("'<")[2] - 2

    " Return the selction that does the job...
    return maxcol . '|'

1 Answer 1

vmap <silent>       ]   $"yygv_$

This selects to the end of the line ($), copies everything to the @y register ("yy), visually selects the block (gv) and then calls _$.

vmap <silent><expr> _$  Under_dollar_visual()

<expr> means that the result of the expression is evaluated (see help map-expression).

In Under_dollar_visual, maxcol is set to

let maxcol = max(map(split(@y, "\n"), 'strlen(v:val)')) 

the longest line of the text in the @y register that was just copied

+ getpos("'<")[2] - 2

plus the start column of the block minus two (without the last character).

return maxcol . '|'

Finally it returns the keys that will be evaluated by vim (| = To screen column [count]).

For example if you select a visual-block (indicated by X)


and press ], you'll get:


(if the cursor was on the last line) which is the same as if you had typed 10| with the initial selection.

  • also, I think <silent> means dont show the command output in the command line area Feb 20, 2017 at 1:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.