Using script highlight is one of the things that will help a “programmer” avoid making mistakes on his script, at the same allowing a quicker and better understanding of the same.
Vim is a great program when it comes to that. A lot of new users are reluctant to use VI (or vim), I was one of them. However after being forced to learn it for my Unix course, I've found that it's a lot better than most other shell text editors. It gives you a wide range of options and commands, at the same time allowing a user who only knows a few commands to use the program.
Like most Linux programs, vim keeps a hidden config file on the users home directory (~/.vimrc). This file can be edited with options to the program. For example, adding the string “set number” will make vim show line numbers.
=> Getting syntax highlight to work.
First thing we need is a .vim file. This file includes a lot of the options on how to highlight the documents. This is fully customizable (you could create one on your own), and you can have one for each type of script. In my case I only use it for bash scripts, so I downloaded bash.vim from here, them saved the file under ~/.vim/syntax/
Now we need to point vim to the syntax file when opening bash scripts. The following lines will do that, as well as enable line numbering:
$ vim .vimrc set number syntax on let X = getline(1) let y = match(X, "#/bin/bash" ) if (y != -1) so ~/.vim/syntax/bash.vim endif unlet X unlet y |
Last we need to install vim-full as the version of vim included in Ubuntu is a stripped down version.
sudo apt-get install vim-full |
Now open one of your scripts and see if it worked.
No comments:
Post a Comment