From 9dcb3ba0d8158d63b09a06a2628ea884904fa8a8 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sun, 30 Jun 2024 21:39:42 +0300 Subject: Added surround.nvim plugin and Ctrl + / keymap for commenting/uncommenting --- .config/nvim/lua/plugins/comment.lua | 15 +++++++++++++-- .config/nvim/lua/plugins/surround.lua | 9 +++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 .config/nvim/lua/plugins/surround.lua (limited to '.config/nvim/lua/plugins') diff --git a/.config/nvim/lua/plugins/comment.lua b/.config/nvim/lua/plugins/comment.lua index d41bad4..6e9a55e 100644 --- a/.config/nvim/lua/plugins/comment.lua +++ b/.config/nvim/lua/plugins/comment.lua @@ -2,7 +2,6 @@ return { 'numToStr/Comment.nvim', opts = { padding = true, - sticky = true, -- keep cursor at it's position ignore = nil, toggler = { line = 'gcc', block = 'gbc' }, @@ -10,8 +9,20 @@ return { extra = { above = 'gcO', below = 'gco', eol = 'gcA' }, mappings = { - basic = true, -- `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` + basic = true, -- `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}` extra = false, -- `gco`, `gcO`, `gcA` }, }, + config = function() + local api = require('Comment.api') + local esc = vim.api.nvim_replace_termcodes('', true, false, true) + -- TODO: Stay in visual mode and keep the same selection even after commenting + local toggole_linewise_selection = function() + vim.api.nvim_feedkeys(esc, 'nx', false) + api.toggle.linewise(vim.fn.visualmode()) + end + + vim.keymap.set('n', '', api.toggle.linewise.current, { noremap = true, silent = true }) + vim.keymap.set('v', '', toggole_linewise_selection, { noremap = true, silent = true }) + end, } diff --git a/.config/nvim/lua/plugins/surround.lua b/.config/nvim/lua/plugins/surround.lua new file mode 100644 index 0000000..2b8d3e0 --- /dev/null +++ b/.config/nvim/lua/plugins/surround.lua @@ -0,0 +1,9 @@ +return { + 'kylechui/nvim-surround', + version = '*', + event = 'VeryLazy', + config = function() + require('nvim-surround').setup({}) + -- TODO: Add a way to not have to press S while in visual mode + end, +} -- cgit v1.3.1