*bashsupport.txt* Bash Support March 25 2014 Bash Support *bash-support* *bashsupport* Plugin version 4.2.1 for Vim version 7.0 and above Fritz Mehner Bash Support implements a bash-IDE for Vim/gVim. It is written to considerably speed up writing code in a consistent style. This is done by inserting complete statements, comments, idioms, and code snippets. Syntax checking, running a script, starting a debugger can be done with a keystroke. There are many additional hints and options which can improve speed and comfort when writing shell scripts. This plug-in can be used for Bash version 4.0. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++ The plug-in version 4.0+ is a rewriting of version 3.12.1. ++ ++ The versions 4.0+ are based on a new and more powerful template system ++ ++ (please see |template-support|for more information). ++ ++ The template syntax has changed! ++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1. Usage with GUI |bashsupport-usage-gvim| 1.1 Menu 'Comments' |bashsupport-comments| 1.1.1 Append aligned comments |bashsupport-aligned-comm| 1.1.2 Adjust end-of-line comments |bashsupport-comm-realign| 1.1.3 Comment/uncomment |bashsupport-comm-toggle| 1.1.4 Frame comments, file header, ... |bashsupport-comm-templates| 1.1.5 Comment/uncomment with echo |bashsupport-comm-echo| 1.1.6 KEYWORD + comment |bashsupport-comm-keywords| 1.2 Menu 'Statements' |bashsupport-statements| 1.2.1 Normal mode, insert mode |bashsupport-stat-norm-ins| 1.2.2 Visual mode |bashsupport-stat-visual| 1.3 Menus'Tests' ... 'Shopts' |bashsupport-tests| 1.4 Menu 'PatternMatching' |bashsupport-pattern| 1.5 Menu 'I/O-Redir' |bashsupport-io-redir| 1.6 Menu 'Snippets' |bashsupport-snippets| 1.6.1 Code Snippets |bashsupport-codesnippets| 1.6.2 Edit Templates |bashsupport-templates-edit| 1.7 Menu 'Run' |bashsupport-run| 1.7.1 Save and run |bashsupport-run-script| 1.7.2 Script command line arguments |bashsupport-cmdline-args| 1.7.3 Bash command line arguments |bashsupport-bash-cmdline-args| 1.7.4 Save and check syntax |bashsupport-syntax-check| 1.7.4.1 Error format |bashsupport-errorformat| 1.7.4.2 Syntax check options |bashsupport-syntax-check-options| 1.7.5 Start debugger |bashsupport-debugger| 1.7.6 Hardcopy |bashsupport-hardcopy| 1.7.7 Xterm size |bashsupport-xterm| 1.7.8 Output redirection |bashsupport-output| 1.8 Menu 'Help' |bashsupport-help| 2. Usage without GUI |bashsupport-usage-vim| 3. Hot keys |bashsupport-hotkeys| 4. Customization and configuration |bashsupport-customization| 4.1 Files |bashsupport-custom-files| 4.2 Global variables |bashsupport-custom-variables| 4.3 The root menu |bashsupport-custom-root| 4.4 System-wide installation |bashsupport-system-wide| 5. Template files and tags |bashsupport-templates| 5.1 Template files |bashsupport-templates-files| 5.2 Macros |bashsupport-templates-macros| 5.2.1 Formats for date and time |bashsupport-templates-date| 5.3 Templates |bashsupport-templates-names| 5.3.1 Template definition |bashsupport-templates-definition| 5.3.1 Template names |bashsupport-templates-names| 5.3.2 The jump tags <+text+> etc. |bashsupport-templates-jumptags| 5.3.3 Command Ctrl-j |bashsupport-Ctrl-j| 5.4 Additional filenames with filetype 'sh' |bashsupport-also-bash| 6. Bash dictionary |bashsupport-dictionary| 7. Additional Mappings |bashsupport-ad-mappings| 8. Windows particularities |bashsupport-windows| 9. TROUBLESHOOTING |bashsupport-troubleshooting| 10. Release Notes |bashsupport-release-notes| How to add this help file to Vim's help |add-local-help| ============================================================================== 1. USAGE with GUI (gVim) *bashsupport-usage-gvim* ============================================================================== If the menus are not visible call them with the entry "Load Bash Support" in the standard Tools-menu. ------------------------------------------------------------------------------ 1.1 MENU 'Comments' *bashsupport-comments* ------------------------------------------------------------------------------ 1.1.1 APPEND ALIGNED COMMENTS TO CONSECUTIVE LINES *bashsupport-aligned-comm* -------------------------------------------------- In NORMAL MODE the menu item 'end-of-line comment' will append a comment to the current line. In VISUAL MODE, this item will append aligned comments to all marked lines. Marking the 4 lines > x11=11; x1111=1111; x11111111=11111111; < and choosing 'end-of-line comment' will yield > x11=11; # | x1111=1111; # x11111111=11111111; # < The cursor position above is marked by '|' . Empty lines will be ignored. The default starting column is 49 ( = (multiple of 2,4, or 8) + 1 ). This can be changed by setting a global variable in the file '.vimrc', e.g. : > let g:BASH_LineEndCommColDefault = 45 < The starting column can also be set by the menu item 'Comments->adjust end-of-line com.' . Just position the cursor in an arbitrary column (normal mode; column number is shown in the Vim status line) and choose this menu item. This setting is buffer related. If the cursor was at the end of a line you will be asked for a column number because this position is most likely not the desired starting column. Your choice will be confirmed. 1.1.2 ADJUST END-OF-LINE COMMENTS *bashsupport-comm-realign* --------------------------------- After some copy/paste/change actions comments may be misaligned: > pathname=$(pwd) # the complete path basename=${pathname##*/} # the basename dirname=${pathname%/*} # the pathname < Realignment can be achieved with the menu item 'adjust end-of-line com.' In normal mode the comment (if any) in the current line will be aligned to the end-of-line comment column (see above) if possible. In visual mode the comments in the marked block will be aligned: > pathname=$(pwd) # the complete path basename=${pathname##*/} # the basename dirname=${pathname%/*} # the pathname < Another way is to use the hotkey \cj. In normal and insert mode the current line will be adjusted. To adjust n lines starting with the current one use n\cj. 1.1.3 COMMENT/UNCOMMENT *bashsupport-comm-toggle* ------------------------ The comment sign # can be set or removed at the beginning of the current line or for a marked block using the menu items 'comment' (or \cc) and 'uncomment' (or \cu). A single line needs not to be marked (normal mode, insert mode). A marked block > pathname=$(pwd) # the complete path basename=${pathname##*/} # the basename dirname=${pathname%/*} # the pathname < will be changed into (and vice versa) > #pathname=$(pwd) # the complete path #basename=${pathname##*/} # the basename #dirname=${pathname%/*} # the pathname < 1.1.4 FRAME COMMENTS, FILE HEADER, ... *bashsupport-comm-templates* -------------------------------------- Frame comments, function descriptions and file header comments are read as templates from the appropriate files (see |bashsupport-templates|). 1.1.5 COMMENT/UNCOMMENT WITH echo *bashsupport-comm-echo* --------------------------------- The echo-entry in the Comments-menu can be used to put one or more statements in a sort of comment. This is usually done for testing: > echo "rm -f $allfiles" < This can only be done in normal mode: The complete line (from the first non-blank to the end) is framed with echo "..." ; the cursor will then be moved to the next line. Now this line can be framed and so forth. The remove-echo-entry removes an echo. The keyword echo, the following double quotation mark, and the last double quotation mark in the current line will be removed; the cursor will then be moved to the next line. 1.1.6 KEYWORD+comment *bashsupport-comm-keywords* --------------------- Preliminary end-of-line comments to document (and find again!) places where work will be resumed shortly, like > # :BUG:23.05.2013 16:43:fgm: < Here 'fgm' is the authors reference (see section 4. for templates and tags). Usually these comments are not meant for the final documentation. ------------------------------------------------------------------------------ 1.2 MENU 'Statements' *bashsupport-statements* ------------------------------------------------------------------------------ 1.2.1 NORMAL MODE, INSERT MODE. *bashsupport-stat-norm-ins* -------------------------------- An empty statement will be inserted and properly indented. The item 'if' will insert an if-statement: > if | ; then fi < The statement will be indented. 1.2.2 VISUAL MODE *bashsupport-stat-visual* ------------------ The highlighted area > xxxxx xxxxx < can be surrounded by one of the following statements ( '|' marks the cursor position after insertion): > +--------------------------+---------------------------------------+ | | | | for | in ; do | for (( CNTR=0; CNTR<|; CNTR++ )); do | | xxxxx | xxxxx | | xxxxx | xxxxx | | done | done | | | | +--------------------------+---------------------------------------+ | | | | if | ; then | if | ; then | | xxxxx | xxxxx | | xxxxx | xxxxx | | fi | else | | | | | | fi | | | | +--------------------------+---------------------------------------+ | | | | select | in ; do | until | ; do | | xxxxx | xxxxx | | xxxxx | xxxxx | | done | done | | | | +--------------------------+---------------------------------------+ | | | | while | ; do | | | xxxxx | | | xxxxx | | | done | | | | | +--------------------------+---------------------------------------+ | | | fname () | | { | | xxxxx | | xxxxx | | } # ---------- end of function fname ---------- | | | +------------------------------------------------------------------+ < The whole statement will be indented after insertion. ------------------------------------------------------------------------------ 1.3 MENUS 'Tests' ... 'Shopts' *bashsupport-tests* ------------------------------------------------------------------------------ Insert tests, parameter substitutions, ... I/O-redirections. ------------------------------------------------------------------------------ 1.4 MENU 'PatternMatching' *bashsupport-pattern* ------------------------------------------------------------------------------ This menu can be used to compose globs and regular expressions with a few keystrokes. In normal and insert mode the items insert the shown constructs after the cursor. The first group ( "zero or more" ... "anything expect") can enclose a marked text. The marked text > xxxxx < will be changed into > *(xxxxx|) < by the first choice. ------------------------------------------------------------------------------ 1.5 MENU 'I/O-Redir' *bashsupport-io-redir* ------------------------------------------------------------------------------ This menu can be used to insert I/O redirectors. The cursor will be positioned at the obvious or most likely continuation point. The item 'here-document' has a visual mode. A few marked lines will be surrounded by the necessary statements, e.g. > << EOF xxxxxxxxxxx xxxxxxxxxxx EOF # ===== end of here-document ===== < ------------------------------------------------------------------------------ 1.6 MENU 'SNIPPETS' *bashsupport-snippets* ------------------------------------------------------------------------------ 1.6.1 Code Snippets *bashsupport-codesnippets* ------------------- Code snippets are pieces of code which are kept in separate files in a special directory. File names are used to identify the snippets. The default snippet directory is '$HOME/.vim/bash-support/codesnippets'. Snippets are managed with the 4 items > 'read code snippet' 'view code snippet' 'write code snippet' 'edit code snippet' < from the Snipptes submenu. Creating a new snippet: ----------------------- When nothing is marked, 'write code snippet' will write the whole buffer to a snippet file, otherwise the marked area will be written to a file. Insert a snippet: ----------------- Select the appropriate file from the snippet directory ('read code snippet'). The inserted lines will be indented. Indentation / no indentation ---------------------------- Code snippets are normally indented after insertion. To suppress indentation add the file extension "ni" or "noindent" to the snippet file name, e.g. > parameter_handling.noindent < Snippet browser --------------- Under a GUI a file requester will be put up. Without GUI the filename will be read from the command line. You can change this behavior by setting a global variable in your $HOME/.vimrc : > let g:BASH_GuiSnippetBrowser = 'commandline' < The default value is 'gui'. 1.6.2 Edit Templates *bashsupport-templates-edit* --------------------- Nearly all menu items insert code snippets or comments. All of these are contained within template files and can be changed by the user to meet their requirements (see|bashsupport-templates|on how to use the template system). The menu item 'edit templates' opens the main template file in a local plug-in installation. This is usually the file '$HOME/.vim/bash-support/templates/Templates'. There may be dependent files loaded from the main file. Now change whatever file you want, save it, and click on the menu item 'reread templates' to read in the file(s) and to rebuild the internal representation of the templates. If menu items, hotkeys, or shortcuts have been added or changed these changes will be applied with the next start of Vim. ------------------------------------------------------------------------------ 1.7 MENU 'Run' *bashsupport-run* ------------------------------------------------------------------------------ 1.7.1 Save and run *bashsupport-run-script* ------------------ Save the current buffer to his file and run this file. The command line, the applied parameters and the shell return code are shown in the bottom line. * In NORMAL MODE the whole buffer will be executed. * In VISUAL MODE only the selected lines will be executed. There are three output destinations (see|bashsupport-output|). If the output destination is VIM runtime errors are caught in an error window allowing quickfix commands to be used (see|quickfix|). The shell used can be set in the file '.vimrc', e.g. : > let g:BASH_Executable = '/bin/zsh' < The default is the value of $SHELL (Linux/U**X) or 'bash.exe' (Windows). 1.7.2 Script command line arguments *bashsupport-cmdline-args* ----------------------------------- The item 'script cmd. line arg.' calls an input dialog which asks for command line arguments. These arguments are forwarded to the script which is run by the 'run' item. The arguments are kept until you change them. For file names tab-expansion will work. The ex command > :BashScriptArguments ... < can also be used to set the command line arguments for the current script. The arguments belong to the current buffer (that is, each buffer can have its own arguments). The input dialog has a history. If the buffer gets a new name with "save as" the arguments will now belong to the buffer with the new name. 1.7.3 Bash command line arguments *bashsupport-bash-cmdline-args* --------------------------------- The menu item 'Bash com. line arg.' calls an input dialog which asks for command line options for the the Bash shell running the script in the actual buffer (like -x or -v; see the Bash manual for possible options). These arguments are forwarded to the invocation of Bash which is run by the 'run' entry. The arguments are kept until you change them. The arguments belong to the current buffer (that is, each buffer can have its own arguments). If the buffer gets a new name with "save as" the arguments will now belong to the buffer with the new name. 1.7.4 Save and check syntax *bashsupport-syntax-check* --------------------------- Save the current buffer to this file and run this file with the -n flag (Bash: read commands but do not execute them; same for dash, ksh, zsh). Errors are listed in an error window; now the quickfix commands can be used. 1.7.4.1 ERROR FORMAT *bashsupport-errorformat* -------------------- The format used to parse runtime errors handle bash, dash, ksh, and zsh errors. This format is appropriate for most locales including 'C' and 'POSIX'. 1.7.4.2 SYNTAX CHECK OPTIONS *bashsupport-syntax-check-options* ---------------------------- The syntax check can be influenced by shopt options. Options which shall always take effect can be declared in '.vimrc' , e.g. > let g:BASH_SyntaxCheckOptionsGlob = "-O extglob" < These options can be augmented or canceled using the menu entry 'syntax check options' typing for instance > +O extglob -O nocaseglob < after the prompt. The options entered this way are buffer related. The global options set in '.vimrc' and the buffer related options are checked. 1.7.5 START DEBUGGER *bashsupport-debugger* -------------------- Start the debugger 'bashdb' or the frontend 'ddd' from the menu entry Run->debug (GUI), with hotkey \rd or F9. Your version of the bash must be prepared for debugging and the debugger must be installed (see http://bashdb.sourceforge.net/). (1) Using bashdb When using gvim or vim running under a GUI the debugger will be started in an independent xterm. This is done because the shell integration in gvim has deficiencies (see also :h shell-window). When using vim from a console terminal the debugger will be started as > :!xterm -e bashdb --