0

Today i woke up with a simple idea.

It would great to have "stackoverflow synthax highlighting in vim".

Do you know a simple way to go SO style ?

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
  • do you mean the syntax HL used in SO code block? it depends on the language detection. – Kent Feb 25 '14 at 11:24
  • Do you want the colors used by StackOverflow to render code blocks or do you want the syntax highlighting rules? – romainl Feb 25 '14 at 11:38

2 Answers2

1

Stack Overflow uses Markdown syntax, so this should do it (in Vim versions 7.3+, which ship with it):

:setf markdown

as separate filetype

If you want to do customizations, it's best to define your own custom stackoverflow filetype by creating a file ~/.vim/syntax/stackoverflow.vim with the following contents (and defining corresponding filetype detection rules):

" Quit when a syntax file was already loaded.
if exists('b:current_syntax') | finish | endif

runtime! syntax/markdown.vim syntax/markdown/*.vim

filetype setting from browser

Since Stack Overflow is browser-based, you probably use a browser plugin to do the editing in Vim. I've described such a setup that can automatically set the filetype based on the currently edited URL for Firefox in my blog post Pentadactyl set filetype in external Vim editor based on URL.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
1

Your question is fuzzy; if you mean to mark certain blocks as having a certain syntax (which on Stack Overflow can be done with language: lang-js HTML comments), my SyntaxRange plugin enables you to define a different filetype syntax on regions of a buffer, either manually or automatically based on markers.

Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324