Find what filetype is loaded in vim

前端 未结 5 866
旧巷少年郎
旧巷少年郎 2021-01-29 19:09

As soon as I load any file in vim, It\'ll try to detect the file and color-highlight it if possible.

I want to know a vim command that will tell me which ftplugin or Fil

5条回答
  •  庸人自扰
    2021-01-29 19:30

    Since you are asking/searching this question in the first place, I assume you do this because your vim somehow does not highlight the proper syntax for you automatically, and you are trying to figure out why, and how to fix it.

    The command :set filetype? in the chosen answer basically asks vim "hey what type do you think the current file is". And if vim is not displaying proper color/highlighting, most likely its answer to you is displaying this filetype= at the bottom of your console, meaning vim does not know the file type. This is only halfway of your quest.

    Logically, your next step will be telling vim "just highlight it using (for example) ps1 syntax". You do so by typing :set filetype=ps1, now vim will highlight the current file using ps1 style (providing that you already download the proper powershell syntax file and put it into your ~/.vim/syntax).

    At this point, you will probably want auto-syntax-highlight from now on. The solution is to put a corresponding detection script into your ~/.vim/ftdetect folder. For example, if you want to highlight all PowerShell scripts .ps1, .psm1, etc., you put this file into your ~/.vim/ftdetect

    Now that is a happy ending.

提交回复
热议问题