|
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. |
0 commit comments