Currently I am working a lot with objdump output (arm / thumb instructions):

The command (arm-none-eabi-objdump -h -S main.elf > main.lst) creates a mixture of assembly (with addresses and hex representations) and c-code. Like this:

080009e4 <configure_led1>:

// configure ccu4 of led1
void configure_led1(uint16_t off_time, uint16_t on_time){
 80009e4:       b480            push    {r7}
 80009e6:       b085            sub     sp, #20
 80009e8:       af00            add     r7, sp, #0
 80009ea:       4603            mov     r3, r0
 80009ec:       460a            mov     r2, r1

Unfortunately the syntax highlighting of vim gets confused by this file. It uses assembly syntax highlighting for the file (:set filetype? returns asm). This syntax doesn't work well with the instruction addresses and hex representations in front of the actual assembly instructions.

How do I need to configure vim to use correct highlighting? Does vim have a specific filetype for objdump output?

  • 1
    AFAIK, none exists for this. You could probably piece it together with a mix of the xxd, c, and asm syntax files. Unfortunately the mix makes it look hard :(
    – D. Ben Knoble
    Dec 13, 2019 at 3:45

1 Answer 1


This is rather meant as a demonstration, not a full-featured syntax file. But it should work correctly against an example above (except only few assemblers, such as GNU, support C/C++ comments natively; in general such comments should be marked as C syntax region).


" standard guard against syntax clash
if exists("b:current_syntax")

" Asm is our main syntax; C is an extra one
runtime! syntax/asm.vim
unlet b:current_syntax
syntax include @C syntax/c.vim
unlet b:current_syntax

" a line starting with [A-Za-z_] is a C line
syntax region odCLine start=/^\h/ end=/$/ keepend contains=@C

" a line starting with a hex number is an objdump address/opcode
" stop at [:xdigit:][:blank:][:blank:] to interpret the rest as asm instruction (default)
syntax region odHead start='^\s*\x\+\>' end=/\x\s\{2,}\|$/ keepend contains=odHex,asmIdentifier

" hex number w/o any prefix (deadbeef)
syntax match odHex '\<\x\+\>' contained
hi def link odHex hexNumber

" assign current syntax
let b:current_syntax = 'objdump'

Of course, you still need filetype/ftdetect to make it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.