This post is written by SathiyaMoorthy.
3 Steps to Install the bash-support pluginStep 1: Download the bash-support pluginDownload the plugin from website. $ cd /usr/src $ wget -O bash-support.zip http://www./scripts/download_script.php?src_id=9890 Step 2: Install the bash-support Vim Plugin$ mkdir ~/.vim # if the directory does not exist already $ cd ~/.vim $ unzip /usr/src/bash-support.zip Step 3: Enable the plugin in the ~/.vimrcAdd the following line to the ~/.vimrc to enable the plugin for Vim editor. $ vim ~/.vimrc filetype plugin on 8 Powerful Features of Bash Vim PluginFeature 1: Add Automatic Header to *.sh fileWhen you open a file with the extension .sh it opens the file with header as shown below. This will also place the cursor in the Description field in Insert mode. #!/bin/bash #============================================================ # # FILE: myscript.sh # # USAGE: ./myscript.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: (), # COMPANY: # VERSION: 1.0 # CREATED: 02/14/09 15:42:08 IST # REVISION: --- #============================================================
let g:BASH_AuthorName = 'SathiyaMoorthy' let g:BASH_Email = 'subscribe@' let g:BASH_Company = 'Open Source Corporation'
#!/bin/bash #============================================================ # # FILE: myscript.sh # # USAGE: ./myscript.sh # # DESCRIPTION: # # OPTIONS: --- # REQUIREMENTS: --- # BUGS: --- # NOTES: --- # AUTHOR: SathiyaMoorthy (), subscribe@ # COMPANY: Open Source Corporation # VERSION: 1.0 # CREATED: 02/14/09 15:39:58 IST # REVISION: --- #============================================================
Feature 2: Adding Bash Function Using \sfuFor writing a subroutine, type \sfu in normal mode, which will prompt for the function name (as shown in Fig1 below) and inserts the subroutine with default function content (as shown in Fig2 below). Fig 1: Type \sfu to add a bash function inside a shell script
Fig 2: Bash function added automatically inside shell script Feature 3: Insert a Function Header Using \cfuFor inserting a function header, type \cfu in normal mode, which shows comments as shown in Fig 3.
Fig 3: Type \cfu to insert a function header inside a shell script Feature 4: Add a Frame Comment Using \cfrTo add a frame comment, type \cfr in normal mode, which will give the following formatted comment as shown in Figure 4. Fig 4: Type \cfr to insert a frame comment inside a shell script Feature 5: Insert Bash Statements Inside Shell ScriptShort cut keys to insert statements are:
Example: Insert the Case Statement inside a shell script automatically\sc will insert the case statements and places the cursor next to the case statement in INSERT mode as shown in figure 5. Like this you can use all the mentioned short cut keystrokes to get the appropriate statement in the table 1. Fig 5: Type \sc to insert case statement inside bash shell script Feature 6: Insert Predefined code-snippet to the Bash Script Using \nrCode snippets can be read / written by using \nr and \nw respectively. The plugin comes with few pre-defined code snippets that you can insert into your code. Following are the default code snippets that comes with the plugin. $ ls -1 ~/.vim/bash-support/codesnippets/ assert basename+pathname basename-function check-number-of-command-line-arguments create-tempfile create-tempfile-with-trap free-software-comment read-and-split-into-array timestamp usage-and-command-line-arguments.noindent use-file-descriptor-read use-file-descriptor-write well-behaved-script
#----------------------------------------------------------------------- # Check number of command line arguments #----------------------------------------------------------------------- if [ $# -lt 1 ] then echo -e "\n\tUsage: ${0##/*/} File\n" exit 1 fi
Feature 7: Get Quick Help on the Bash Builtin CommandsWhen you need to read help page for the bash builtins use \hh when the cursor is in the word. Fig 6: Type \hh to get help about the selected bash builtin command Feature 8: Featured CommentingFollowing commands will add the corresponding keyword comments. For example, type \ckb to add the BUG comment line inside shell-script.
Fig 7: Type \ckt to add TODO inside bash shell script
Recommended ReadingVim 101 Hacks, by Ramesh Natarajan. I’m a command-line junkie. So, naturally I’m a huge fan of Vi and Vim editors. Several years back, when I wrote lot of C code on Linux, I used to read all available Vim editor tips and tricks. Based on my Vim editor experience, I’ve written Vim 101 Hacks eBook that contains 101 practical examples on various advanced Vim features that will make you fast and productive in the Vim editor. Even if you’ve been using Vi and Vim Editors for several years and have not read this book, please do yourself a favor and read this book. You’ll be amazed with the capabilities of Vim editor. If you enjoyed this article, you might also like.. |
|