Home

Awesome

nx.nvim

Utility library to n^x your work with the nvim api.

<br>

Features

Installation

<br>

Features

All features maintain familiarity with their underlying base functions. Below is an overview of their differences and extended functionalities.

<br>

nx.map

Based on vim.keymap.set()

nx.map({
   { ";w", "<Cmd>w<CR>" },
   { ";q", "<Cmd>confirm quit<CR>", desc = "Close Current Window" },
   { "<leader>ts", "<Cmd>set spell!<CR>", desc = "Toggle Spellcheck", wk_label = "Spellcheck" },
   { "<leader>tp", "<Cmd>MarkdownPreviewToggle<CR>", ft = "markdown", desc = "Toggle Markdown Preview" },
})
-- ...
nx.map({
   -- Line Navigation
   { { "j", "<Up>" }, "&wrap ? 'gj' : 'j'", "" },
   { { "k", "<Down>" }, "&wrap ? 'gk' : 'k'", "" },
   { "$", "&wrap ? 'g$' : '$'", "" },
   { "^", "&wrap ? 'g^' : '^'", mode = "" },
   -- Indentation
   { "i", function() return smart_indent "i" end },
   { "a", function() return smart_indent "a" end },
   { "A", function() return smart_indent "A" end },
   }, { expr = true, silent = true })
})

Differences

<br> <details open> <summary><b>Detailed Examples</b> <sub><sup>Toggle visibility...</sup></sub></summary><br> </details> <br>

nx.hl

Based on nvim_set_hl()

nx.hl({
 { "LineNr", fg = "DraculaComment:fg" },
 { "Normal", bg = "DraculaBg:bg" },
 { "BgDarker", bg = palette.bg .. ":#b-15" },
 { "BufferLineSeparatorShadow", fg = "TabLine:bg:#b-10", bg = "Normal:bg" } }
 { { "Directory", "MarkSign" }, link = "DraculaPurple" },
})

Differences

<br> <details> <summary><b>Detailed Examples</b> <sub><sup>Toggle visibility...</sup></sub></summary><br> </details> <br>

nx.au

Based on nvim_create_autocmd()

nx.au({
   { "BufWritePost", pattern = "options.lua", command = "source <afile>", desc = "Execute files on save" },
   { "BufWritePre", command = "call mkdir(expand('<afile>:p:h'), 'p')", desc = "Create non-existent parents" },
})
nx.au({
   { "BufWinLeave", pattern = "*.*", command = "mkview" },
   { "BufWinEnter", pattern = "*.*", command = "silent! loadview" },
}, { create_group = "RememberFolds" })

Differences

<br> <details> <summary><b>Detailed Examples</b> <sub><sup>Toggle visibility...</sup></sub></summary><br> </details> <br>

nx.cmd

Based on nvim_create_user_command()

nx.cmd({
  "LspFormat",
  function() vim.lsp.buf.format({ async = true }) end,
  bang = true,
  desc = "Fromat the Current Buffer",
})

Differences

<br> <details> <summary><b>Detailed Examples</b> <sub><sup>Toggle visibility...</sup></sub></summary><br> </details> <br>

nx.set

There is also nx.set to assign multiple variables or options.

Next to an array of variables/settings, add the scope (vim.g|vim.opt|vim.bo|...) as a second parameter. If no scope is specified vim.g is used.

(This features function currently consists of just over 10 lines of code. It's not as extensive or well annotated, but feel free to use it if you like).

<details> <summary><b>Details</b> <sub><sup>Toggle visibility...</sup></sub></summary><br> </details> <br>

Getting Started

Install "tenxsoydev/nx.nvim" via your favorite plugin manager.

The only thing left to do then is to import the nx functions you want to use.<br>

Examples

<br>

Reusability

To be easily composable, the utilities are written as single modules that can stand on their own. So if they can be helpful within the project you are working - and adding dependencies is too heavy - they are light copy pasta 🍝. In such cases, keeping a small reference of attribution warms the heart of your fellow developer.

<br>

Contribution

There is always room for enhancement. Reach out if you experience any issues, would like to request a feature, or submit improvements. If you would like to tackle open issues - they are usually "help wanted" by nature. Leaving an emoji to show support for an idea that has already been requested also helps to prioritize community needs.

<br>

Credits