A Neovim plugin for smart toggling of comma and semicolon at the end of lines. Handles comments across multiple languages intelligently.
Full setup (default, everything enabled):
{
"saifulapm/commasemi.nvim",
lazy = false,
opts = {
leader = "<localleader>",
keymaps = true,
commands = true
}
}
Keymaps only:
{
"saifulapm/commasemi.nvim",
lazy = false,
init = function()
vim.g.commasemi_disable_commands = true -- disable commands before plugin loads
end,
opts = {
keymaps = true,
commands = false
}
}
Commands only:
{
"saifulapm/commasemi.nvim",
cmd = { "CommaToggle", "SemiToggle" },
opts = {
keymaps = false,
commands = true
}
}
Custom setup:
{
"saifulapm/commasemi.nvim",
keys = {
{ "<localleader>,", desc = "Toggle comma" },
{ "<localleader>;", desc = "Toggle semicolon" },
},
opts = {
leader = "<localleader>",
keymaps = true,
commands = true
}
}
You can use the plugin in two ways (depending on your configuration):
When keymaps are enabled:
<localleader>, - Toggle comma<localleader>; - Toggle semicolonWhen commands are enabled:
:CommaToggle - Toggle comma at the end of current line:SemiToggle - Toggle semicolon at the end of current line:%CommaToggle - Toggle comma on all lines:5,10CommaToggle - Toggle comma on lines 5-10:'<,'>SemiToggle - Toggle semicolon on visually selected lines// Start with no punctuation
const foo = 'bar'
// After <localleader>,
const foo = 'bar',
// After <localleader>, again (removes comma)
const foo = 'bar'
// After <localleader>;
const foo = 'bar';
// After <localleader>, (replaces semicolon with comma)
const foo = 'bar',
// Select multiple lines and toggle
const foo = 'bar'
const baz = 'qux'
const data = { x: 1 }
// After visual select and <localleader>,
const foo = 'bar',
const baz = 'qux',
const data = { x: 1 },
// Works with inline comments
const foo = 'bar' // some comment
const foo = 'bar', // some comment
// Works with block comments
const data = { x: 1 } /* block comment */
const data = { x: 1 }, /* block comment */
// PHP
$foo = 'bar' // comment
$foo = 'bar'; // comment
// With block comments
$data = array() /* comment */
$data = array(); /* comment */
# Python
x = 42 # comment
x = 42, # comment
require('commasemi').setup({
leader = '<localleader>', -- optional, defaults to <localleader>
keymaps = true, -- optional, set to false to disable keymaps
commands = true -- optional, set to false to disable commands
})
Works with various comment styles:
// - JavaScript, TypeScript, PHP, C, C++, Go, Rust# - Python, Ruby, Shell scripts-- - Lua, SQL/**/ - CSS, C-style block comments<!----> - HTML, XMLMIT
Contributions are welcome! Feel free to submit a Pull Request.