-
Notifications
You must be signed in to change notification settings - Fork 103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature request] Text object for comments #237
Comments
@robertjk You might find following two plugins helpful to use together with vim-commentary: |
Thanks. Actually that's what I'm on right now: vim-commentary + vim-context-commentstring. Still I thought it's good to make this plugin better by adding comment textobject support. |
I certainly agree with you. tcomment + text object pluginIf you prefer tcomment with its support for embedded languages over vim-commentary + vim-context-commentstring, you could go the other way and add a text object comment plugin to tcomment: Also the textobj-syntax should do it see following comment by tomtom himself: #154 (comment) Implementation in commentaryWhen I see the sloc count of The lines for setting up the mapping should also be quite similar: onoremap <silent> <Plug>Commentary :<C-U>call <SID>textobject(get(v:, 'operator', '') ==# 'c')<CR>
" ...
omap gc <Plug>Commentary
" ... However, vim-commentary is a simpler commenting plugin considering only linewise comments. Existing code with name "textobject" in tcommentIt seems to be that there is already an experimental text object
A search through the issues reveals a few matches as well |
Also the textobj-syntax should do it
* https://github.com/kana/vim-textobj-syntax
The syntax textobj works well for line-wise comments.
The situation is more tricky for inline and block comments. It works but
not in a consistent way. Sometimes, you have to try different maps to
issue the right command and it is not easy to tell in advance which map
behaves how. To make this work consistently would require some
finetuning I currently don't have time for.
|
This addresses tomtom#255 and tomtom#188. It also partially addresses tomtom#237 (by making it clear that the functionality exists, even if it doesn't quite do what's being asked for there).
At least today, tcomment has the |
This is a feature request.
Feature description
vim-commentary plugin has a text object for comment (
gc
), which you can use in operator pending mode. It selects the whole comment - all the adjacent lines which are commented - from anywhere within that comment. I find that a very convenient feature that allows for quick operations on the whole comment without a need to precisely select it.As vim-commentary plugin has no support for embedded file types, which I find essential in modern programming, I'd love this feature implemented here, where embedded file types are supported.
Feature use cases
I find text object especially useful to delete commented code after I decide I'll no longer be using it - it's just a matter of doing
dgc
then.The other result of that is a very useful shortcut
gcgc
, which uncomments the whole comment (instead of just a single line) from anywhere within that comment, without the need to precisely select the whole comment.Example usage
An example to make it clear:
Being anywhere in the lines 2-6 and pressing
dgc
would produce:Being anywhere in the lines 2-6 and pressing
gcgc
would produce:The text was updated successfully, but these errors were encountered: