mizlan/iswap.nvim

github github
editing-supports plugin
star 138
stars
alert-circle 8
open issues
users 1
subscribers
git-branch 7
forks
CREATED

2021-05-30

UPDATED

last month

packer

require('packer').startup(function()
  use 'mizlan/iswap.nvim'
end)

paq

require "paq" { 
  'mizlan/iswap.nvim'
}

iswap.nvim

Interactively select and swap: function arguments, list elements, function parameters, and more. Powered by tree-sitter.

iswap demo

installation

For vim-plug:

Plug 'mizlan/iswap.nvim'

usage

Run the command :ISwap when your cursor is in a location that is suitable for swapping around things. These include lists/arrays, function arguments, and parameters in function definitions. Then, hit two keys corresponding to the items you wish to be swapped. After both keys are hit, the text should immediately swap in the buffer. See the gif above for example usage.

Use :ISwapWith if you want to have the element your cursor is over automatically as one of the elements. This way, you only need one keypress to make a swap.

configuration

In your init.lua:

require('iswap').setup{
  -- The keys that will be used as a selection, in order
  -- ('asdfghjklqwertyuiopzxcvbnm' by default)
  keys = 'qwertyuiop',

  -- Grey out the rest of the text when making a selection
  -- (enabled by default)
  grey = 'disable',

  -- Highlight group for the sniping value (asdf etc.)
  -- default 'Search'
  hl_snipe = 'ErrorMsg',

  -- Highlight group for the visual selection of terms
  -- default 'Visual'
  hl_selection = 'WarningMsg',

  -- Highlight group for the greyed background
  -- default 'Comment'
  hl_grey = 'LineNr',

  -- Automatically swap with only two arguments
  -- default nil
  autoswap = true
}

inspired by hop.nvim and nvim-treesitter-textobjects

todo

  • add angle bracket stuff
  • add docs and stuff