Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight Bash scripts in Vim?

My Vim editor auto highlights PHP files (vim file.php), HTML files (vim file.html) and so on.

But when I type: vim file and inside it write a Bash script, it doesn't highlight it.

How can I tell Vim to highlight it as a Bash script?

I start typing #!/bin/bash at the top of the file, but it doesn't make it work.

like image 955
never_had_a_name Avatar asked Apr 05 '10 02:04

never_had_a_name


People also ask

How do I enable highlighting in Vim?

After opening login.sh file in vim editor, press ESC key and type ':syntax on' to enable syntax highlighting. The file will look like the following image if syntax highlighting is on. Press ESC key and type, “syntax off” to disable syntax highlighting.

How do I highlight keywords in vim?

Press 1 to highlight the current visually selected text, or the current word (if nothing is selected). Highlight group hl1 is used. Press 2 for highlight hl2 , 3 for highlight hl3 , etc. Press 0 to remove all highlights from the current visually selected text, or the current word.

How do I enable syntax highlighting in bash?

There is no simple way to obtain syntax highlighting in GNU Bash (or GNU Readline), but it is in principle possible to implement your own line editor in Bash script by binding all the user inputs to shell functions using the builtin command bind -x 'BYTE: SHELL-COMMAND' .

Does vim have syntax highlighting?

VIM is an alternative and advanced version of VI editor that enables Syntax highlighting feature in VI. Syntax highlighting means it can show some parts of text in another fonts and colors. VIM doesn't show whole file but have some limitations in highlighting particular keywords or text matching a pattern in a file.


1 Answers

Are you correctly giving the shell script a .sh extension? Vim's automatic syntax selection is almost completely based on file name (extension) detection. If a file doesn't have a syntax set (or is the wrong syntax), Vim won't automatically change to the correct syntax just because you started typing a script in a given language.

As a temporary workaround, the command :set syn=sh will turn on shell-script syntax highlighting.

like image 50
Mark Rushakoff Avatar answered Sep 18 '22 08:09

Mark Rushakoff