2

Consider the following snippet,

def foo():
    do_something()
    do_something_else()
    print('Hello!')
    return 0

is there a plugin able to comment it as illustrated below

def foo():
    do_something()
    do_something_else()
#   print('Hello!')
    return 0

instead of,

def foo():
    do_something()
    do_something_else()
    # print('Hello!')
    return 0

Likewise, for LaTeX,

\begin{itemize}
    \item Accent
    \item Dialect
    \item Register
    \item Discourse analysis
    \item Language varieties
    \item Linguistic description
    \item Pragmatics
    \item Variation
\end{itemize}
\begin{itemize}
    \item Accent
    \item Dialect
    \item Register
%   \item Discourse analysis
    \item Language varieties
    \item Linguistic description
    \item Pragmatics
    \item Variation
\end{itemize}

and for C++,

    strncpy (protobuf, protocol, PROTOBUFSIZE - 1);
    protobuf[PROTOBUFSIZE-1] = '\0';

    for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
        if (isupper ((unsigned char)protobuf[i]))
            protobuf[i] = tolower ((unsigned char)protobuf[i]);
    strncpy (protobuf, protocol, PROTOBUFSIZE - 1);
//  protobuf[PROTOBUFSIZE-1] = '\0';

    for (i = 0; i < PROTOBUFSIZE && protobuf[i] != '\0'; i++)
        if (isupper ((unsigned char)protobuf[i]))
            protobuf[i] = tolower ((unsigned char)protobuf[i]);
3
  • 2
    Vim-commentary can do it. I have provided a patch(like a year or smth ago) that adds an option for a filetype to add comment chars at column 1.
    – Maxim Kim
    Jun 27 at 14:05
  • 2
  • 2
    @MaximKim Thank you! Would you turn your comments into an answer so that I can accept it? Jun 27 at 15:29
3

Use vim-commentary plugin, it has buffer-local variable b:commentary_startofline you can setup per filetype:

let b:commentary_startofline = 1

See patch https://github.com/tpope/vim-commentary/commit/62b68aecec2de531bc3978bfb9c07d3b6759ce0e

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.