comment hotkeys + manager

This commit is contained in:
Michael Peters 2022-02-28 08:41:22 -06:00
parent 8a1f67d50f
commit e31fb9b976
4 changed files with 39 additions and 2 deletions

29
lua/configs/comment.lua Normal file
View File

@ -0,0 +1,29 @@
local M = {}
function M.config()
local status_ok, comment = pcall(require, "Comment")
if not status_ok then
return
end
comment.setup {
pre_hook = function(ctx)
local U = require "Comment.utils"
local location = nil
if ctx.ctype == U.ctype.block then
location = require("ts_context_commentstring.utils").get_cursor_location()
elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then
location = require("ts_context_commentstring.utils").get_visual_start_location()
end
return require("ts_context_commentstring.internal").calculate_commentstring {
key = ctx.ctype == U.ctype.line and "__default" or "__multiline",
location = location,
}
end,
}
end
return M

View File

@ -25,4 +25,7 @@ map("n", "<S-h>", "<cmd>bprevious<CR>", opts)
map('n', '<leader>e', '<cmd>NvimTreeToggle<CR>', opts)
map('n', '<leader>o', '<cmd>NvimTreeFocus<CR>', opts)
-- Comment
map('n', '<leader>/', '<cmd>lua require(\'Comment.api\').toggle_current_linewise()<CR>', opts)
map('v', '<leader>/', '<esc><cmd>lua require(\'Comment.api\').toggle_linewise_op(vim.fn.visualmode())<CR>', opts)

View File

@ -92,6 +92,9 @@ packer.startup {
-- Quality of Life
--
-- Commenting
use { 'numToStr/Comment.nvim', config = function() require'configs.comment'.config() end }
-- Automatically colorize color strings (#f1b8f1)
use { 'norcalli/nvim-colorizer.lua', config = function() require'configs.colorizer'.config() end }

View File

@ -5,8 +5,8 @@
[x] Theme
[x] VSCode Dark
[ ] File Explorer
[ ] NvimTree
[x] File Explorer
[x] NvimTree
[x] Status Line
[x] lualine
@ -46,3 +46,5 @@
[ ] which-key
[ ] Bugs
[ ] Comment Colors don't show (but they show if you delete the compiled config and resync)