38

Possible Duplicate:
How do comments work?

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

asked Jan 12, 2011 at 18:36
6
  • Writing what comments? Not sure I understand Commented 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 Commented Jan 12, 2011 at 18:43
  • 4
    Like this: This is code. Commented 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. Commented Jan 12, 2011 at 21:21
  • wait, so you can't write code in comments with more than 1 line? Commented 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. Commented Aug 16, 2018 at 21:52

2 Answers 2

56

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

Kev
19.3k11 gold badges50 silver badges101 bronze badges
answered Jan 12, 2011 at 18:44
33
  • Better to upvote or accept, but I'll take the thanks for now ;) Commented Jan 12, 2011 at 18:47
  • test code not code Commented Sep 23, 2014 at 6:58
  • 'something' this is a test Commented Nov 30, 2014 at 12:07
  • ~something~ this is another test Commented Nov 30, 2014 at 12:08
  • one more time , cool Commented Nov 30, 2014 at 12:08
  • this is just a test Commented 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 Commented Dec 15, 2015 at 2:10
  • test code in comments Commented 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. Commented Jul 9, 2016 at 15:58
  • this is test command Commented Nov 21, 2016 at 12:00
  • This is a test Commented Nov 27, 2016 at 13:46
  • 2
    And now you're flooded with a bunch of test codes comments. Commented 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 Commented Jun 6, 2017 at 5:47
  • Not in comments you can't Commented Jun 6, 2017 at 7:11
  • 1
    Just an update, does it still work? Yes, it does. Commented 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".)

Arjan
28.3k18 gold badges114 silver badges178 bronze badges
answered Jan 12, 2011 at 18:43
2
  • @CHID: like drachenstern said, better to upvote or accept. ;) Commented Jan 12, 2011 at 18:48
  • ¨ds¨ test vfdsfds Commented Jan 28, 2016 at 22:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.