From e31fb9b9763e689c570f8d07cb940d80589e8877 Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Mon, 28 Feb 2022 08:41:22 -0600 Subject: [PATCH] comment hotkeys + manager --- lua/configs/comment.lua | 29 +++++++++++++++++++++++++++++ lua/keybinds.lua | 3 +++ lua/plugins.lua | 3 +++ todo.txt | 6 ++++-- 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 lua/configs/comment.lua diff --git a/lua/configs/comment.lua b/lua/configs/comment.lua new file mode 100644 index 0000000..960689a --- /dev/null +++ b/lua/configs/comment.lua @@ -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 + diff --git a/lua/keybinds.lua b/lua/keybinds.lua index 252ae83..42ef392 100644 --- a/lua/keybinds.lua +++ b/lua/keybinds.lua @@ -25,4 +25,7 @@ map("n", "", "bprevious", opts) map('n', 'e', 'NvimTreeToggle', opts) map('n', 'o', 'NvimTreeFocus', opts) +-- Comment +map('n', '/', 'lua require(\'Comment.api\').toggle_current_linewise()', opts) +map('v', '/', 'lua require(\'Comment.api\').toggle_linewise_op(vim.fn.visualmode())', opts) diff --git a/lua/plugins.lua b/lua/plugins.lua index 83037f6..a152fd8 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -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 } diff --git a/todo.txt b/todo.txt index 85f61d9..6cea916 100644 --- a/todo.txt +++ b/todo.txt @@ -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)