Files
vim/runtime/pack/dist/opt/comment/plugin/comment.vim
Mark Woods 1cbe3e89c9 runtime(comment): add <Plug>-mappings
vim9script <expr> mappings relying on imports cannot be evaluated
outside of the script file with the imports, so do not work with plugins
like vim-which-key, which evaluates <expr> mappings to apply them.

Using <Plug> mappings is one way to address this, and has the added
benefit of reading like a description for users finding the mappings.

fixes: #17523
closes: #17563

Signed-off-by: Mark Woods <mwoods.online.ie@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
2025-06-22 20:20:34 +02:00

30 lines
1.2 KiB
VimL

vim9script
# Maintainer: Maxim Kim <habamax@gmail.com>
# Last Update: 2025 Mar 21
# 2025 Jun 22 by Vim Project: add <Plug> mappings #17563
import autoload 'comment.vim'
nnoremap <silent> <expr> <Plug>(comment-toggle) comment.Toggle()
xnoremap <silent> <expr> <Plug>(comment-toggle) comment.Toggle()
nnoremap <silent> <expr> <Plug>(comment-toggle-line) comment.Toggle() .. '_'
nnoremap <silent> <expr> <Plug>(comment-toggle-end) comment.Toggle() .. '$'
onoremap <silent> <Plug>(comment-text-object-inner) <scriptcmd>comment.ObjComment(v:true)<CR>
onoremap <silent> <Plug>(comment-text-object-outer) <scriptcmd>comment.ObjComment(v:false)<CR>
xnoremap <silent> <Plug>(comment-text-object-inner) <esc><scriptcmd>comment.ObjComment(v:true)<CR>
xnoremap <silent> <Plug>(comment-text-object-outer) <esc><scriptcmd>comment.ObjComment(v:false)<CR>
if get(g:, 'comment_mappings', true)
nmap gc <Plug>(comment-toggle)
xmap gc <Plug>(comment-toggle)
nmap gcc <Plug>(comment-toggle-line)
nmap gC <Plug>(comment-toggle-end)
omap ic <Plug>(comment-text-object-inner)
omap ac <Plug>(comment-text-object-outer)
xmap ic <Plug>(comment-text-object-inner)
xmap ac <Plug>(comment-text-object-outer)
endif