简体   繁体   中英

How to copy text within quotes across multiple lines in vim like Sublime, and then paste it

I've been doing some digging, but can't seem to find a way to achieve a very similar functionality to that of Sublime's multi-line-select demonstrated by the giphy below:

  1. copy all text within double quotes (so assuming something like yi" )
  2. Do this across multiple lines
  3. Paste all registers? or better yet all contents from a single register to a new buffer
  4. add colons (turn into symbols) to each line of the pasted text
  5. go to the end of each line and add a comma

I thought a visual selection and running norm yi" would do it, but it only captures the last line of the visual selection.

You can do these in Vim...

  • yanking within quotes over multiple lines

    record a macro ( :let @a=''<cr>qq"Ayiw:let @A="\\n"<cr>j" )

    use the macro ( n@q )

  • pasting a into a new buffer ( :tabnew<cr>"ap )

  • add colons to the beginnings of multiple lines ( <cv>njI:<esc> )

  • add commas to the ends of multiple lines ( <cv>nj$A,<esc> )

Maps and functions can also reduce the number of keystrokes for things.

eg nnoremap <leader>b :tabnew<cr>p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM