Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I highlight multiple lines in gVim without using the mouse?

Tags:

vim

Vim noob here. I am trying to select multiple lines of code to copy and paste in other areas. Is there a way to do this without using the mouse?

like image 706
Sean Avatar asked Dec 11 '25 14:12

Sean


1 Answers

A few other ways that don't use visual mode at all:

using marks

  1. leave a mark somewhere with ma

  2. move somewhere else

  3. yank from here to there with y'a

using search motions

  1. localize some unique token at the end of the part you want to yank

  2. yank from here to there with y/foo<cr> (forward search) or y?bar<cr> (backward search)

using text-objects

  1. determine what text-object would map to what you want to yank:

    • inner/outer word, iw/aw

    • inner/outer pair, i'"([{</a'"([{<

    • inner/outer html tag, it/at

    • sentence, s

    • paragraph, p

    • "block", ]

  2. yank that text-object with, say, yip

using other motions

  • yank to end of function: y]}

  • yank to end of file: yG

all of the above solutions with visual mode

  • V'ay

  • V/foo<cr>y

  • V?bar<cr>y

  • Vipy, etc.

  • V]}y

  • VGy


:h motion.txt will hopefully blow your mind, like it did to mine.

like image 70
romainl Avatar answered Dec 13 '25 04:12

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!