tomtom / tcomment_vim

An extensible & universal comment vim-plugin that also handles embedded filetypes

Home Page:http://www.vim.org/scripts/script.php?script_id=1173

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inline comment does not work correctly when visual selection spans multiple lines

lilyball opened this issue · comments

If I go into characterwise Visual mode and press <C-_>i it wraps the selection in an inline comment. But if my selection spans multiple lines, it does not wrap the selection. Instead it wraps a span of text on the cursor line where the start column is the minimum of the column for the start and end, and the end column is the maximum. It's a little hard to describe, it's easy enough to see in practice.

In a blank buffer with the filetype set to "C" (or any other language with inline comments), run:

:exe "normal!" "ithis is\<CR>foo\<Esc>" . "khvjll" 

This will produce a selection. Now press <C-_>i. The broken behavior should be obvious.

Again in an empty buffer, run:

:exe "normal!" "ithis is\<CR>a test\<Esc>0kllllvjhhh"

This will produce a similar selection except the cursor is now left of the start. Press <C-_>i again. Once again, broken behavior.

In both cases, if you press o to switch the cursor to the other end, the <C-_>i now comments out different text.

There's lots of weirdness with inline comments and block selections too, and with inline comments that touch the end of a line, or bizarrely, inline comments that should cover everything but the last character on a line that end up including that last character anyway.

Inline comments are actually that: comments within one line. Inline comments don't span multiple lines.

Inline style and block style are different though. Even if you think inline comments should never span a line break (which I strongly disagree with), that doesn't excuse the current behavior.

I admit one could discuss this behavior. One could also discuss though whether inline comments aren't bad style to begin with. In any case, inline comments are a pain to implement consistently for all possible settings of the various ever-growing number of related options. The bottom line is I wont change this. If you have the time and the energy to implement this, please submit a pull request. I'll be happy to integrate it.