Suppose there is a text

- '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 to copy autoindent autoread backspace... and so on to the system register?

P.S. I tried vim-multiple-cursors, but this plugin is buggy and allows you to copy-paste only if you don’t exit the multiple-cursors mode

  • one
    Need to copy a few lines entirely? or a rectangular block that contains exactly the words you specified? - cronfy
  • @cronfy I need to copy the words in ordinary brackets, I assume that this is done using visual block - srghma
  • one
    Look, will it work? superuser.com/q/208852/576308 - cronfy
  • @cronfy not, since all the words are of different sizes (renamed the question) - srghma
  • @cronfy, for example, here I was given the following response stackoverflow.com/questions/41149337/… - srghma

3 answers 3

Copy several lines entirely

  1. Move to the first line.
  2. V
  3. Move the cursor to the last line.
  4. y

Buffer text. You can insert with P

Copy and paste rectangular block

  1. Move to the upper left corner.
  2. Ctrl-v (in Windows Ctrl-q ).
  3. Move the cursor to the bottom right corner.
  4. y

Buffer text. There are two insertion options:

  1. Without new lines - the text will be inserted in the column where the cursor is located, moving the existing text to the right - the command P
  2. Creating new lines for text from the buffer - command :put .

Copy multiple occurrences of text into a single buffer that match regular expressions.

If you want to copy something not rectangular, you can use copy to register through regular expressions.

  1. qaq - clear the register "a".
  2. :%s/\v^- '([^']*)'/\=setreg('A', submatch(1), 'V')/n (regular for your particular case, what happens here - see explanation below).

Text in register "a". You can insert with P In your case, we get the following result:

 autoindent autoread backspace backupdir complete directory 

What happens in the regular season:

  • \ v - enable the 'very magic' mode for extended regular expressions to work (in our case we need parentheses).
  • The part that needs to be added to the buffer is enclosed in parentheses.
  • setreg() using submatch(1) gets the value of the entry in parentheses and adds it to the register "a" (note that the register is indicated by an uppercase letter so that the text is added, and not replaced by the existing one).
  • / n - specifying s /// not to replace the text.

More options here .

Manually type parts of the text into the buffer

If a regular expression cannot collect text, you can manually type it into the buffer:

  1. qaq - clear the register "a".
  2. Select the desired piece of text. For example, being on the word 'autoindent' we press vi' , literally such a command means "select the word inside single quotes".
  3. "Ay - copies the selected text to the register" a ", adding to the buffer, rather than overwriting it.
  4. Repeat steps 2-3 as needed.

Buffer text. You can insert with P

Combination of different approaches

Actually, if you do not type qaq before each new search, the register will not be cleared. You can type data into it first manually, then regularly, then somehow, then again manually, and so on.

  • Just not overkill, but that very vim way I understood 2 things: vim-multiple-cursors is the right plugin and if they don't fix it - I'll switch to vintageous Thank you - srghma
  • @BjornMelgaard updated the answer, added a regular session example for your case and one more option (manual dialing into the buffer for cases when the regular schedule fails). - cronfy

The condition “get the text between the first and second quotes” is easy to accomplish using the cut program:

 $ echo "- 'autoindent' is set by default" | cut -d "'" -f 2 autoindent 

longer way

in vim -e, you can transfer the current selected lines to an external program (for which we will use cut ) using the following construction:

 :диапазон! внешняя-программа-или-команда 

i.e., select the necessary lines in the visual mode by going to it by pressing V , then pressing ! and on the vim command line, get this text:

 :'<,'>! 

after it, enter the external command to make it like this:

 :'<,'>! cut -d "'" -f 2 

press enter and instead of all selected lines you get only words between the first and second quotes:

 autoindent autoread backspace backupdir complete directory 

press g v to repeat the selection of the same range of lines, then y to save them in the register (by default - in an unnamed register " ).

to return after this the original contents of the strings, press u .


if it is necessary to work not with a range of lines, but with all the lines of a file, then the whole procedure will be slightly shorter. execute the command:

 :%! cut -d "'" -f 2 

then copy all the resulting lines into a register (by default, unnamed):

 :%y 

then return the source strings by pressing u .


shorter way

  1. Copy the necessary lines into the nameless register (i.e., select them and press y ).
  2. call the cut program using the system() function, passing it the contents of the unnamed register ( @" ), and write its output back to the same register:

     :let @"=system("cut -d \"'\" -f 2",@") 

    quotes inside the parameters for the cut program had to be “locked”.

  3. now the nameless register contains the required strings. You can insert them in the right place, for example, by pressing p .

Of course, you can use any other register. storing strings in register a : " a y . addressing register a on the command line: @a (instead of @" ). paste from register a : " a p .

  • It is worth remembering such an answer. We are reviewing the best option and find out why vim-multiple-cursors is not working - srghma
  • one
    @BjornMelgaard, came up with a shorter way (and added to the answer). - aleksandr barakin
  • wow, you can even immediately specify the register + - srghma
  • one
    the register could also be specified in the first variant:: :%ya - copy all the lines into the register a . - aleksandr barakin

Decided to switch to Vintageous. My configs are here

Also hooked up MarkAndMove, AceJump and Surround.

Just see what MarkAndMove is and see the potential. This is much better vim