Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [comments]

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

Filter by
Sorted by
Tagged with
1 vote
0 answers
32 views

Possible to use the 'comments' option to check if a line is commented?

I am looking for a way to check if a line is commented or not. It should not be a filetype specific but should be commonly usable for a lot of filetypes. Note that there are single-line and multi-line ...
Rick Howe's user avatar
  • 363
1 vote
0 answers
26 views

How to use different comment string for yaml blocks inside markdown files?

Many markdown implementations allow for a leading yaml configuration block like so: --- title: "My title" date: 2023-12-29 --- ## Heading Some markdown text With the vim commentary plugin,...
joelostblom's user avatar
5 votes
2 answers
82 views

Don't auto-extend c/c++ trailing comments

Edit this C++ excerpt: // line 1 int xxxxxxxx = 0; // line 2 int yyyyyyyy = 0; When the cursor is in line 1 and you hit o to insert a line below it, Vim conveniently starts the new line with another /...
Camille Goudeseune's user avatar
2 votes
2 answers
707 views

Conceal comments in Vim/Neovim

I am writing a lot of latex and would like to conceal comments. There are often several lines of text that I comment but would like to keep/not delete. Concealing comments explained: A comment is ...
baxbear's user avatar
  • 314
0 votes
1 answer
21 views

How can add the comment lines when call function?

I want to add shebang when creating anew python file. .vimrc: autocmd BufNewFile *.py exec ":call SetTitle_py(0)" func SetTitle_py(line_num) let boilerplate = [ \"#!/usr/bin/...
showkey's user avatar
  • 1,140
0 votes
2 answers
36 views

Why the comment can't be set at the second line instead of first line?

I want to add some comment lines when to edit python file: vim .vimrc autocmd BufNewFile *.py exec ":call SetTitle_py()" func SetTitle_py() call append(line("."), "#...
showkey's user avatar
  • 1,140
2 votes
1 answer
45 views

:.w !bash a temporarily modified line and executing it in the shell

#!/usr/bin/env bash # scp /tmp/abc.sh SERVER1:~/bin && ssh SERVER1 "~/bin/abc.sh" echo "Hello Stack Exchange" echo "thanks for the help I would like to be able to use ...
Aaron Burda's user avatar
0 votes
0 answers
293 views

block comments not automatically indented in Neovim

When inserting a block comment in a (TypeScript) buffer in Neovim, the line after the /**<Return> is not automatically indented. How can I achieve the expected behavior described below? Neovim ...
KIYZ's user avatar
  • 101
1 vote
0 answers
53 views

Stop foldmarker inserting hash

I my folds are set with foldmarker={{{,}}}. When I create a fold it inserts a comment # char before the marker. So it inserts #{{{. How do I stop it doing this? I have syntax highlighting (and it ...
markling's user avatar
  • 389
2 votes
1 answer
43 views

A question about the comment for comment shell command

When I read the comment help file, I found It is not possible to add a comment to a shell command ":!cmd" or to the ":map" command and a few others (mainly commands that expect ...
lizhe's user avatar
  • 137
0 votes
1 answer
620 views

How do you disable all magic comment formatting in neovim?

I recently switched to Neovim's new LSP setup instead of the old Vim-based language plugins and now I get this incredibly annoying comment "helper" behavior when I hit enter after a /** in e....
Qix - MONICA WAS MISTREATED's user avatar
2 votes
1 answer
392 views

How to comment html in php file in vim?

I use this plugin for comments. Plug 'tpope/vim-commentary' And when I comment html code in php I get /* <div class="our-photos"> */ /* <h2 class="our-photos__main-title"...
serii 's user avatar
  • 91
0 votes
0 answers
22 views

Plug-in to create comment layer

Is there any plug-in where you can write text without being in insert mode but it’s not being written to the actual file? If you enter insert mode, all that comment text disappears. It should be in a ...
Julius Hamilton's user avatar
0 votes
1 answer
461 views

Automatic removal of indent in markdown (fenced) codeblock comments starting with #

When writing indented fenced codeblocks (the only ones I use) like ```sh some shell code ``` in markdown the indentation of comments is automatically removed when I type the comment ...
Stefan's user avatar
  • 179
0 votes
0 answers
63 views

Marking/Annotating lines with symbols (with external storage)

When I audit code I perform a lot of annotations/mark lines. (what audited, by whom, if we have open issue, etc etc...). When I work with code I would like to mark lines (both individually and ranges),...
Grzegorz Wierzowiecki's user avatar
3 votes
1 answer
197 views

Reformatting comments with gq, using spaces in 'comments'

I'm using Prettier to automatically reformat JavaScript (well, TypeScript, but same deal in this situation) source-code. It enforces a comment-style like this, with leading spaces replaced with ·: ···/...
ELLIOTTCABLE's user avatar
6 votes
0 answers
560 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 ...
needle's user avatar
  • 181
1 vote
1 answer
100 views

Insert and remove a marker at the start of the current line

So, I'm trying to set up a sort of bookmark/marker kind of workflow, and I came to notice I'm used to put characters such as # and such for different meaning inside my own notes, etc. Now, I already ...
Nordine Lotfi's user avatar
2 votes
1 answer
163 views

Check if vim is in a comment section

How can I check if the cursor is inside a comment section like this in C: /* * Comment section */ Or in python: """ Doc string """ # Comment line My idea for C is, ...
TornaxO7's user avatar
  • 571
1 vote
1 answer
49 views

Why does this pattern make :global work only on the first line of the highligted match?

\/\*.*\(\n\s\*.*\)*\n\s\*\/ is a pattern which I cooked up to match some multi-line C comments, i.e., in the format of: /* Comment Text * Comment Text * Comment Text */ Searching for the pattern ...
Monke's user avatar
  • 13
2 votes
1 answer
119 views

Commentary with a Single Block

With Commentary I've set the commentstring for markdown: autocmd FileType markdown setlocal commentstring=<!--\ %s\ --> When I visually select the lines and gc a b c I get <!-- a --> <...
laktak's user avatar
  • 2,943
2 votes
2 answers
2k 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, ...
Warrick Macmillan's user avatar
0 votes
1 answer
801 views

Change default character for comments

The assigned character for comments is " for vimscript. But i want to change it to some other character (like * or # for example). Based on this post, it seems like the string setlocal ...
Nordine Lotfi's user avatar
1 vote
2 answers
153 views

How to comment out only code lines and not existing comments

I use vim-commentary to comment. Hit g-c-c to toggle comments. But this will comment out the already existing comments if they start with // and it will comment out already existing comments startin ...
Salahuddin Ahmed's user avatar
3 votes
2 answers
270 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 double-quote character (") ...
August's user avatar
  • 141
0 votes
1 answer
249 views

How are quotation marks used in this dotfile?

I'm a complete Linux beginner, trying to understand dotfiles. I've got the .vimrc dotfile, and tried to add the following command to the bottom: " <Ctrl-l> redraws the screen and removes ...
Lou's user avatar
  • 103
2 votes
1 answer
81 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 ...
ryan0270's user avatar
  • 123
2 votes
2 answers
197 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. ...
Diggs's user avatar
  • 75
1 vote
2 answers
54 views

Autoindent unordered lists that start with a hyphen in cpp files

The context I've the following options in my vimrc set formatoptions=cnroqj set textwidth=80 When editing tex files, lines whose content is longer than &textwidth is splitted and formatted as ...
gfe's user avatar
  • 245
1 vote
2 answers
74 views

Defining a color to be the same color of comments

I'm using the indentLine plugin to display line indents with a continuos vertical line, and I'd like to set the color of that line to the same color of my comments. To get the foreground color of my ...
noibe's user avatar
  • 189
5 votes
1 answer
8k 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 ...
Joshua Fox's user avatar
3 votes
1 answer
163 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', ...
0az's user avatar
  • 133
3 votes
1 answer
531 views

Comment highlight group does not work without reloading .vimrc

The following line in my ~/.vimrc: hi Comment ctermfg=gray does not take effect unless I start Vim and then use :source to reload .vimrc. As far as I can tell, all of the other hi commands work ...
jth's user avatar
  • 133
1 vote
1 answer
70 views

Automatically fold particular content, in any filetype

I often find myself patching projects that add a relatively big (23 lines out of a 37-line file? ) license-header to every. single. file. Is there a plugin or straightforward way I can add a global ...
ELLIOTTCABLE's user avatar
3 votes
3 answers
409 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 ...
Throckmorton's user avatar
1 vote
1 answer
65 views

Are there comments in command-line mode?

Does VIM support comments in command-line mode? I have tried the most popular variants including .VIMRC comments but neither worked: :echo "hello" // echo usage :echo "hello" /* echo usage */ :echo "...
ka3ak's user avatar
  • 261
6 votes
3 answers
861 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 # ############## ...
Flame_Phoenix's user avatar
2 votes
0 answers
444 views

Javascript syntax-highlight for JsDoc comments

I now use plugin vim-javascript just to have a nice syntax highlight for JsDoc comments in my Javascript files. vim-javascript provides nice colors highlight but it conflict with all parentheses ...
Giorgio Robino's user avatar
1 vote
1 answer
180 views

MatchIt not matching anymore if parenthesis, brackets, etc. are between quotes or in comments?

I upgraded to Ubuntu 18.04 and this has Vim version 8.0. This newer version has MatchIt setup to ignore parenthesis, brackets, etc. found inside comments and strings. Although it is at times useful, ...
Alexis Wilke's user avatar
0 votes
0 answers
147 views

Auto-insert C++ comment only on <shift+enter>

The comment auto-insert feature is often very helpful and otherwise very annoying, depending on the kind of comment I am writing. Is it possible to bind the auto-insertion of // exclusively to <...
Byron Hawkins's user avatar
0 votes
1 answer
420 views

How to set a shortcut for multiple leader commands

I'm using the nerdcommenter to comment and uncomment my c++ code. Basically I use \cc to comment one line, \cu to uncomment, \ca to switch the delimiters (switch // to /**/ or switch back). Now I ...
Yves's user avatar
  • 1,023
2 votes
1 answer
175 views

Vim and enhanced commentify weird behavior for C

I am trying to use EnhancedCommentify plugin for vim and mostly using C. However I can't figure out the issue but when I comment/uncomment it uses (* ---- \*) instead of /* ----- \*/. I tried to ...
Jacques's user avatar
  • 21
1 vote
1 answer
221 views

Alert sound when using <C-L> etc. mappings

I've got these mappings in my .vimrc: nnoremap <C-Tab> :tabn<cr> " cycle tabs nnoremap <C-S-Tab> :tabp<cr> " cycle tabs backward nnoremap <C-J> <C-W><C-J&...
Jacktose's user avatar
  • 873
1 vote
1 answer
216 views

use J to join comments

Imagine I have comments // line one // line two and I am on line one and want to join it with line two I will press J but that results in this: // line one // line two Instead of what I want // ...
minseong's user avatar
  • 2,333
2 votes
1 answer
1k 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 ...
Anadian's user avatar
  • 23
2 votes
1 answer
74 views

Mapping to insert comment at the end of a line

I'm currently writing a plugin to quickly appends commented TODO: codetags to the end of a line in any file type. How can I make vim make use of it's commenstring feature to append a comment that ...
Benjamin Chausse's user avatar
0 votes
0 answers
161 views

How do I get Vim (with TComment) to do proper block comments in OCaml?

(I have TComment installed, and I'm on NeoVim 0.4.0.) Given this code, for example: let mem key st = let is_matching_key = function | Positional _ -> false | Flag f -> f.name == key ...
ELLIOTTCABLE's user avatar
0 votes
1 answer
601 views

How can I make Vimscript check if the current line has a comment?

I want to make a Python ftplugin (but other filetypes will also have this option) where, if the previous line has a comment that starts with #, the next line can be commented via <Shift><CR&...
Paul Kim's user avatar
  • 241
2 votes
1 answer
122 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 ...
brandones's user avatar
  • 123
2 votes
0 answers
53 views

Applying full auto-format to comments but not code

I am considering using Vim's auto-format feature (i.e., adding a to formatoptions). However, I can't seem to figure out a combination of options that will give me the configuration that I want. For ...
sasquires's user avatar
  • 121