Reputation: 1757
Whenever I paste a text, vim always tell me how many lines I pasted on the bottom left. Eg it says "6 more lines".
Is it possible to programmatically access that number?
Or, access total line on given register?
I'm gonna use the number to count how many macro should I execute. Eg. vim says "6 more lines", then I type 6@q.
Upvotes: 2
Views: 71
Reputation: 11820
fun! MacroOverChange(macroname)
let l:how_many = line("']") - line("'[") + 1
execute "normal! ". l:how_many . "@" . a:macroname
endfun
:call MacroOverChange("a")
com -nargs=1 Mover :call MacroOverChange(<f-args>)
nnoremap <leader>m :Mover<space>
The command Mover (Mnemonic for "Macro Over") accepts arguments, for instance, if you want to run Mover macro 'a', just type:
:Mover a
The map allows you to type <leader>m
and get the following
:Mover |
Where | is the cursor point
A better function that runs over exactly last changed/yanked block. The advantage of this function is that it runs exactly over the last yanked/changed block
fun! RunMacroOver(macroname)
execute "'[,']normal @". a:macroname
endfun
com -nargs=1 Rover :call RunMacroOver(<f-args>)
nnoremap <leader>r :Rover<space>
To avoid creating files in your system in order to test these functions copy them in yout browser and run:
:@+
If you paste these line in a vim buffer you can select a paragraph, for example and yank, that will place the copied text into default register @"
and you can make those lines active making: :@"
OBS: Just avoid copying lines with :
Upvotes: 1
Reputation: 94676
Calculate the difference between the line of mark '[
and ']
(first and last lines of yanked text):
:echo line("']") - line("'[") + 1
Please note the marks are for any change, not only yanks, so use the expression right after yanking.
Upvotes: 2