Simplifies commenting and uncommenting lines of code for all and custom filetypes
Add to your init.lua with packer.nvim.
-- in your init.lua, to install the plugin
use 'jrihon/mutineer.lua'
-- set up mutineer
require('mutineer').setup()
require('mutineer').setup({
lineCommentSymbols = {
lua = '--',
}
})
The command :Mutineer
handles both single line and multiline commenting/uncommenting.
-- I did the following in my init.lua (`m` stands for mute) :
local keymap = vim.api.nvim_set_keymap
local opts = {noremap = true, silent = true }
keymap('n', '<leader>m', ':Mutineer<CR>', opts)
keymap('v', '<leader>m', ':Mutineer<CR>', opts)
- It suffices to have the cursor on a line and to then actuate the command.
- Multiline comments are actuated by using
Visual Mode
and higlighting the desired lines. - Uncommenting a line is handles by the same command
You can check if vim recognises your filetype by :echo &filetype
or :lua print(vim.bo.filetype)
.
If this command returns
or nil
, the filetype is not recognised.
path/to/mutineer.lua/docs/AllKnownVimFileTypes.txt
contains a list of all the natively recognised filetypes.
To have a certain filetype recognised :
vim.cmd[[autocmd BufNewFile,BufRead *.foo set filetype='foobar']]
lineCommentSymbols = { asm = ';', -- Assembly
c = '//', -- C
cpp = '//', -- C++
cs = '//', -- C#
csh = '#', -- C-shell
d = '//', -- D
dart = '//', -- Dart
go = '//', -- Golang
hs = '--', -- Haskell
java = '//', -- Java
javascript = '//', -- JavaScript
kotlin = '//', -- Kotlin
lua = '--', -- Lua
matlab = '%', -- Matlab
perl = '#', -- Perl
php = '//', -- PHP
python = '#', -- Python
ruby = '#', -- Ruby
rust = '//', -- Rust
sh = '#', -- Shell
sql = '--', -- SQL
swift = '//', -- Swift
tex = '%', -- LaTeX
typescript = '//', -- TypeScript
vim = '"', -- Vim
yml = '#', -- YAML
zsh = '#', -- Z-shell
}
My roommate for being excited whenever I sent him shows of progress while coding Mutineer.vim and now Mutineer.lua . Thanks S <3