0

I want to use filetype=nasm to get syntax highlighting in assembly files (ending with a .asm extension). I have the following autocommand for it:

augroup FileTypes
    au!
    au BufNewFile,BufRead *.asm :setlocal filetype=nasm
augroup END

And it works as intended except for the fact that vim also loads the syntax file for asm.vim (which was the default).

:scriptnames

Is there any way to disable loading this file?

3
  • 1
    What makes you believe it is the asm.vim that is used? What is the result of :echo b:current_syntax Feb 15, 2023 at 10:23
  • The syntax being used is nasm.vim. My motivation for ignoring asm.vim is simply to avoid loading a redundant file of settings.
    – First User
    Feb 15, 2023 at 12:54
  • 1
    The solution of @Matt is then the correct one. the $VIM\filetype.vim first decide to associate the *.asm to something. There is a logic in $VIM\autoload\dist\ft.vim that by default associate to the filetype asm but you can override that using g:asmsyntax global variable. The logic looks at the first 5 line for a string like asmsyntax=nasm Feb 15, 2023 at 13:10

2 Answers 2

3

To set nasm as default assembly syntax simply do

let g:asmsyntax = 'nasm'

Never forget to read help, i.e. :h asm.vim (or :helpgrep nasm, for example).

1

You can't prevent the standard syntax from being sourced (unless you remove the file). But, by introducing your own syntax (~/.vim/syntax/nasm.vim), you can make sure it 'override' the standard one.

I your syntax files defines b:current_syntax the standard one will do nothing and you should have the effect you want.

let b:current_syntax = "nasm"

The reason is that, as all standard syntax files, it starts with:

if exists("b:current_syntax")
  finish
endif

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.