@@ -612,52 +612,54 @@ end
612
612
--- @param add boolean
613
613
local function matchAddCursor (direction , add )
614
614
mc .action (function (ctx )
615
- local mainCursor = ctx :mainCursor ()
616
- local cursorChar
617
- local cursorWord
618
- local searchWord
619
- if not mainCursor :hasSelection () then
620
- local c = mainCursor :col ()
621
- cursorChar = string.sub (mainCursor :getLine (), c , c )
622
- cursorWord = mainCursor :getCursorWord ()
623
- if cursorChar ~= " "
624
- and isKeyword (cursorChar )
625
- and string.find (cursorWord , cursorChar , 1 , true )
626
- then
627
- searchWord = true
628
- mainCursor :feedkeys (' "_yiw' )
629
- end
630
- end
631
- addCursor (ctx , function (cursor )
632
- local regex
633
- local hasSelection = cursor :hasSelection ()
634
- if hasSelection then
635
- regex = " \\ C\\ V" .. escapeRegex (
636
- table.concat (cursor :getVisualLines (), " \n " ))
637
- if vim .o .selection == " exclusive" then
638
- regex = regex .. " \\ v.*\\ n"
639
- end
640
- if cursor :mode () == " V" or cursor :mode () == " S" then
641
- cursor :feedkeys (cursor :atVisualStart () and " 0" or " o0" )
642
- elseif not cursor :atVisualStart () then
643
- cursor :feedkeys (" o" )
615
+ for _ = 1 , vim .v .count1 do
616
+ local mainCursor = ctx :mainCursor ()
617
+ local cursorChar
618
+ local cursorWord
619
+ local searchWord
620
+ if not mainCursor :hasSelection () then
621
+ local c = mainCursor :col ()
622
+ cursorChar = string.sub (mainCursor :getLine (), c , c )
623
+ cursorWord = mainCursor :getCursorWord ()
624
+ if cursorChar ~= " "
625
+ and isKeyword (cursorChar )
626
+ and string.find (cursorWord , cursorChar , 1 , true )
627
+ then
628
+ searchWord = true
629
+ mainCursor :feedkeys (' "_yiw' )
644
630
end
645
- else
646
- if cursorChar == " " then
647
- regex = " \\ v^$"
648
- elseif searchWord then
649
- regex = " \\ v<\\ C\\ V" .. escapeRegex (cursorWord ) .. " \\ v>"
631
+ end
632
+ addCursor (ctx , function (cursor )
633
+ local regex
634
+ local hasSelection = cursor :hasSelection ()
635
+ if hasSelection then
636
+ regex = " \\ C\\ V" .. escapeRegex (
637
+ table.concat (cursor :getVisualLines (), " \n " ))
638
+ if vim .o .selection == " exclusive" then
639
+ regex = regex .. " \\ v.*\\ n"
640
+ end
641
+ if cursor :mode () == " V" or cursor :mode () == " S" then
642
+ cursor :feedkeys (cursor :atVisualStart () and " 0" or " o0" )
643
+ elseif not cursor :atVisualStart () then
644
+ cursor :feedkeys (" o" )
645
+ end
650
646
else
651
- regex = " \\ C\\ V" .. escapeRegex (cursorChar )
647
+ if cursorChar == " " then
648
+ regex = " \\ v^$"
649
+ elseif searchWord then
650
+ regex = " \\ v<\\ C\\ V" .. escapeRegex (cursorWord ) .. " \\ v>"
651
+ else
652
+ regex = " \\ C\\ V" .. escapeRegex (cursorChar )
653
+ end
652
654
end
653
- end
654
- cursor : perform ( function ( )
655
- vim . fn . search ( regex , ( direction == - 1 and " b " or " " ) )
656
- end )
657
- if hasSelection then
658
- cursor : feedkeys ( TERM_CODES . ESC )
659
- end
660
- end , { addCursor = add })
655
+ cursor : perform ( function ()
656
+ vim . fn . search ( regex , ( direction == - 1 and " b " or " " ) )
657
+ end )
658
+ if hasSelection then
659
+ cursor : feedkeys ( TERM_CODES . ESC )
660
+ end
661
+ end , { addCursor = add })
662
+ end
661
663
end )
662
664
end
663
665
@@ -681,18 +683,20 @@ local function searchAddCursor(direction, add)
681
683
return
682
684
end
683
685
mc .action (function (ctx )
684
- local mainCursor = ctx :mainCursor ()
685
- if mainCursor :hasSelection () then
686
- mainCursor :feedkeys (
687
- (mainCursor :atVisualStart () and " " or " o" )
688
- .. TERM_CODES .ESC
689
- )
686
+ for _ = 1 , vim .v .count1 do
687
+ local mainCursor = ctx :mainCursor ()
688
+ if mainCursor :hasSelection () then
689
+ mainCursor :feedkeys (
690
+ (mainCursor :atVisualStart () and " " or " o" )
691
+ .. TERM_CODES .ESC
692
+ )
693
+ end
694
+ addCursor (ctx , function (cursor )
695
+ cursor :perform (function ()
696
+ vim .fn .search (regex , (direction == - 1 and " b" or " " ))
697
+ end )
698
+ end , { addCursor = add })
690
699
end
691
- addCursor (ctx , function (cursor )
692
- cursor :perform (function ()
693
- vim .fn .search (regex , (direction == - 1 and " b" or " " ))
694
- end )
695
- end , { addCursor = add })
696
700
end )
697
701
end
698
702
@@ -752,39 +756,41 @@ end
752
756
--- @param add boolean
753
757
local function lineAddCursor (direction , add )
754
758
mc .action (function (ctx )
755
- local mainCursor = ctx :mainCursor ()
756
- local line , _ , offset = table.unpack (mainCursor :getPos ())
757
- if offset > 0 then
758
- addCursor (ctx , direction == - 1 and " k" or " j" , {
759
- addCursor = add ,
760
- remap = false ,
761
- })
762
- return
763
- end
764
- local virtCol = vim .fn .virtcol (" ." )
765
- local lastLine = vim .fn .line (" $" )
766
- local found = false
767
- while true do
768
- line = line + direction
769
- if line < 1 or line > lastLine then
770
- break
759
+ for _ = 1 , vim .v .count1 do
760
+ local mainCursor = ctx :mainCursor ()
761
+ local line , _ , offset = table.unpack (mainCursor :getPos ())
762
+ if offset > 0 then
763
+ addCursor (ctx , direction == - 1 and " k" or " j" , {
764
+ addCursor = add ,
765
+ remap = false ,
766
+ })
767
+ return
771
768
end
772
- local maxCol = vim .fn .virtcol ({ line , " $" })
773
- if virtCol == 1 or maxCol > virtCol then
774
- found = true
775
- break
769
+ local virtCol = vim .fn .virtcol (" ." )
770
+ local lastLine = vim .fn .line (" $" )
771
+ local found = false
772
+ while true do
773
+ line = line + direction
774
+ if line < 1 or line > lastLine then
775
+ break
776
+ end
777
+ local maxCol = vim .fn .virtcol ({ line , " $" })
778
+ if virtCol == 1 or maxCol > virtCol then
779
+ found = true
780
+ break
781
+ end
776
782
end
783
+ if not found then
784
+ return
785
+ end
786
+ addCursor (ctx , function (cursor )
787
+ cursor :setPos ({
788
+ line ,
789
+ vim .fn .virtcol2col (0 , line , virtCol ),
790
+ offset ,
791
+ })
792
+ end , { addCursor = add })
777
793
end
778
- if not found then
779
- return
780
- end
781
- addCursor (ctx , function (cursor )
782
- cursor :setPos ({
783
- line ,
784
- vim .fn .virtcol2col (0 , line , virtCol ),
785
- offset ,
786
- })
787
- end , { addCursor = add })
788
794
end )
789
795
end
790
796
@@ -909,16 +915,21 @@ end
909
915
--- @param add boolean
910
916
--- @param opts ? vim.diagnostic.JumpOpts
911
917
local function diagnosticAddCursor (direction , add , opts )
918
+ opts = opts or {}
912
919
mc .action (function (ctx )
913
- local d = direction == 1 and
914
- vim .diagnostic .get_next (opts )
915
- or vim .diagnostic .get_prev (opts )
916
- if d == nil then
917
- return
920
+ for _ = 1 , vim .v .count1 do
921
+ local pos = ctx :mainCursor ():getPos ()
922
+ opts .pos = { pos [1 ], pos [2 ] - 1 }
923
+ local d = direction == 1 and
924
+ vim .diagnostic .get_next (opts )
925
+ or vim .diagnostic .get_prev (opts )
926
+ if d == nil then
927
+ return
928
+ end
929
+ addCursor (ctx , function (cursor )
930
+ cursor :setPos ({ d .lnum + 1 , d .col + 1 })
931
+ end , { addCursor = add })
918
932
end
919
- addCursor (ctx , function (cursor )
920
- cursor :setPos ({ d .lnum + 1 , d .col + 1 })
921
- end , { addCursor = add })
922
933
end )
923
934
end
924
935
0 commit comments