乐闻世界logo
搜索文章和话题

How to make .less files to have .css syntax highlight in Vim?

1个答案

1
  1. Confirm Vim supports syntax highlighting: Ensure your Vim version supports syntax highlighting. You can enable it by entering :syntax on in command mode.

  2. Edit Vim's configuration file: Modify the user configuration file .vimrc, typically located in your home directory.

  3. Add syntax highlighting configuration for .less files: In the .vimrc file, add the following configuration line:

vim
au BufRead,BufNewFile *.less set filetype=css

This command automatically sets the file type to css when opening or creating a .less file, enabling Vim to apply CSS syntax highlighting rules to .less files.

  1. Save and reload Vim configuration: After saving the .vimrc file, restart Vim or enter :source ~/.vimrc in command mode to reload the configuration.

  2. Test the configuration: Open a .less file and verify that CSS syntax highlighting is correctly applied.

By following these steps, you can enable CSS syntax highlighting for .less files in Vim. This improves readability and manageability when writing and reviewing .less files, as syntax highlighting makes the code more intuitive and easier to navigate.

2024年8月12日 15:30 回复

你的答案