Skip to content

Commit 265f7d6

Browse files
committed
feat: help docs :h comment-nvim
1 parent 0932d0c commit 265f7d6

File tree

12 files changed

+487
-512
lines changed

12 files changed

+487
-512
lines changed

README.md

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ There are two hook methods i.e `pre_hook` and `post_hook` which are called befor
254254

255255
<a id="pre-hook"></a>
256256

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.
257+
- `pre_hook` - This method is called with a `ctx` (Read `comment.utils.CommentCtx`) 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.
258258

259259
```lua
260260
-- NOTE: The example below is a proper integration and it is RECOMMENDED.
@@ -287,7 +287,7 @@ There are two hook methods i.e `pre_hook` and `post_hook` which are called befor
287287

288288
<a id="post-hook"></a>
289289

290-
- `post_hook` - This method is called after commenting is done. It receives the same [`ctx`](#comment-context) argument as [`pre_hook`](#pre_hook).
290+
- `post_hook` - This method is called after commenting is done. It receives the same `ctx` (Read `comment.utils.CommentCtx`) argument as [`pre_hook`](#pre_hook).
291291

292292
```lua
293293
{
@@ -407,40 +407,6 @@ Although, `Comment.nvim` supports neovim's `commentstring` but unfortunately it
407407

408408
> 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`
409409
410-
<a id="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-
---@class CommentCtx
421-
---@field ctype CommentType
422-
---@field cmode CommentMode
423-
---@field cmotion CommentMotion
424-
---@field range CommentRange
425-
426-
---Range of the selection that needs to be commented
427-
---@class CommentRange
428-
---@field srow integer Starting row
429-
---@field scol integer Starting column
430-
---@field erow integer Ending row
431-
---@field ecol integer Ending column
432-
```
433-
434-
`CommentType`, `CommentMode` and `CommentMotion` all of them are exported from the plugin's utils for reuse
435-
436-
```lua
437-
require('Comment.utils').ctype.{linewise,blockwise}
438-
439-
require('Comment.utils').cmode.{toggle,comment,uncomment}
440-
441-
require('Comment.utils').cmotion.{line,char,v,V}
442-
```
443-
444410
### 🤝 Contributing
445411

446412
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.

doc/API.md

Lines changed: 1 addition & 227 deletions
Original file line numberDiff line numberDiff line change
@@ -1,227 +1 @@
1-
# ⚙️ API
2-
3-
Following are list of APIs that are exported from the plugin. These can be used to setup [custom keybinding](#usage) or to make your own custom comment function. All API functions can take a `{motion}` (Read `:h :map-operator`) and a optional [`{cfg}`](../README.md#config) argument which can be used to override the [default configuration](../README.md#config)
4-
5-
<details>
6-
<summary>Deprecated API</summary>
7-
8-
```lua
9-
---@alias OpMode 'line'|'char'|'v'|'V' Vim operator-mode motions. Read `:h map-operator`
10-
```
11-
12-
### Core
13-
14-
These APIs powers the [basic-mappings](../README.md#basic-mappings).
15-
16-
```lua
17-
--######### LINEWISE #########--
18-
19-
---Toggle linewise-comment on the current line
20-
---@param cfg? CommentConfig
21-
require('Comment.api').toggle_current_linewise(cfg)
22-
23-
---(Operator-Pending) Toggle linewise-comment on the current line
24-
---@param opmode OpMode
25-
---@param cfg? CommentConfig
26-
require('Comment.api').toggle_current_linewise_op(opmode, cfg)
27-
28-
---(Operator-Pending) Toggle linewise-comment over multiple lines
29-
---@param opmode OpMode
30-
---@param cfg? CommentConfig
31-
require('Comment.api').toggle_linewise_op(opmode, cfg)
32-
33-
---Toggle linewise-comment over multiple lines using `vim.v.count`
34-
---@param cfg? CommentConfig
35-
require('Comment.api').toggle_linewise_count(cfg)
36-
37-
--######### BLOCKWISE #########--
38-
39-
---Toggle blockwise comment on the current line
40-
---@param cfg? CommentConfig
41-
require('Comment.api').toggle_current_blockwise(cfg)
42-
43-
---(Operator-Pending) Toggle blockwise comment on the current line
44-
---@param opmode OpMode
45-
---@param cfg? CommentConfig
46-
require('Comment.api').toggle_current_blockwise_op(opmode, cfg)
47-
48-
---(Operator-Pending) Toggle blockwise-comment over multiple lines
49-
---@param opmode OpMode
50-
---@param cfg? CommentConfig
51-
require('Comment.api').toggle_blockwise_op(opmode, cfg)
52-
53-
---Toggle blockwise-comment over multiple lines using `vim.v.count`
54-
---@param cfg? CommentConfig
55-
require('Comment.api').toggle_blockwise_count(cfg)
56-
```
57-
58-
### Extra
59-
60-
These APIs powers the [extra-mappings](../README.md#extra-mappings) and also provides the blockwise version.
61-
62-
```lua
63-
--######### LINEWISE #########--
64-
65-
---Insert a linewise-comment below
66-
---@param cfg? CommentConfig
67-
require('Comment.api').insert_linewise_below(cfg)
68-
69-
---Insert a linewise-comment above
70-
---@param cfg? CommentConfig
71-
require('Comment.api').insert_linewise_above(cfg)
72-
73-
---Insert a linewise-comment at the end-of-line
74-
---@param cfg? CommentConfig
75-
require('Comment.api').insert_linewise_eol(cfg)
76-
77-
--######### BLOCKWISE #########--
78-
79-
---Insert a blockwise-comment below
80-
---@param cfg? CommentConfig
81-
require('Comment.api').insert_blockwise_below(cfg)
82-
83-
---Insert a blockwise-comment above
84-
---@param cfg? CommentConfig
85-
require('Comment.api').insert_blockwise_above(cfg)
86-
87-
---Insert a blockwise-comment at the end-of-line
88-
---@param cfg? CommentConfig
89-
require('Comment.api').insert_blockwise_eol(cfg)
90-
```
91-
92-
### Extended
93-
94-
These APIs powers the [extended-mappings](../README.md#extended-mappings).
95-
96-
```lua
97-
--######### LINEWISE #########--
98-
99-
---Comment current line using linewise-comment
100-
---@param cfg? CommentConfig
101-
require('Comment.api').comment_current_linewise(cfg)
102-
103-
---(Operator-Pending) Comment current line using linewise-comment
104-
---@param opmode OpMode
105-
---@param cfg? CommentConfig
106-
require('Comment.api').comment_current_linewise_op(opmode, cfg)
107-
108-
---(Operator-Pending) Comment multiple line using linewise-comment
109-
---@param opmode OpMode
110-
---@param cfg? CommentConfig
111-
require('Comment.api').comment_linewise_op(opmode, cfg)
112-
113-
---Uncomment current line using linewise-comment
114-
---@param cfg? CommentConfig
115-
require('Comment.api').uncomment_current_linewise(cfg)
116-
117-
---(Operator-Pending) Uncomment current line using linewise-comment
118-
---@param opmode OpMode
119-
---@param cfg? CommentConfig
120-
require('Comment.api').uncomment_current_linewise_op(opmode, cfg)
121-
122-
---(Operator-Pending) Uncomment multiple line using linewise-comment
123-
---@param opmode OpMode
124-
---@param cfg? CommentConfig
125-
require('Comment.api').uncomment_linewise_op(opmode, cfg)
126-
127-
--######### BLOCKWISE #########--
128-
129-
---Comment current line using linewise-comment
130-
---@param cfg? CommentConfig
131-
require('Comment.api').comment_current_blockwise(cfg)
132-
133-
---(Operator-Pending) Comment current line using blockwise-comment
134-
---@param opmode OpMode
135-
---@param cfg? CommentConfig
136-
require('Comment.api').comment_current_blockwise_op(opmode, cfg)
137-
138-
---Uncomment current line using blockwise-comment
139-
---@param cfg? CommentConfig
140-
require('Comment.api').uncomment_current_blockwise(cfg)
141-
142-
---(Operator-Pending) Uncomment current line using blockwise-comment
143-
---@param opmode OpMode
144-
---@param cfg? CommentConfig
145-
require('Comment.api').uncomment_current_blockwise_op(opmode, cfg)
146-
```
147-
148-
</details>
149-
150-
### Core
151-
152-
> **NOTE**:
153-
>
154-
> 1. All API functions are dot-repeatable except `*.count()`
155-
> 2. For the `*.current()` functions, `{motion}` argument is optional
156-
> 3. `{cfg}` is optional for all the API functions
157-
158-
```lua
159-
require('Comment.api').toggle.linewise(motion, cfg)
160-
require('Comment.api').toggle.linewise.current(motion, cfg)
161-
require('Comment.api').toggle.linewise.count(count, cfg)
162-
163-
require('Comment.api').toggle.blockwise(motion, cfg)
164-
require('Comment.api').toggle.blockwise.current(motion, cfg)
165-
require('Comment.api').toggle.blockwise.count(count, cfg)
166-
167-
require('Comment.api').comment.linewise(motion, cfg)
168-
require('Comment.api').comment.linewise.current(motion, cfg)
169-
require('Comment.api').comment.linewise.count(count, cfg)
170-
171-
require('Comment.api').comment.blockwise(motion, cfg)
172-
require('Comment.api').comment.blockwise.current(motion, cfg)
173-
require('Comment.api').comment.blockwise.count(count, cfg)
174-
175-
require('Comment.api').uncomment.linewise(motion, cfg)
176-
require('Comment.api').uncomment.linewise.current(motion, cfg)
177-
require('Comment.api').uncomment.linewise.count(count, cfg)
178-
179-
require('Comment.api').uncomment.blockwise(motion, cfg)
180-
require('Comment.api').uncomment.blockwise.current(motion, cfg)
181-
require('Comment.api').uncomment.blockwise.count(count, cfg)
182-
```
183-
184-
### Additional
185-
186-
```lua
187-
---Callback function to provide dot-repeat support
188-
---NOTE: VISUAL mode mapping doesn't support dot-repeat
189-
---@param cb string Name of the API function to call
190-
require('Comment.api').call(cb)
191-
```
192-
193-
<a id="usage"></a>
194-
195-
# ⚙️ Usage
196-
197-
Following are some example keybindings using the APIs.
198-
199-
```lua
200-
-- # NORMAL mode
201-
202-
-- Linewise toggle current line using C-/
203-
vim.keymap.set('n', '<C-_>', '<CMD>lua require("Comment.api").toggle.linewise.current()<CR>')
204-
-- or with dot-repeat support
205-
-- vim.keymap.set('n', '<C-_>', '<CMD>lua require("Comment.api").call("toggle.linewise.current")<CR>g@$')
206-
207-
-- Blockwise toggle current line using C-\
208-
vim.keymap.set('n', '<C-\\>', '<CMD>lua require("Comment.api").toggle.blockwise.current()<CR>')
209-
-- or with dot-repeat support
210-
-- vim.keymap.set('n', '<C-\\>', '<CMD>lua require("Comment.api").call("toggle.blockwise.current")<CR>g@$')
211-
212-
-- Linewise toggle multiple line using <leader>gc with dot-repeat support
213-
-- Example: <leader>gc3j will comment 4 lines
214-
vim.keymap.set('n', '<leader>gc', '<CMD>lua require("Comment.api").call("toggle.linewise")<CR>g@')
215-
216-
-- Blockwise toggle multiple line using <leader>gc with dot-repeat support
217-
-- Example: <leader>gb3j will comment 4 lines
218-
vim.keymap.set('n', '<leader>gb', '<CMD>lua require("Comment.api").call("toggle.blockwise")<CR>g@')
219-
220-
-- # VISUAL mode
221-
222-
-- Linewise toggle using C-/
223-
vim.keymap.set('x', '<C-_>', '<ESC><CMD>lua require("Comment.api").toggle.linewise(vim.fn.visualmode())<CR>')
224-
225-
-- Blockwise toggle using <leader>gb
226-
vim.keymap.set('x', '<leader>gb', '<ESC><CMD>lua require("Comment.api").toggle.blockwise(vim.fn.visualmode())<CR>')
227-
```
1+
`Comment.nvim` now has `:help` docs 🎉. Read `:h comment.api` for the Lua API documentation and usage.

doc/plugs.md

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
## 🔌 Plug Mappings
2-
3-
Following are the `<Plug>` mappings which you can use to quickly setup your custom keybindings
4-
5-
- `<Plug>(comment_toggle_linewise)` - Toggles line comment via Operator pending mode
6-
- `<Plug>(comment_toggle_blockwise)` - Toggles block comment via Operator pending mode
7-
- `<Plug>(comment_toggle_linewise_current)` - Toggles line comment on the current line
8-
- `<Plug>(comment_toggle_blockwise_current)` - Toggles block comment on the current line
9-
- `<Plug>(comment_toggle_linewise_count)` - Toggles line comment with count
10-
- `<Plug>(comment_toggle_blockwise_count)` - Toggles block comment with count
11-
- `<Plug>(comment_toggle_linewise_visual)` - Toggles line comment in VISUAL mode
12-
- `<Plug>(comment_toggle_blockwise_visual)` - Toggles block comment in VISUAL mode
13-
14-
> NOTE: There are only meant for custom keybindings but If you want to create a custom comment function then be sure to check out all the [API](./API.md).
15-
16-
#### Usage
17-
18-
Following snippets is same as the default mappings set by the plugin.
19-
20-
```lua
21-
local opt = { expr = true, remap = true, replace_keycodes = false }
22-
23-
-- Toggle using count
24-
vim.keymap.set('n', 'gcc', "v:count == 0 ? '<Plug>(comment_toggle_linewise_current)' : '<Plug>(comment_toggle_linewise_count)'", opt)
25-
vim.keymap.set('n', 'gbc', "v:count == 0 ? '<Plug>(comment_toggle_blockwise_current)' : '<Plug>(comment_toggle_blockwise_count)'", opt)
26-
27-
-- Toggle in Op-pending mode
28-
vim.keymap.set('n', 'gc', '<Plug>(comment_toggle_linewise)')
29-
vim.keymap.set('n', 'gb', '<Plug>(comment_toggle_blockwise)')
30-
31-
-- Toggle in VISUAL mode
32-
vim.keymap.set('x', 'gc', '<Plug>(comment_toggle_linewise_visual)')
33-
vim.keymap.set('x', 'gb', '<Plug>(comment_toggle_blockwise_visual)')
34-
```
1+
`Comment.nvim` now has `:help` docs 🎉. Read `:h comment.plugmap` for the `<Plug>` mappings documentation and usage.

dump.lua

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)