Vim quotes and commas around words

I have a list of currencies in their abbreviations and long forms:

AED United Arab Emirates dirham
AFN Afghani
ALL Lek
AMD Armenian Dram
ANG Netherlands Antillian Guilder
AOA Kwanza
ARS Argentine Peso
AUD Australian Dollar
AWG Aruban Guilder
AZN Azerbaijanian Manat
BAM Convertible Marks
BBD Barbados Dollar
BDT Bangladeshi Taka
BGN Bulgarian Lev

I actually have 182 lines of them ... in notepad ++. I can easily get quotes around individual words and commas after each word in seconds, I was wondering if there is a way to do this in vim or any other editor in Linux.

Even if I already did this in Notepad ++, it would be nice to expand myself for other editors as well.

suggestions

very much appreciated.

+4
source share
3 answers

Try this command in ex mode.

%s/\w\+/"&",/g | $s/,$//

He has to do the trick.

Explanation: %sreplaces all lines

In terms of compliance:

\w " ",

\+ ,

:

&

, g , .

| ex- .

$s . , $. , .

+7

:

gg
qq
I"<Esc>
f<space>
s","<Esc>
A",<Esc>
q

:

:%norm @q<CR>

:

:%norm I"<C-v><Esc>f<space>s","<C-v><Esc>A",<C-v><Esc><CR>

, , :

:%s/\(\w\+\) \(.\+\)$/"\1","\2",
+3

, . NP ++ ( Notepad!). ctrl-v, :

  • : gg0
  • : <ctrl-v>Ge
  • : s""<esc>P
  • : f<space><ctrl-v>G
  • : s,"

, , . (. romainl), - --- : :%s/$/"/g<enter>, !

0

Source: https://habr.com/ru/post/1544510/


All Articles