All Projects → zegervdv → nrpattern.nvim

zegervdv / nrpattern.nvim

Licence: other
Neovim plugin to expand incrementing/decrementing to more formats.

Programming Languages

lua
6591 projects
Vim Script
2826 projects

Projects that are alternatives of or similar to nrpattern.nvim

neogen
A better annotation generator. Supports multiple languages and annotation conventions.
Stars: ✭ 339 (+1312.5%)
Mutual labels:  neovim, neovim-plugin
nvim-lsp-compl
A fast and asynchronous auto-completion plugin for Neovim >= 0.5, focused on LSP.
Stars: ✭ 46 (+91.67%)
Mutual labels:  neovim, neovim-plugin
nvim-ghost.nvim
👻 GhostText plugin for Neovim with zero dependencies 🎉 Supports neovim running inside WSL too! 🥳 Windows/Linux/macOS supported out-of-the-box! 😄 (Other OSes need python3.6+ installed)
Stars: ✭ 32 (+33.33%)
Mutual labels:  neovim, neovim-plugin
lir.nvim
Neovim file explorer
Stars: ✭ 194 (+708.33%)
Mutual labels:  neovim, neovim-plugin
nvim-dap-python
An extension for nvim-dap, providing default configurations for python and methods to debug individual test methods or classes.
Stars: ✭ 70 (+191.67%)
Mutual labels:  neovim, neovim-plugin
close-buffers.nvim
📑 Delete multiple vim buffers based on different conditions
Stars: ✭ 54 (+125%)
Mutual labels:  neovim, neovim-plugin
igs.nvim
A minimalist Neovim plugin that enhances the usage of git status inside Neovim.
Stars: ✭ 17 (-29.17%)
Mutual labels:  neovim, neovim-plugin
nvim context vt
Virtual text context for neovim treesitter
Stars: ✭ 193 (+704.17%)
Mutual labels:  neovim, neovim-plugin
cmp-under-comparator
nvim-cmp comparator function for completion items that start with one or more underlines
Stars: ✭ 77 (+220.83%)
Mutual labels:  neovim, neovim-plugin
denite-gtags
Denite source for GNU Global
Stars: ✭ 27 (+12.5%)
Mutual labels:  neovim, neovim-plugin
null-ls.nvim
Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
Stars: ✭ 965 (+3920.83%)
Mutual labels:  neovim, neovim-plugin
agitator.nvim
No description or website provided.
Stars: ✭ 16 (-33.33%)
Mutual labels:  neovim, neovim-plugin
Comment.nvim
🧠 💪 // Smart and powerful comment plugin for neovim. Supports treesitter, dot repeat, left-right/up-down motions, hooks, and more
Stars: ✭ 796 (+3216.67%)
Mutual labels:  neovim, neovim-plugin
virt-column.nvim
Display a character as the colorcolumn
Stars: ✭ 64 (+166.67%)
Mutual labels:  neovim, neovim-plugin
nvim-jdtls
Extensions for the built-in LSP support in Neovim for eclipse.jdt.ls
Stars: ✭ 282 (+1075%)
Mutual labels:  neovim, neovim-plugin
spellsitter.nvim
Treesitter powered spellchecker
Stars: ✭ 251 (+945.83%)
Mutual labels:  neovim, neovim-plugin
Vim Vsnip
Snippet plugin for vim/nvim that supports LSP/VSCode's snippet format.
Stars: ✭ 224 (+833.33%)
Mutual labels:  neovim, neovim-plugin
Vim Ghost
Vim/Nvim client for GhostText - Edit browser text areas in Vim/Neovim
Stars: ✭ 245 (+920.83%)
Mutual labels:  neovim, neovim-plugin
boo-colorscheme-nvim
Boo is a colorscheme for Neovim with handcrafted support for LSP, Treesitter.
Stars: ✭ 62 (+158.33%)
Mutual labels:  neovim, neovim-plugin
nvim-lsp-smag
Seamless integration of language server locations into NeoVim
Stars: ✭ 60 (+150%)
Mutual labels:  neovim, neovim-plugin

Nrpattern

A Neovim plugin to expand the number formats supported to increment or decrement.

This plugin requires Neovim 0.5.

preview

Details

In (Neo)vim you can increment or decrement values using the <ctrl-a> and <ctrl-x> mappings. However, these only work for a limited set of formats:

  • Decimal: 1231
  • Hexadecimal: 0xaaff
  • Octal: 0755
  • Binary: 0b110011

But there are many more formats used by the various programming languages in existance today, and likely many more will follow.

This plugin allows you to define custom patterns.

Features

  • Custom formats and patterns
  • Value separators (e.g. 123_1231 for python or php)
  • Repeat with . (requires tpope/vim-repeat)
  • Arbitrary large number support
  • Cyclic patterns: toggle between words

Installation

  • vim-plug
Plug 'zegervdv/nrpattern.nvim'
lua require"nrpattern".setup()
  • packer.nvim
use {
  'zegervdv/nrpattern.nvim',
  config = function()
    -- Basic setup
    -- See below for more options
    require"nrpattern".setup()
  end,
}

Configuration

Nrpattern.nvim comes with a couple of default patterns installed, but you can add more, disable some or change their options.

-- Get the default dict of patterns
local patterns = require"nrpattern.default"

-- The dict uses the pattern as key, and has a dict of options as value.
-- To add a new pattern, for example the VHDL x"aabb" format.
patterns['()x"(%x+)"'] = {
  base = 16, -- Hexadecimal
  format = '%sx"%s"', -- Output format
  priority = 15, -- Determines order in pattern matching
}

-- Change a default setting:
patterns["(%d*)'h([%x_]+)"].separator.group = 8

-- Remove a pattern
patterns["(%d*)'h([%x_]+)"] = nil

-- Add a cyclic pattern (toggles between yes and no)
patterns[{"yes", "no"}] = {priority = 5}

-- Call the setup to enable the patterns
require"nrpattern".setup(patterns)

Options

The pattern must have two capture groups. The first is the prefix and may be an empty match. The second must match the value with any possible separators.

For example, to match 32'haaaa_bbbb as a hexadecimal value, you need the pattern "(%d*)'h([%x_]+)":

  • (%d*): The prefix capture group, matches zero or more digits
  • 'h: Literally match this string
  • ([%x_]+): The value capture group, match any hexadecimal charactor or _ once or more

If the pattern is a list, it matches each word in the list and cycles over the opions. For example you can toggle between true or false, or in and out. When the list has more than two options it cycles through the list in order of definition. E.g. for a list of {'one', 'two', 'three'}, when incrementing over the word one will update to two, then to three.

For every pattern you can set some options:

  • base : The base of the format, e.g. 10 for decimal, 16 for hex
  • format : The output format, must have 2 string patterns ('%s'), first is prefix (and may be empty), second is new value
  • priority : Order in which to match patterns, lower is earlier. See default.lua for default values.
  • separator : Optional dict, for digit separators in pattern
    • char : Charactor to insert as separator
    • group : How many digits to group (e.g., add a , every 3 digits)
  • filetypes: Optional list, filetypes to enable the pattern for

Separators are inserted in the value when one was already present in the value. The separators are however inserted in fixed groups, regardless of the previous location of the separators.

For example the value 32'hff_fff_ff7 will become 32'hffff_fff8, because the group setting for SystemVerilog hexadecimal values is set to 4.

Mappings

By default <ctrl-a>, <ctrl-x>, and g<ctrl-a> and g<ctrl-x> are remapped to nrpattern. If you want to avoid this you can set g:nrpattern_no_mapping.

-- vimscript
let g:nrpattern_no_mapping = 1

-- lua
vim.g.nrpattern_no_mapping = 1

To map them manually:

  nmap <C-a> <Plug>(PatternIncrement)
  nmap <C-x> <Plug>(PatternDecrement)
  vmap <C-a> <Plug>(PatternRangeIncrement)
  vmap <C-x> <Plug>(PatternRangeDecrement)
  vmap g<C-a> <Plug>(PatternMultIncrement)
  vmap g<C-x> <Plug>(PatternMultDecrement)

TODO

Following topics are planned to be added:

  • Keep original case, for now every value is lowercased
  • Keep leading zeros

If possible (harder problems):

  • Preserve original location of separators

Thanks

Thanks to @smolck for the initial code snippet to start this plugin.

The BigInteger.lua file to enable support for large numbers (over 64 bits) is copyrighted to @a-benlolo: BigInteger.lua repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].