Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM range line number registers

Tags:

git

vim

Is there a register or variable that holds the line numbers for currently selected range?

line(".") works as for the current line but is there one for in a visual range?

EDIT

As mentioned below the '< and '> registers hold the beginning and ending lines.

What I ended up doing in addition to using the above was writing a function in VimScript which takes those line numbers and executes an external command, I'll include it below:

function! Github(line1, line2)
    execute "!github -f " . expand("%") . " -l " . a:line1 . " -n " . a:line2
endfunction
com! -range Github call Github(<line1>, <line2>)

I'm brand new to VimScript but from what I gathered from an initial google search, the above function accepts a range. I then take the beginning and ending line numbers and use them to execute the external script github which interfaces with the Github API and/or opens a browser to a github page based on the git info.

like image 582
lukecampbell Avatar asked Feb 19 '23 22:02

lukecampbell


1 Answers

  • '< and '> respectively.

    So: line("'<") and line("'>") should be what you expect

  • Also,

    :'<,'>sort
    

    to sort the last visual selection

  • `< to jump to the start of the last visual selection (also see :he v_o)

  • Finally, if 'cpoptions' does not include *, you can use :* as a synonym for :'<,'>:

    :se cpoptions-=*
    :*sort
    
like image 57
sehe Avatar answered Feb 21 '23 11:02

sehe