MisanthropicBit/decipher.nvim

github github
utilitytext-objectplugin
stars 41
issues 1
subscribers 3
forks 1
CREATED

UPDATED


[!IMPORTANT]
A bit library is needed which requires that either neovim has been compiled with luajit or you are using v0.9.0+ which provides a bit library.

demo

Table of contents

Installing

Requires at least neovim v0.8.0.

Plug 'MisanthropicBit/decipher.nvim'
use 'MisanthropicBit/decipher.nvim'

Setup

Setup decipher using decipher.setup unless you are content with the defaults. The options below are the default values. Refer to the docs for more help.

require("decipher").setup({
    float = { -- Floating window options
        padding = 0, -- Zero padding (does not apply to title if any)
        border = { -- Floating window border
            { "╭", "FloatBorder" },
            { "─", "FloatBorder" },
            { "╮", "FloatBorder" },
            { "│", "FloatBorder" },
            { "╯", "FloatBorder" },
            { "─", "FloatBorder" },
            { "╰", "FloatBorder" },
            { "│", "FloatBorder" },
        },
        mappings = {
            close = "q", -- Key to press to close the floating window
            apply = "a", -- Key to press to apply the encoding/decoding
            jsonpp = "J", -- Key to prettily format contents as json if possbile
            help = "?", -- Toggle help
        },
        title = true, -- Display a title with the codec name
        title_pos = "left", -- Position of the title
        autoclose = true, -- Autoclose floating window if insert
                          -- mode is activated or the cursor is moved
        enter = false, -- Automatically enter the floating window if
                       -- opened
        options = {}, -- Options to apply to the floating window contents
    },
})

Example keymaps

There are several ways in which you can invoke decipher. Check out the docs for more info. Below are some examples:

-- Encode visually selected text as base64. If invoked from normal mode it will
-- try to use the last visual selection
vim.keymap.set({ "n", "v" }, "<mykeymap>", function()
    require("decipher").encode_selection("base64")
end)

-- Decode encoded text using a motion, selecting a codec and previewing the result
vim.keymap.set("n", "<mykeymap>", function()
    require("decipher").decode_motion_prompt({ preview = true })
end)

Supported Codecs

Base32

Example: "this is encoded" => "ORUGS4ZANFZSAZLOMNXWIZLE"

Base64

Example "light work." => "bGlnaHQgd29yay4="

Base64-url

Url-safe version of base64 with optional padding used in json web tokens.

Example "light work." => "bGlnaHQgd29yay4" (base64 would have added a single '=' at the end)

Base64-url-safe

Url-safe version of base64 that uses a different encoding table to avoid use of url-unsafe characters. This is basically base64url with mandatory padding.

Example "🔑_🏧⛳🈹" => "8J-UkV_wn4-n4puz8J-IuQ=="

Base64-url-encoded

Url-safe version of base64 with url percent-encoding.

Example "🔑_🏧⛳🈹" => "8J%2bUkV%2fwn4%2bn4puz8J%2bIuQ%3d%3d"

Crockford

Variant of base32 which excludes 'I', 'L', 'O', and 'U' to avoid confusion with digits.

Example: "this is encoded" => "EHM6JWS0D5SJ0SBECDQP8SB4"

Url

Also known as percent-encoding.

Example th<is is encod!ed> => th%3cis+is+encod%21ed%3e

Z-base32

A more human-readable version of base32.

Example: "this is encoded" => "qtwg1h3ypf31y3mqcpzse3mr"