Skip to content

A very small plugin for toggling alternate "boolean" values.

License

Notifications You must be signed in to change notification settings

rmagatti/alternate-toggler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alternate Toggler

Alternate Toggler is a very small plugin for toggling alternate "boolean" values.

Usage

:ToggleAlternate toggles the current word () based on a pre-defined map of alternates.

Installation

Any plugin manager should do, I use Packer.

use {
  'rmagatti/alternate-toggler',
  config = function()
    require("alternate-toggler").setup {
      alternates = {
        ["=="] = "!="
      }
    }
    
    vim.keymap.set(
      "n",
      "<leader><space>", -- <space><space>
      "<cmd>lua require('alternate-toggler').toggleAlternate()<CR>"
    )
  end,
  event = { "BufReadPost" }, -- lazy load after reading a buffer
}

Configuration

Defaults

This plugin provides a few pre-defined alternate mappings.

{
  ["true"] = "false",
  ["True"] = "False",
  ["TRUE"] = "FALSE",
  ["Yes"] = "No",
  ["YES"] = "NO",
  ["1"] = "0",
  ["<"] = ">",
  ["("] = ")",
  ["["] = "]",
  ["{"] = "}",
  ['"'] = "'",
  ['""'] = "''",
  ["+"] = "-",
	["==="] = "!=="
}

Custom

You can add more alternates through a global config variable:

let g:at_custom_alternates = {'===': '!=='}

Or through calling the setup method of the plugin passing in an alternates table in the config.

require("alternate-toggler").setup {
  alternates = {
    ["==="] = "!==",
    ["=="] = "!=",
  }
}

⚠️ WARNING: anything added here will override existing values if the key of the dict/table is the same as any of the defaults.

Commands

Alternate Toggler exposes a single :ToggleAlternate command.

Example mappings:

nnoremap <leader>ta :ToggleAlternate<CR>

OR

augroup AlternateToggles
  au!
  au FileType typescript,viml,lua nnoremap <buffer> <CR> :ToggleAlternate<CR>
augroup end

This allows for merely hitting the enter key to toggle an alternate, the caveat is having to specify supported file types manually.

Compatibility

Neovim > 0.5

Tested with:

NVIM v0.5.0-dev+a1ec36f
Build type: Release
LuaJIT 2.1.0-beta3

About

A very small plugin for toggling alternate "boolean" values.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •