In short
Edit
When you need to display a block of code in a tip, it is best to use <pre> ... </pre> tags around the block.
A simple alternative is to insert a space before each line in the block, but that method can give the problems discussed below.
For inline code (for example, :s/old/new/), type <code>:s/old/new/</code>. See Template:code for more information.
Examples and explanations
Edit
When you use <pre>Some Text</pre>:
- Some Text is not parsed for wiki code (it's as if you had used
<nowiki>). - Some Text is taken as preformatted (so whitespace, including line breaks, is preserved).
- Some Text is displayed in a
fixed-widthfont. - Special characters (like
<for<) are processed normally.
Simply prefixing each line with a space gives the same result as using the <pre> tag, except that in a line prefixed with a space, normal wiki processing rules apply (for example, '' gives italics).
Here is some sample wikitext that might be in a tip:
<pre>
function MyFunction()
let newline = ''
if getline("'>") != getline("'<")
let newline = "\n"
endif
" More stuff would go here.
endfunction
</pre>
This is how the above wikitext is displayed:
function MyFunction()
let newline = ''
if getline("'>") != getline("'<")
let newline = "\n"
endif
" More stuff would go here.
endfunction
Problems using space prefix
Edit
Here is some text, using <pre> before the text, and </pre> after:
The first line looks good.
Here are some {{double braces}} in the text.
myvar = '' " this comment explains that '' is an empty string
:nnoremap <F3> :let @+='http://www.example.com/?item='.expand('<cword>')<CR>
Here is exactly the same text, using the insert space before each line technique:
The first line looks good. Here are some Template:Double braces in the text. myvar = " this comment explains that is an empty string :nnoremap <F3> :let @+='http://www.example.com/?item='.expand('<cword>')<CR>
The insert space before each line technique has these disadvantages:
- Punctuation may be mistaken for wiki syntax, so the display may be incorrect.
- Under some circumstances, if you select text from the spaced code block, you will find that each line has a trailing space (which is irritating if you want to paste the code into an example, and which can break some scripts).
- On long code blocks, it is easier to insert
<pre>before the block and</pre>after.