neovim에 대한 스마트하고 강력한 댓글 플러그인

commentstring 지원합니다. 읽기 :h comment.commentstring// ) 및 블록 ( /* */ ) 주석. ) gcc , gbc 및 Friends에 대한 반복 지원[count]gcc 및 [count]gbc 에 대한 지원 수치gcw gc$ ) 및 Up-Down ( gc2j gc4k ) 동작gci{ gbat )와 함께 사용 -- add this to your lua/plugins.lua, lua/plugins/init.lua, or the file you keep your other plugins:
{
' numToStr/Comment.nvim ' ,
opts = {
-- add any options here
}
}
use {
' numToStr/Comment.nvim ' ,
config = function ()
require ( ' Comment ' ). setup ()
end
}Plug ' numToStr/Comment.nvim '
" Somewhere after plug#end()
lua require ( ' Comment ' ). setup () Comment.nvim 실행을 통해 액세스 할 수있는 도움말 문서를 제공합니다 :help comment-nvim
먼저 기본 매핑을 만들려면 setup() 메소드를 호출해야합니다.
참고 - KeyBindings에 직면하는 경우 매핑되었지만 작동하지 않는 문제가 발생하지 않으면이 문제를 시도하십시오.
require ( ' Comment ' ). setup () lua << EOF
require ( ' Comment ' ). setup ()
EOF 다음은 setup() 의 기본 구성입니다. 재정의하려면 원하는 옵션을 수정하면 기본 구성과 병합됩니다. 읽기 :h comment.config 자세한 내용을 보려면.
{
--- Add a space b/w comment and the line
padding = true ,
--- Whether the cursor should stay at its position
sticky = true ,
--- Lines to be ignored while (un)comment
ignore = nil ,
--- LHS of toggle mappings in NORMAL mode
toggler = {
--- Line-comment toggle keymap
line = ' gcc ' ,
--- Block-comment toggle keymap
block = ' gbc ' ,
},
--- LHS of operator-pending mappings in NORMAL and VISUAL mode
opleader = {
--- Line-comment keymap
line = ' gc ' ,
--- Block-comment keymap
block = ' gb ' ,
},
--- LHS of extra mappings
extra = {
--- Add comment on the line above
above = ' gcO ' ,
--- Add comment on the line below
below = ' gco ' ,
--- Add comment at the end of line
eol = ' gcA ' ,
},
--- Enable keybindings
--- NOTE: If given `false` then the plugin won't create any mappings
mappings = {
--- Operator-pending mapping; `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}`
basic = true ,
--- Extra mapping; `gco`, `gcO`, `gcA`
extra = true ,
},
--- Function to call before (un)comment
pre_hook = nil ,
--- Function to call after (un)comment
post_hook = nil ,
} setup() 메소드를 호출 할 때 Comment.nvim 일반 및 시각적 모드에서 사용할 수있는 기본 매핑을 설정하여 주석을내는 즐거움을 시작할 수 있습니다.
이 매핑은 기본적으로 활성화됩니다. (구성 : mappings.basic )
`gcc` - Toggles the current line using linewise comment
`gbc` - Toggles the current line using blockwise comment
`[ count ]gcc` - Toggles the number of line given as a prefix-count using linewise
`[ count ]gbc` - Toggles the number of line given as a prefix-count using blockwise
`gc[ count ]{motion}` - (Op-pending) Toggles the region using linewise comment
`gb[ count ]{motion}` - (Op-pending) Toggles the region using blockwise comment `gc` - Toggles the region using linewise comment
`gb` - Toggles the region using blockwise comment 이 매핑은 기본적으로 활성화됩니다. (구성 : mappings.extra )
`gco` - Insert comment to the next line and enters INSERT mode
`gcO` - Insert comment to the previous line and enters INSERT mode
`gcA` - Insert comment to end of the current line and enters INSERT mode# Linewise
`gcw` - Toggle from the current cursor position to the next word
`gc $ ` - Toggle from the current cursor position to the end of line
`gc}` - Toggle until the next blank line
`gc5j` - Toggle 5 lines after the current cursor position
`gc8k` - Toggle 8 lines before the current cursor position
`gcip` - Toggle inside of paragraph
`gca}` - Toggle around curly brackets
# Blockwise
`gb2}` - Toggle until the 2 next blank line
`gbaf` - Toggle comment around a function (w/ LSP/treesitter support)
`gbac` - Toggle comment around a class (w/ LSP/treesitter support) 이 플러그인에는 Vue 또는 Markdown과 같은 여러 (주입/임베디드) 언어에 작동하는 commentstring 계산하는 데 기본 트리 시터가 지원됩니다. 그러나 구문 분석 된 트리의 특성으로 인해이 구현에는 알려진 한계가 있습니다.
jsx/tsx 지원이 없습니다. 그 구현은 상당히 복잡했습니다. 사전 사용 사례의 경우 NVIM-TS-CONTEXT-CommentString을 사용하십시오. 통합은 pre_hook 섹션을 참조하십시오.
참고 -이 플러그인은 NVIM-Treesitter에 의존하지 않지만 트리 시터 파서를 쉽게 설치하기 위해 권장됩니다.
두 가지 후크 방법, 즉 pre_hook 및 post_hook 는 각각 댓글 이전 및 댓글 이후에 호출됩니다. 둘 다 setup() 중에 제공되어야합니다.
pre_hook ctx 인수와 함께 호출 (읽기 :h comment.utils.CommentCtx ) 전에 (un) 주석. 선택적으로 (un) 댓글에 사용될 commentstring 반환 할 수 있습니다. {
pre_hook = function ( ctx )
if ctx . range . srow == ctx . range . erow then
-- do something with the current line
else
-- do something with lines range
end
end ,
} pre_hook 사용하여 nvim-ts-context-commentstring을 통합하여 tsx/jsx 파일을 쉽게 주석 할 수 있습니다.
참고
Comment.nvim이미tsx/jsx제외한 모든 언어에 대한treesitter지원합니다.
{
pre_hook = require ( ' ts_context_commentstring.integrations.comment_nvim ' ). create_pre_hook (),
}post_hook 이 방법은 (un) 댓글을 달린 후 호출됩니다. 그것은 동일한 ctx (읽기 :h comment.utils.CommentCtx ) 인수를 pre_hook 과 수신합니다. {
post_hook = function ( ctx )
if ctx . range . srow == ctx . range . erow then
-- do something with the current line
else
-- do something with lines range
end
end ,
} post_hook 다음과 같은 일부 틈새 사용 사례를 다루기 위해 구현할 수 있습니다.
#if 0 과 함께 C에서 코드를 주석하기 위해 패딩하는 대신 NewLines를 사용합니다. 여기 예를 참조하십시오.pre_hook 사용) 커서를 다음 블록 ( post_hook 사용)으로 이동합니다. 이것을 참조하십시오.참고 :
gc,gb및 Friends를 누르면pre_hook내부의cmode(Commode) (댓글 모드)를 누르면 pre-hook이 호출 될 때gc또는gb라인에 주석을 주는지 또는 무례한 지 알 수 없습니다. 그러나 운 좋게도, 우리는post_hook전에 이것을 알고 있으며 이것은 항상 의견이나 무책임 상태를받을 것입니다.
주석/무책임 중에 특정 줄을 무시하는 데 ignore 수 있습니다. lua regex 문자열 또는 regex 문자열을 반환하는 함수를 취할 수 있으며 setup() 중에 제공되어야합니다.
참고 : LineWise 댓글이있는 경우에만 무시합니다. 이것은 디자인에 의한 것입니다. 블록 댓글의 라인을 무시하는 것은 그리 이해되지 않습니다.
string 로 -- ignores empty lines
ignore = ' ^$ '
-- ignores line that starts with `local` (excluding any leading whitespace)
ignore = ' ^(%s*)local '
-- ignores any lines similar to arrow function
ignore = ' ^const(.*)=(%s?)%((.*)%)(%s?)=> 'function 으로 {
ignore = function ()
-- Only ignore empty lines for lua files
if vim . bo . filetype == ' lua ' then
return ' ^$ '
end
end ,
} 대부분의 언어/파일 타입은 commentstring 통한 댓글을 기본적으로 지원하지만 지원되지 않는 파일 유형이있을 수 있습니다. 지원되지 않는 필레 타입에 대한 주석을 활성화하는 두 가지 방법이 있습니다.
commentstring 설정할 수 있습니다. 읽기 :h commentstring 더 많은 정보를 얻으십시오. vim . bo . commentstring = ' //%s '
-- or
vim . api . nvim_command ( ' set commentstring=//%s ' )commentstring 로 취급 할 수 있습니다. 읽기 :h comment.ft 더 많은 정보를 얻으려면. local ft = require ( ' Comment.ft ' )
-- 1. Using set function
ft
-- Set only line comment
. set ( ' yaml ' , ' #%s ' )
-- Or set both line and block commentstring
. set ( ' javascript ' , { ' //%s ' , ' /*%s*/ ' })
-- 2. Metatable magic
ft . javascript = { ' //%s ' , ' /*%s*/ ' }
ft . yaml = ' #%s '
-- Multiple filetypes
ft ({ ' go ' , ' rust ' }, ft . get ( ' c ' ))
ft ({ ' toml ' , ' graphql ' }, ' #%s ' )PR (S)은 플러그인 내부에 댓글 문장을 더 추가 할 수 있습니다.
보고/수정 버그, 기능 요청에 기여하는 여러 가지 방법이 있습니다. Ft.lua를 업데이트하고 PR을 보내 면서이 플러그인에 CommentString을 제출할 수도 있습니다.
/**%s*/ (JS), ///%s (Rust) ---- ------------------
-- This is a header --
---- ------------------