2

I have a json file and I want to change keys of json file. For example

{
 name: "John",
 age: 31,
 city:"New York",
 school:"xyz"
}

I want to make all keys uppercase. How can I do this with min keystroke in Vim?

5
  • Min keystroke is not always the most convenient.
    – Maxim Kim
    Jan 28 '20 at 12:48
  • @MaximKim may I know the reason why?
    – WitVault
    Jan 28 '20 at 13:01
  • have a look into vimgolf.com as examples. They do min keystrokes that are rarely convenient.
    – Maxim Kim
    Jan 28 '20 at 13:11
  • I understand it may not be intuitive
    – WitVault
    Jan 28 '20 at 13:14
  • :%norm! gUt: does it. Will uppercase everything up to a colon on every line that has one. No effect on lines that don't have a colon in them. Use with a visual selection instead of % if you want that on specific lines only.
    – filbranden
    Jan 28 '20 at 14:34
2

As I mentioned in comment, min keystrokes are not always the most convenient.

I would go with:

:%s/^.*:/\U&/g

Or, align all text with vim-easy-align:

gaip:
CTRL-V (and select all keys)
U

But this has a side effect of all keys aligned with :.

Or without a plugin:

  1. /name
  2. gUiw
  3. j.j.j.

Or with normal command:

  1. vap
  2. :'<,'>norm! wgUiw

'<,'> is inserted automatically

PS, some visuals: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.