srghma
srghma

Reputation: 5353

Vim way to yank text object on multiple lines

Suppose I have

- 'autoindent' is set by default
- 'autoread' is set by default
- 'backspace' defaults to "indent,eol,start"
- 'backupdir' defaults to .,~/.local/share/nvim/backup (|xdg|)
- 'complete' doesn't include "i"
- 'directory' defaults to ~/.local/share/nvim/swap// (|xdg|), auto-created

How can I yank words autoindent autoread backspace... and so on to system register with visual block (suppose)

P.S. have tried vim-multiple-cursors, but that plugin buggy (and not vim way) and dont allow copy-paste if one exit multiple-cursors mode in between.


Great answers too in russian version

Upvotes: 3

Views: 951

Answers (4)

Ingo Karkat
Ingo Karkat

Reputation: 172758

My ExtractMatches plugin has (among others) a :YankMatches command for that. It works similar to the built-in :substitute:

:YankMatches!/'\zs[^']\+\ze'/+

By default, the command separates the elements by a newline; if you want them space-separated, use this variation:

:YankMatches!/'\zs[^']\+\ze'/& /+

Upvotes: 1

romainl
romainl

Reputation: 196876

One method

:%norm f'"Zya'

would put 'autoindent' 'autoread' 'backspace' 'backupdir' 'complete' 'directory' in register z.

method 1

To make it available outside of Vim you can do:

:let @+ = @z

Another one with the same result but a lot more complicated (just for the fun of it)

/'\w\{-}' <CR>
"Zca'
<C-r><C-o>"<Esc>
n.n.n.n.n.

method 2

Bonus

The quickest way to clear a named register (register z, here) is:

qzq

Upvotes: 6

ma-ti
ma-ti

Reputation: 134

A solution without visual block:

:let @+='' - clear the system register

qa - record to register 'a'

^3l"kyej - go fourth column, yank the word to register 'k' and go to the next line

:let @+=@+ . ' ' . @k - concatenate the system register, ' ' and register 'k' and store the result again in the system register

q - stop recording

5@a - repeat the recorded command 5 times - voila

reg + - shows "+ autoindent autoread backspace backupdir complete

Upvotes: 1

Julio Batista
Julio Batista

Reputation: 113

In order to make it work:

  1. empty the register a: typing

qaq in normal mode

  1. execute in command line :

    :%s/^- '\(\w\+\)'/\=setreg('A',submatch(1),'V')/n

  2. the desired output is copied in register a and you can get it by typing in command line :

:put A

Upvotes: 1

Related Questions