runtime(comment): add gC mapping to (un)comment rest of line

Commit: 
https://github.com/vim/vim/commit/9142136161560a22390de3716044cb21aa57262e
Author: Konfekt <konf...@users.noreply.github.com>
Date:   Sun Sep 29 10:46:41 2024 +0200

    runtime(comment): add gC mapping to (un)comment rest of line
    
    fixes: https://github.com/vim/vim/issues/15727
    closes: https://github.com/vim/vim/issues/15737
    
    Signed-off-by: Konfekt <konf...@users.noreply.github.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/pack/dist/opt/comment/autoload/comment.vim 
b/runtime/pack/dist/opt/comment/autoload/comment.vim
index 9dda266ff..ed3534b84 100644
--- a/runtime/pack/dist/opt/comment/autoload/comment.vim
+++ b/runtime/pack/dist/opt/comment/autoload/comment.vim
@@ -1,7 +1,7 @@
 vim9script
 
 # Maintainer: Maxim Kim <haba...@gmail.com>
-# Last Update: 2024-04-26
+# Last Update: 2024-09-24
 #
 # Toggle comments
 # Usage:
@@ -10,6 +10,7 @@ vim9script
 #       nnoremap <silent> <expr> gc comment.Toggle()
 #       xnoremap <silent> <expr> gc comment.Toggle()
 #       nnoremap <silent> <expr> gcc comment.Toggle() .. '_'
+#       nnoremap <silent> <expr> gC  comment.Toggle() .. '$'
 export def Toggle(...args: list<string>): string
     if len(args) == 0
         &opfunc = matchstr(expand('<stack>'), '[^. ]*\ze[')
@@ -19,6 +20,19 @@ export def Toggle(...args: list<string>): string
     var cms = substitute(substitute(&cms, '\S\zs%s\s*', ' %s', ''), '%s\ze\S', 
'%s ', '')
     var [lnum1, lnum2] = [line("'["), line("']")]
     var cms_l = split(escape(cms, '*.'), '\s*%s\s*')
+
+    var first_col = indent(lnum1)
+    var start_col = getpos("'[")[2]
+    if len(cms_l) == 1 && lnum1 == lnum2 && first_col < start_col
+        var line_start = getline(lnum1)[0 : max(0, start_col - 2)]
+        var line_end = getline(lnum1)[start_col - 1 : -1]
+        line_end = line_end =~# $'^\s*{cms_l[0]}' ?
+                    \ substitute(line_end, $'^\s*\zs{cms_l[0]}', '', '') :
+                    \ printf(substitute(cms, '%s\@!', '%%', 'g'), line_end)
+        setline(lnum1, line_start .. line_end)
+        return ''
+    endif
+
     if len(cms_l) == 0 | return '' | endif
     if len(cms_l) == 1 | call add(cms_l, '') | endif
     var comment = 0
diff --git a/runtime/pack/dist/opt/comment/doc/comment.txt 
b/runtime/pack/dist/opt/comment/doc/comment.txt
index 25bd06756..4d791e56c 100644
--- a/runtime/pack/dist/opt/comment/doc/comment.txt
+++ b/runtime/pack/dist/opt/comment/doc/comment.txt
@@ -1,4 +1,4 @@
-*comment.txt*   For Vim version 9.1.  Last change:  2024 Jun 04
+*comment.txt*   For Vim version 9.1.  Last change:  2024 Sep 29
 
 
                  VIM REFERENCE MANUAL
@@ -12,17 +12,26 @@ See |comment-install| on how to activate this package.
 The comment.vim package, allows to toggle comments for a single line, a range
 of lines or a selected text object.  It defines the following mappings:
 
-                                                       *gcc*
-gcc            to comment/uncomment current line
                                                        *o_gc*
 gc{motion}     to toggle comments for the selected motion
-                                                       *gcip*
-gcip           to comment/uncomment current paragraph
-                                                       *gcG*
-gcG            to comment/uncomment from current line till the end of a buffer
                                                        *v_gc*
 {Visual}gc     to comment/uncomment the highlighted lines.
 
+Since gc operates on a motion, it can be used with any motion, for example _
+to comment the current line, or ip to comment the current paragraph.
+A default mapping `gcc` to `gc_` is defined:
+                                                       *gcc*
+gcc            to comment/uncomment current line
+
+To comment the rest of the line by  `gC`  whenever the filetype plugin
+supports it (that is, whenever the comment marker precedes the code) and fall
+back to `gcc` otherwise, add the following mapping to your vimrc: >
+
+       nnoremap <silent> <expr> gC comment.Toggle() .. '$'
+<
+Note: using `gC` may not always result in valid comment markers depending on
+the language used.
+
 This plugin uses the buffer-local 'commentstring' option value to add or remove
 comment markers to the selected lines.  Whether it will comment or un-comment
 depends on the first line of the range of lines to act upon.  When it matches
diff --git a/runtime/pack/dist/opt/comment/doc/tags 
b/runtime/pack/dist/opt/comment/doc/tags
index ec3569e93..ffe4177cc 100644
--- a/runtime/pack/dist/opt/comment/doc/tags
+++ b/runtime/pack/dist/opt/comment/doc/tags
@@ -1,8 +1,6 @@
 b:comment_first_col    comment.txt     /*b:comment_first_col*
 comment.txt    comment.txt     /*comment.txt*
 g:comment_first_col    comment.txt     /*g:comment_first_col*
-gcG    comment.txt     /*gcG*
 gcc    comment.txt     /*gcc*
-gcip   comment.txt     /*gcip*
 o_gc   comment.txt     /*o_gc*
 v_gc   comment.txt     /*v_gc*

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1supmd-00GxGm-2Q%40256bit.org.

Raspunde prin e-mail lui