Search code examples
vimeditorvi

In Vim, how can I show or hide line numbers depending on the current file's extension?


Vim can be configured to show line numbers by adding set number to your .vimrc.

How can I configure Vim to instead only show or hide line numbers for certain file extensions?

Examples:

  • Show line numbers for all files except .md files
  • Only show line numbers for .rb, .js, and .vue files

A .vimrc-based solution is probably preferable, but barring that, workarounds are welcome.


Solution

  • Here's what you're looking for:

    autocmd filetype markdown setlocal nonumber
    

    for your first example, and

    set nonumber
    autocmd filetype ruby,javascript,vue setlocal number