Add text to end of multiple line - vim

Suppose you have a whole list of text:

Movies
Travel
Fashion (Men)
Fashion (Women)
Education
Technology
Clubbing
Nightlife
Fine Dining
Food
E-Commerce
Beauty
Wellness
Gaming
Performing Arts
Sports
Books
Music
Photography
Fitness
Gadgets

And you want to make the whole thing an array in ruby.

How do you do it in vim, quickly?

First, we need to give everyone quotation marks.

Using surround.vim, do:

  • Surround the entire text using Ctrl-V
  • In vim, type:
:norm yss "

This will give every single line in the selection a "" like:

"Movies"
"Travel"
"Fashion (Men)"
"Fashion (Women)"
"Education"
"Technology"
"Clubbing"
"Nightlife"
"Fine Dining"
"Food"
"E-Commerce"
"Beauty"
"Wellness"
"Gaming"
"Performing Arts"
"Sports"
"Books"
"Music"
"Photography"
"Fitness"
"Gadgets"

Then we need to add commas,

Do this:

  • Surround the entire text using Ctrl-V
  • Press $ to surround the block to the end of every line
  • Press A (shift-a) to go into insert mode
  • Make your changes!
 Ctrl-V {highlight entire block} $ Shift-A , Esc

to make it:

"Movies",
"Travel",
"Fashion (Men)",
"Fashion (Women)",
"Education",
"Technology",
"Clubbing",
"Nightlife",
"Fine Dining",
"Food",
"E-Commerce",
"Beauty",
"Wellness",
"Gaming",
"Performing Arts",
"Sports",
"Books",
"Music",
"Photography",
"Fitness",
"Gadgets",

Then, add your surrounding array brackets and you’re done!

Reference: Vim Wiki