I have this function which displays line numbers. I want it to be called in different ways:
- from a command, specifying the lines as arguments
- with a visual selection, printing the first and last line numbers of the selection
- with a motion, printing the current line and the line at the end of the motion
So far I have the first two ones:
command! -nargs=* PL :call PrintLines('command',<f-args>)
vnoremap <silent> P :<C-U>call PrintLines('visual')<CR>
function! PrintLines(type,...)
" Get the lines to fold around
if a:type == 'command'
let l:line_before = a:000[0]
let l:line_after = a:000[1]
elseif a:type == 'visual'
let l:line_before = line("'<")
let l:line_after = line("'>")
endif
echo l:line_before
echo l:line_after
endfunction
But I can't figure out the way to use this with a motion. Ideally it would be possible to do something like:
nnoremap P{motion} :<C-U>call('normal')<CR>
And use it like this:
Pib