Questions tagged [comments]

Comments are programmer-readable annotations in source code which are ignored by the parser.

Filter by
Sorted by
Tagged with
59
votes
3answers
22k views

How can I get vim to stop putting comments in front of new lines?

I'm editing my .vimrc file, and I am including comments. When I have a comment like this: " example comment And then hit enter at the end of the line after finishing the comment, the next line is ...
38
votes
11answers
5k views

How to comment out a set of lines which are selected in visual mode?

How do I comment out multiple in visual mode selected lines? How do I make it language specific? For example, if the first 4 lines are selected: def foo(a,b): for each in (a,b): print ...
15
votes
4answers
3k views

Adding 80-column wide comment header block with centered text

For some reason or another I often divide the code into subsections separated by headers like these: ################################################################################ ##################...
12
votes
2answers
5k views

Hide certain lines completely (not folding)

I would like to be able to hide certain lines in my buffer from showing up at all (and being able to toggle seeing them). I found similar questions, but they don't solve my problem. I don't want to ...
11
votes
2answers
14k views

How to toggle comments with ctrl+/? [duplicate]

I'm coming from Atom, and with that I can highlight multiple lines and hit ctrl/ and it'll toggle comments for those lines. I how easy this is. Can I do something similar using ctrl/ with vim? I don'...
8
votes
3answers
522 views

How can I create a /* comments section with /// like in XCode?

In XCode, there is an add-on called vvdocument, which can detect three / hits, and transfer /// into: /*! * @author Robbie Yi JIANG, 29-Jan-2016 14:01:45 * * */ How can I do this in Vim.
7
votes
1answer
1k views

Is it possible to add inline comments in a multiline statement?

I have a function that looks like fu! MultiLineTest(u, v) if a:u != 2 && \ a:v != 2 return 'yes' else return 'no' end endfu Of course, the actual ...
6
votes
2answers
2k views

Configure custom key mapping for plugin actions

I am using https://github.com/scrooloose/nerdcommenter/ plugin to comment the code. It's working fine, but I would like to do a modification. Currently these are the default mappings: <leader>...
5
votes
4answers
1k views

How to generate patterns for comments?

As a way of organizing my codes, I like to include some titles as comments with specific patterns (I wish I can add ASCII art!). Consider for example, putting the following to mark a specific block of ...
5
votes
2answers
576 views

Create indented comment box vim

Background I have a code file and I like to place comments inside my code. Sometimes, these comments are boxed: defmodule BananasModule do ############## # Public API # ############## ...
5
votes
1answer
183 views

gqip for VHDL comments does not work

After I set syntax=vhdl and set fo=tcq, running gqip on the following paragraph does not work as expected: -- Lorem ipsum dolor sit amet, -- tempor incididunt ut labore et dolore magna aliqua. Ut ...
5
votes
1answer
125 views

Edit comments as if separate lines?

Is there a way to edit comments so that they will all be aligned without having to align them manually with tab? i.e., How can I get something like that? some text %comment some more text ...
5
votes
1answer
2k views

Uncomment multiline block with NERDCommenter

Is it possible using NERD-commenter to uncomment a multiline block under the cursor without selecting the entire block visually first? If no, are there any better plugins, that can do the job? Here ...
5
votes
1answer
484 views

A plugin to align comments

I often edit code where I have a general comment for a block of code and specific comment for each line. For instance, this a sample of my .vimrc. "indentation set autoindent "...
5
votes
3answers
714 views

Making a custom function to comment out a range of lines

I want to make block commenting easy. To comment out a range of lines, what I can do is something like: :17,21s/^/# This will comment lines 17 to 21 in Python. But I don't want to write the whole ...
5
votes
0answers
89 views

Comments pane for current buffer that you can jump to such as TODO:, WARN:, and NOTE:?

A while ago I used to use eclipse as my IDE, and I remember you could add TODO: some task, NOTE: some comment, WARN: some warning to your code, and it would appear in a particular pane for the current ...
4
votes
3answers
5k views

Uncomment multiple lines

In vim I can use for instance 10j to go 10 lines down. And I can use . to repeat the last deletion. Now, in bash script I have many commented lines like this: # ... # ... # ... # ... # ... # ... # .....
4
votes
3answers
618 views

How do I comment out lines without changing indentation?

I use Vim to write my Python source and use the debugging library pdb. Let's say I have this code with break points commented out: import pdb #pdb.set_trace() def func1(): #pdb.set_trace() ...
4
votes
2answers
190 views

Why are new lines under commented lines automatically commented too? [duplicate]

I will frequently use visual mode and the "norm" command to quickly comment out several lines. Let's say this is my text (line numbers added for clarity): 1. #include <iostream> 2. using ...
4
votes
2answers
3k views

vim comment out every line of text containing a pattern using the 'global' command

In my file containing LaTeX source code, I wish to comment out all the lines matching a pattern (specifically, the pattern that I am interested in is \draw, including the \ character). I have magic ...
4
votes
1answer
172 views

Is it possible to put vim comments in lines that include `iabbrev`

Is it possible to put vim comments in lines that include iabbrev, as in: iabbrev hte the " common typo
4
votes
1answer
908 views

How can I clearly document errorformat patterns in a plugin compiler file?

While testing out the vim-go plugin I encountered an issue that I wanted to look into more closely. In a comment on the issue, the owner of the plugin writes: The text read 0 byte, err read tcp 127....
4
votes
2answers
95 views

vim tcomment plugin changes the hyphens in untagged text (html) to html code (& #45;)

When editing html in vim, I'll write the class name of the section that I am working on like this: mid-med It is untagged plain text. I'll call tcomment to comment that out. What I expect to have ...
4
votes
0answers
73 views

How to get bold comments in vim

I am trying to add bold comments to my vim files. What i mean, is to be able to get something like this: I saw other articles like this that allow to toggle bold comment. The proposed solutions from ...
3
votes
1answer
12k views

How to comment a line in vim?

#inlcude<stdio.h> int main() { printf("Hello world\n"); } I want to comment line where the cursor is. For, example if I am on the line printf then I want to get following - #inlcude<...
3
votes
3answers
1k views

How can I return the current filetype's comment character in vimscript?

Simple question. I want to use the Tabular plugin to right-align end-of-line comments for arbitrary filetypes, and for that I need to write a simple nnoremap that uses the current filetype's comment ...
3
votes
2answers
284 views

write a key command for a markdown comment

I've been messing about with file type specific commands this evening (which is going to be very useful) and I'm trying to write a markdown comment command at the moment. I'm not sure how to go about ...
3
votes
1answer
356 views

Automatic comment leader not inserted on some file types

My formatoptions include cro. I have a filetype (Stata .do files) in which the comment character is *. Anything after this character is considered a comment line. In insert mode *<CR>* leads ...
3
votes
1answer
453 views

Vim "gq" command doesn't recognize Haskell-style comments

I have a Haskell file on VIM with a Haskell-style comment block: When I select that comment block on visual mode... And press gq, I expected VIM to format my comment to something like: But instead, ...
3
votes
1answer
316 views

Vim Comment Box Macro

I write comments of the form ############# ## Example ## ############# Always one line, always just like that. It's a way of breaking up code more visually. I have lately taken to the following way ...
3
votes
1answer
303 views

How to comment a line directly from bash using vim?

What I usually do from bash/vim ... is open file with vim go to line to comment comment a line save and quit My file is /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini and the initial content is [...
3
votes
1answer
159 views

Commenting out an element of a multiline list

Is it possible to comment out one element of a multiline list? Or, in general, can you combine line continuations with comments? (Lightly modified from my vimrc) [ \'eslint', \'tsserver', ...
3
votes
1answer
1k views

How to add JavaScript and JSX comments in the same .js file

I've been using Neovim to do the majority of my dev work for most of 2018 however something that has eluded me is being able to quickly toggle JSX comments {/* JSX */} and regular Javascript ...
3
votes
1answer
280 views

vim specific indentation for markdown

I want the indentation in markdown file as follows - [ ] Here is some text. When I press enter - [ ] <--- This entire thing should get populated. It means - [ ] should be copied onto the next ...
3
votes
2answers
93 views

Break long comments

Given the file alfa.c: // Lorem ipsum dolor sit amet, apeirian constituam interpretaris no his, soluta salutandi persequeris vel ne, facete impedit contentiones te eam. Ut utamur habemus qualisque ...
3
votes
2answers
101 views

Is there a way to insert documentation comments into a VIM macro definition?

I have found VI / VIM macros extremely obtuse to understand even a week after I've written them. The syntax of a .vimrc file supports comments on lines beginning with a doublequote character (") ...
3
votes
1answer
63 views

Match by syntax highlighting instead of expressions

I want to delete all the comments from a program. Vim already knows (in some sense) where all the comments are because it is correctly formatting them based on the syntax file the particular language ...
3
votes
3answers
190 views

Pretty python comments

I comment sections in python via a centered title surrounded by #. What I would like is to make a command so that I can automatically generate such headers. For example, to generate a line like the ...
3
votes
1answer
67 views

Different color for comments with one # and two ## in python

I would like to know if there is some way to color different comments in python inside VIM. Today I use wombat256mod and I would like to color in red comments that start with double ## and color with ...
3
votes
0answers
138 views

Formatting blocks of "commented out" text

I would like to be able to edit and format blocks of comments (in different markup and programming languages) as if the commenting characters (generally in the beginning of the lines) are ignored. ...
2
votes
2answers
1k views

visual mode gq not reflowing comment block

I am looking for an easy way to reflow blocks of comments (in GO). According to this post I should be able to just run gq on a block and it will reflow automatically, but this doesn't seem to work. ...
2
votes
2answers
113 views

How to disable auto insertion of comment header when pressing enter, but keep auto insertion of header when auto wrapping comment?

When editing c and cpp files, this is the behavior I want to achieve: When typing a comment line of the form // Line..., pressing <CR> should not add the comment header // in the next line. ...
2
votes
2answers
433 views

Adding new filetypes with vim commentary

I'm trying to add include an unsupported filetype, gf, with vim commentary. The comments are simple, just prepend -- to any line, as in the Haskell tradition. According to the vim-commentary git, ...
2
votes
1answer
2k views

Comment-out in vim with Shift-i not working

To comment out a block in vim, I enter visual mode with v or Control-v, select some lines, then hit I (Shift-i). However, I takes me out of visual mode and into Insert mode (which makes sense, as ...
2
votes
1answer
701 views

Folding my .vimrc doesn't work as expected

To structure my .vimrc a bit better I decided to create a custom fold expression in the file .vim/after/ftplugin/vim/folding.vim which gets loaded automatically for my .vimrc: " The purpose of this ...
2
votes
1answer
44 views

bad comment behavior in cmake files

When I'm editing a cmake file in (neo)vim I'm getting bad behavior block inserting comment characters. Given this section of text install_license_file( PACKAGE tomcrypt TARGET ...
2
votes
1answer
84 views

Vim doesn't extend Roxygen R comments

I'd like it if, when filling out my Roxygen comment snippet, #' Title #' #' @param #' #' @return #' #' @examples #' #' #' @export ...
2
votes
1answer
430 views

How do I highlight pc-lint comments in C/C++

How do I mimic the behavior of Doxygen comment highlighting for PC-lint comments? Comments are in the following formats: /*lint ... */ //lint ... /* LINTLIBRARY */ /* ARGUSED */ /* VARARGS[N] */ <--...
2
votes
1answer
258 views

What does Special Comment refer to in reference to a colorscheme?

I've recently delved into taking an existing colorscheme and customizing it to my liking. While doing this however, I found there was a highlight option for special comments and I'm not sure exactly ...
2
votes
1answer
303 views

NeoVim: Single-Line Comments Also Format the Next Line [duplicate]

So, I started using NeoVim a little while ago and discovered a rather annoying quirk when using C++-style single-line comments // in source code of any language. Specifically, when you create a new ...