You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Finally! We now have proper help docs for everything from keybindings to Lua API. It's auto generated from emmylua annotation so it would always be up to date.
Credits to https://github.com/phaazon/hop.nvim for excellent docs and reference.
- Supports line (`//`) and block (`/* */`) comments
11
11
- Dot (`.`) repeat support for `gcc`, `gbc` and friends
12
12
- Count support for `[count]gcc` and `[count]gbc`
@@ -37,6 +37,10 @@ Plug 'numToStr/Comment.nvim'
37
37
lua require('Comment').setup()
38
38
```
39
39
40
+
### 📖 Getting Help
41
+
42
+
`Comment.nvim` provides help docs which can be accessed by running `:help comment-nvim`
43
+
40
44
<aid="setup"></a>
41
45
42
46
### ⚒️ Setup
@@ -63,46 +67,31 @@ EOF
63
67
64
68
#### Configuration (optional)
65
69
66
-
Following are the **default** config for the [`setup()`](#setup). If you want to override, just modify the option that you want then it will be merged with the default config.
70
+
Following are the **default** config for the [`setup()`](#setup). If you want to override, just modify the option that you want then it will be merged with the default config. Read `:h comment.config` for more info.
67
71
68
72
```lua
69
73
{
70
74
---Add a space b/w comment and the line
71
-
---@typeboolean|fun():boolean
72
75
padding=true,
73
-
74
76
---Whether the cursor should stay at its position
75
-
---NOTE: This only affects NORMAL mode mappings and doesn't work with dot-repeat
76
-
---@typeboolean
77
77
sticky=true,
78
-
79
-
---Lines to be ignored while comment/uncomment.
80
-
---Could be a regex string or a function that returns a regex string.
81
-
---Example: Use '^$' to ignore empty lines
82
-
---@typestring|fun():string
78
+
---Lines to be ignored while (un)comment
83
79
ignore=nil,
84
-
85
80
---LHS of toggle mappings in NORMAL mode
86
-
---@typetable
87
81
toggler= {
88
82
---Line-comment toggle keymap
89
83
line='gcc',
90
84
---Block-comment toggle keymap
91
85
block='gbc',
92
86
},
93
-
94
-
---LHS of operator-pending mappings in NORMAL mode
95
-
---LHS of mapping in VISUAL mode
96
-
---@typetable
87
+
---LHS of operator-pending mappings in NORMAL and VISUAL mode
97
88
opleader= {
98
89
---Line-comment keymap
99
90
line='gc',
100
91
---Block-comment keymap
101
92
block='gb',
102
93
},
103
-
104
94
---LHS of extra mappings
105
-
---@typetable
106
95
extra= {
107
96
---Add comment on the line above
108
97
above='gcO',
@@ -111,29 +100,19 @@ Following are the **default** config for the [`setup()`](#setup). If you want to
111
100
---Add comment at the end of line
112
101
eol='gcA',
113
102
},
114
-
115
-
---Create basic (operator-pending) and extended mappings for NORMAL + VISUAL mode
116
-
---NOTE: If `mappings = false` then the plugin won't create any mappings
117
-
---@typeboolean|table
103
+
---Enable keybindings
104
+
---NOTE: If given `false` then the plugin won't create any mappings
118
105
mappings= {
119
-
---Operator-pending mapping
120
-
---Includes `gcc`, `gbc`, `gc[count]{motion}` and `gb[count]{motion}`
121
-
---NOTE: These mappings can be changed individually by `opleader` and `toggler` config
@@ -224,14 +203,6 @@ These mappings are disabled by default. (config: `mappings.extended`)
224
203
`gbac` - Toggle comment around a class (w/ LSP/treesitter support)
225
204
```
226
205
227
-
<aid="api"></a>
228
-
229
-
### ⚙️ API
230
-
231
-
-[Plug Mappings](./doc/plugs.md) - Excellent for creating custom keybindings
232
-
233
-
-[Lua API](./doc/API.md) - Details the Lua API. Great for making custom comment function.
234
-
235
206
<aid="treesitter"></a>
236
207
237
208
### 🌳 Treesitter
@@ -254,12 +225,10 @@ There are two hook methods i.e `pre_hook` and `post_hook` which are called befor
254
225
255
226
<aid="pre-hook"></a>
256
227
257
-
-`pre_hook` - This method is called with a [`ctx`](#comment-context) argument before comment/uncomment is started. It can be used to return a custom `commentstring`which will be used for comment/uncomment the lines. You can use something like [nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring) to compute the commentstring using treesitter.
228
+
-`pre_hook` - Called with a `ctx` argument (Read `:h comment.utils.CommentCtx`) before (un)comment. Can optionally return a `commentstring`to be used for (un)commenting. You can use [nvim-ts-context-commentstring](https://github.com/JoosepAlviste/nvim-ts-context-commentstring) to easily comment `tsx/jsx` files.
258
229
259
230
```lua
260
-
-- NOTE: The example below is a proper integration and it is RECOMMENDED.
261
231
{
262
-
---@paramctxCommentCtx
263
232
pre_hook=function(ctx)
264
233
-- Only calculate commentstring for tsx filetypes
265
234
ifvim.bo.filetype=='typescriptreact' then
@@ -285,13 +254,14 @@ There are two hook methods i.e `pre_hook` and `post_hook` which are called befor
-`post_hook` - This method is called after commenting is done. It receives the same [`ctx`](#comment-context) argument as [`pre_hook`](#pre_hook).
261
+
-`post_hook` - This method is called after (un)commenting. It receives the same `ctx` (Read `:h comment.utils.CommentCtx`) argument as [`pre_hook`](#pre_hook).
Most languages/filetypes have native support for comments via `commentstring` but there might be a filetype that is not supported. There are two ways to enable commenting for unsupported filetypes:
349
319
350
-
1. You can set `commentstring` for that particular filetype like the following
320
+
1. You can set `commentstring` for that particular filetype like the following. Read `:h commentstring` for more info.
2. You can also use this plugin interface to store both line and block commentstring for the filetype. You can treat this as a more powerful version of the `commentstring`
331
+
2. You can also use this plugin interface to store both line and block commentstring for the filetype. You can treat this as a more powerful version of the `commentstring`. Read `:h comment.ft` for more info.
> PR(s) are welcome to add more commentstring inside the plugin
393
359
394
-
<aid="commentstring"></a>
395
-
396
-
### 🧵 Comment String
397
-
398
-
Although, `Comment.nvim` supports neovim's `commentstring` but unfortunately it has the least priority. The commentstring is taken from the following place in the respective order.
399
-
400
-
-[`pre_hook`](#hooks) - If a string is returned from this method then it will be used for commenting.
401
-
402
-
-[`ft.lua`](#ft-lua) - If the current filetype is found in the table, then the string there will be used.
403
-
404
-
-`commentstring` - Neovim's native commentstring for the filetype
405
-
406
-
<aid="commentstring-caveat"></a>
407
-
408
-
> There is one caveat with this approach. If someone sets the `commentstring` (w/o returning a string) from the `pre_hook` method and if the current filetype also exists in the `ft_table` then the commenting will be done using the string in `ft_table` instead of using `commentstring`
409
-
410
-
<aid="comment-context"></a>
411
-
412
-
### 🧠 Comment Context
413
-
414
-
The following object is provided as an argument to `pre_hook` and `post_hook` functions.
415
-
416
-
> I am just placing it here just for documentation purpose
417
-
418
-
```lua
419
-
---Comment context
420
-
---@classCommentCtx
421
-
---@fieldctypeCommentType
422
-
---@fieldcmodeCommentMode
423
-
---@fieldcmotionCommentMotion
424
-
---@fieldrangeCommentRange
425
-
426
-
---Range of the selection that needs to be commented
427
-
---@classCommentRange
428
-
---@fieldsrowinteger Starting row
429
-
---@fieldscolinteger Starting column
430
-
---@fielderowinteger Ending row
431
-
---@fieldecolinteger Ending column
432
-
```
433
-
434
-
`CommentType`, `CommentMode` and `CommentMotion` all of them are exported from the plugin's utils for reuse
There are multiple ways to contribute reporting/fixing bugs, feature requests. You can also submit commentstring to this plugin by updating [ft.lua](./lua/Comment/ft.lua) and sending PR.
0 commit comments