39

Possible Duplicate:
How do comments work?

How do I add code while writing comments and how do I enter a newline character?

6
  • Writing what comments? Not sure I understand
    – Pekka
    Jan 12, 2011 at 18:41
  • While commenting to an answer / question.. When i hav to include a code sample, there s not formattin option lik available for asking a question
    – CHID
    Jan 12, 2011 at 18:43
  • 4
    Like this: This is code.
    – John
    Jan 12, 2011 at 18:44
  • You don't add newlines in comments. If you want to post that much code edit your question (or answer) or post an answer.
    – ChrisF Mod
    Jan 12, 2011 at 21:21
  • wait, so you can't write code in comments with more than 1 line? Jun 20, 2016 at 19:32
  • @CharlieParker - Unfortunately, that's correct. Well, you can insert one or more newlines into comments, and the newlines will be preserved, but they will not be displayed. Aug 16, 2018 at 21:52

2 Answers 2

57

You can't put newlines in a comment codeblock, but you can do inline code by using the backtick character. It looks like this

`

and it appears below the escape key on most keyboards which is sometimes the same key as the tilde (for example, on US English keyboards):

~

Surrounding something in backticks lets it appear as an "inline code block" and you could put them almost anywhere you like, even breaking across new lines. int c; c++; sprintf(); but notice there's no coloration, of course.

E.g. typing `something` in the editor produces something on the page

33
  • Better to upvote or accept, but I'll take the thanks for now ;)
    – jcolebrand
    Jan 12, 2011 at 18:47
  • test code not code
    – Marek
    Sep 23, 2014 at 6:58
  • 'something' this is a test
    – Tyler
    Nov 30, 2014 at 12:07
  • ~something~ this is another test
    – Tyler
    Nov 30, 2014 at 12:08
  • one more time , cool
    – Tyler
    Nov 30, 2014 at 12:08
  • this is just a test
    – kimreik
    Jan 11, 2015 at 0:54
  • you need to place the symbol just before the letter, and no spacing between the back quote and starting letter. ` FYI` :P Dec 15, 2015 at 2:10
  • test code in comments Jun 26, 2016 at 7:44
  • 1
    Thanks. I thought they meant the single quote '. Luckily I found this answer in under 4 minutes or I could have earned the "Can't tell a backtick from a single quote" badge. Jul 9, 2016 at 15:58
  • this is test command Nov 21, 2016 at 12:00
  • This is a test Nov 27, 2016 at 13:46
  • 2
    And now you're flooded with a bunch of test codes comments.
    – Gellie Ann
    Dec 21, 2016 at 1:36
  • 1
    This is a test because this was not working for me ok? <br> This is not giving me a line break. I cannot line break. /sigh Jun 6, 2017 at 5:47
  • Not in comments you can't
    – jcolebrand
    Jun 6, 2017 at 7:11
  • 1
    Just an update, does it still work? Yes, it does. Jun 13, 2018 at 23:24
7

Place this symbol: ` before and after the code. (On many keyboards, this "backtick" is the button to the left of "1".)

2
  • @CHID: like drachenstern said, better to upvote or accept. ;)
    – John
    Jan 12, 2011 at 18:48
  • ¨ds¨ test vfdsfds
    – Dejo Dekic
    Jan 28, 2016 at 22:00

Not the answer you're looking for? Browse other questions tagged .