Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nvim-mutate

Quickly reshape JSON and escaped strings (certificates, keys, config values) right inside your buffer.

Quick start

  1. Install (lazy.nvim):

    { "yourname/nvim-mutate", config = true }
  2. Open a file, then run any of the commands below. With no selection they act on the whole buffer; select some lines first (visual mode) to act on just the selection.

    :MutateJsonFormat          " pretty-print the whole file
    :'<,'>MutateNewlinesExpand " expand the selected one-line cert

That's it.

Commands

Command What it does
:MutateJsonFormat Pretty-print JSON with indentation.
:MutateJsonMinify Collapse JSON onto a single line.
:MutateNewlinesExpand Turn escaped \n (and \r\n) into real line breaks.
:MutateNewlinesCollapse Turn real line breaks back into escaped \n.

Every command works on the visual selection when you run it with a range (:'<,'>Command), and on the entire buffer otherwise.

Examples

Read a certificate that's crammed into one line

You have a JSON value like this and want to actually read it:

"cert": "-----BEGIN CERTIFICATE-----\nMIIB...\n-----END CERTIFICATE-----\n"

Select that line and run :'<,'>MutateNewlinesExpand:

"cert": "-----BEGIN CERTIFICATE-----
MIIB...
-----END CERTIFICATE-----
"

When you're done editing, select the lines and run :'<,'>MutateNewlinesCollapse to squeeze it back onto one line.

Format or minify JSON

Turn a compact blob into something readable with :MutateJsonFormat:

{"name":"demo","tags":["a","b"],"nested":{"on":true}}

becomes

{
  "name": "demo",
  "tags": [
    "a",
    "b"
  ],
  "nested": {
    "on": true
  }
}

Run :MutateJsonMinify to go back to a single line — handy before pasting into another config file.

Configuration

Optional. The only setting is the indent width used by :MutateJsonFormat:

require("nvim-mutate").setup({
  indent = 2, -- spaces per level (default)
})

Development

make test   # run the test suite (fetches plenary.nvim into .tests/ if needed)

About

Reshape JSON and escaped strings (certs, keys) right in your Neovim buffer.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages