From 228fe1b1b395f69c0d3b70a437a8fd9d49b82008 Mon Sep 17 00:00:00 2001 From: James Wright Date: Sun, 25 Jan 2026 15:49:51 -0700 Subject: [PATCH] feat(comment): Add ignore_surrounding_blank_line --- doc/mini-comment.txt | 5 ++++- lua/mini/comment.lua | 11 +++++++++++ readmes/mini-comment.md | 3 +++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/mini-comment.txt b/doc/mini-comment.txt index 466b8ab1..65048eec 100644 --- a/doc/mini-comment.txt +++ b/doc/mini-comment.txt @@ -77,6 +77,9 @@ Defaults ~ -- Whether to ignore blank lines in actions and textobject ignore_blank_line = false, + -- Whether to ignore blank lines at beginning or end of range selection + ignore_surrounding_blank_line = false, + -- Whether to recognize as comment only lines without indent start_of_line = false, @@ -227,4 +230,4 @@ Return ~ `(string)` Relevant value of 'commentstring'. - vim:tw=78:ts=8:noet:ft=help:norl: \ No newline at end of file + vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/lua/mini/comment.lua b/lua/mini/comment.lua index 54fbebf0..05b86d95 100644 --- a/lua/mini/comment.lua +++ b/lua/mini/comment.lua @@ -121,6 +121,9 @@ MiniComment.config = { -- Whether to ignore blank lines in actions and textobject ignore_blank_line = false, + -- Whether to ignore blank lines at beginning or end of range selection + ignore_surrounding_blank_line = false, + -- Whether to recognize as comment only lines without indent start_of_line = false, @@ -200,6 +203,13 @@ MiniComment.operator = function(mode) -- tree-sitter-based 'commentstring'. Recompute every time for a proper -- dot-repeat. In Visual and sometimes Normal mode it uses left position. local cursor = vim.api.nvim_win_get_cursor(0) + + local config = H.get_config() + if (lnum_from ~= lnum_to) and config.options.ignore_surrounding_blank_line then + lnum_from = vim.fn.nextnonblank(lnum_from) + lnum_to = vim.fn.prevnonblank(lnum_to) + cursor = { lnum_from, 1 } + end MiniComment.toggle_lines(lnum_from, lnum_to, { ref_position = { cursor[1], cursor[2] + 1 } }) return '' end @@ -413,6 +423,7 @@ H.setup_config = function(config) H.check_type('options', config.options, 'table') H.check_type('options.custom_commentstring', config.options.custom_commentstring, 'function', true) H.check_type('options.ignore_blank_line', config.options.ignore_blank_line, 'boolean') + H.check_type('options.ignore_surrounding_blank_line', config.options.ignore_surrounding_blank_line, 'boolean') H.check_type('options.start_of_line', config.options.start_of_line, 'boolean') H.check_type('options.pad_comment_parts', config.options.pad_comment_parts, 'boolean') diff --git a/readmes/mini-comment.md b/readmes/mini-comment.md index ebce800f..8d3e85a0 100644 --- a/readmes/mini-comment.md +++ b/readmes/mini-comment.md @@ -126,6 +126,9 @@ Here are code snippets for some common installation methods (use only one): -- Whether to ignore blank lines when commenting ignore_blank_line = false, + -- Whether to ignore blank lines at beginning or end of range selection + ignore_surrounding_blank_line = false, + -- Whether to ignore blank lines in actions and textobject start_of_line = false,