glts / vim-textobj-comment

Vim text objects for comments
http://www.vim.org/scripts/script.php?script_id=4570
131 stars 8 forks source link

Select from cursor to the end of current comment #6

Closed powerman closed 7 years ago

powerman commented 7 years ago

I'm get used to gq} for usual text - previous part of paragraph is usually already formatted (and sometimes manually, a bit different from default formatting), and I need to auto-reformat only rest of current paragraph. I'd like to use same for comments, but motions you've defined didn't allow to select "to the end of comment block".

Can you please add this feature, or at least give me quick hint what to patch in your plugin for this?

glts commented 7 years ago

I understand, but what you are looking for is a motion command, not a text object.

Text objects often have motion commands to go alongside: paragraph ap goes together with { }, sentence as with ( ), word aw with b e, and so on.

This plugin only does comment text objects, so unfortunately this is out of scope.

powerman commented 7 years ago

Is there any reason why "object" can't just start at cursor position? If I get it correctly, then "object" lifetime is limited to current command, so this shouldn't be an issue, isn't it?

glts commented 7 years ago

Sure, I think in principle it is possible. I just cannot think of any text object in Vim that does it this way, and to me consistency with Vim is important.

Anyway, since this plugin uses textobj-user, perhaps there is a starting point there to implement this … I haven’t checked.

powerman commented 7 years ago

I've solved this using

autocmd FileType go nnoremap <buffer> Q}
    \ gq/\m\%#.*\(^\s*\/\/.*\)\@<=\(\n\s*\/\/.*\S.*\)*\(\n\s*\)*\ze/e+1<CR>

It contains hardcoded comment marker //, but it's not a big deal to duplicate this for several file types/comment markers. Will be more complicated in case /* … */, if someone needs that too.