Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

vi

editor

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.

like image 765
David Gay Avatar asked Oct 27 '25 06:10

David Gay


1 Answers

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
like image 159
Zorzi Avatar answered Oct 29 '25 20:10

Zorzi