Vim Macros for Editing DocBook Documents
DocBook is a vast markup language offering many tags, and most projects use only a subset of the available tags. The bindings above were developed for marking up LJ articles. Your use of DocBook probably will focus on a different set of tags, so you probably need to change the templates and key bindings.
The file tagtmps.vim contains the templates inserted by the <F2> key. Listing 2 shows the template for the article tag.
Listing 2. Article Tag Template
let g:Template_article ="<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"no\"?><CR>" \."<!DOCTYPE article SYSTEM \"docbookx.dtd\"><CR><CR>" \."<article><CR><CR>" \."<simplesect><title/><CR>" \."<para><CR>-:-<CR>" \."</para><CR>" \."</simplesect><CR><CR>" \."<simplesect><title></title><CR>" \."<para><CR>" \."</para><CR>" \."</simplesect><CR><CR>" \."</article>"
All templates are stored in global string variables whose names start with Template_ and end with the tag to which the template corresponds. The g: prefix in the variable name makes it a global variable. Long strings can be placed on multiple lines by prefixing the second and subsequent lines with a backslash (\) and using the dot (.) concatenation operator to append the lines together. Each string piece is contained within double quotes. Double-quoted strings understand the usual C escape sequences. You can modify the existing templates or add new ones for other tags by following the described naming sequence. Within a template the sequence -:- is used to specify where you want the cursor to be placed after the template is inserted. The macro automatically removes this string after inserting the macro.
If you want to change the function keys used to execute the macros, modify the following lines in the file mfuncs.vim:
let s:InsertTagTemplateKey = "<F2>" let s:InsertSymbolKey = "<F3>" let s:InsertForeignCharKey = "<F4>" let s:InsertStartTagKey = "<F5>" let s:InsertEndTagKey = "<F6>" let s:TagWordKey = "<F7>" let s:TagRangeKey = "<F7>" let s:ChangeTagKey = "<F8>"
If you want to change the tag-keys, symbol-keys or foreign-char-keys that follow the functions keys or change the tags associated with the keys, change the corresponding lines in maps.vim. For example, to change b so it is associated with the tag <book> rather than the tag <emphasis role="bold">, look for the following line in maps.vim:
call MapTagKey("b", 0, 0, "emphasis", " role=\"bold\"")
and change it to:
call MapTagKey("b", 1, 1, "book", "")
The function MapTagKey is defined in mfuncs.vim. Its prototype is:
function! MapTagKey(key, snewline, enewline, tag, stagx)
Its parameters are explained in Table 5.
Table 5. MapTagKey Parameters
|key||Keystroke(s) to bind the tag key to (for example, <F2>key).|
|snewline||One if the start tag should be placed on a new line, zero otherwise.|
|enewline||One if the end tag should be placed on a new line, zero otherwise.|
|tag||The tag associated with the key.|
|stagx||Extra attributes that should be placed in the start tag.|
The function MapTagKey merely sets up and executes a number of Vim nmap and imap commands to make the appropriate key bindings. Similarily, symbol-keys and foreign-char-keys are mapped by the functions MapSymbolKey and MapForeignCharKey. These functions each take two arguments, the key and the text to insert. For example:
call MapSymbolKey("3", "¾") call MapForeignCharKey("b", "β")
Near the bottom of the file maps.vim are a handful of Vim nmap commands for binding the tag manipluation and movement keys, including delete tag, change tag and move tag. All of these bindings call the functions defined in the file tfuncs.vim.
nmap <S-F8> :call DeleteTag()^M " Delete tag at cursor. nmap <F9> :call CursorLeftByTag()^M " Move left by tags. nmap <F10> :call MoveTagLeft()^M " Move tag left of preceding word. nmap <F11> :call MoveTagRight()^M " Move tag right of following word. nmap <F12> :call CursorRightByTag()^M " Move right by tags. nmap <S-F9> :call TightenTagLeft()^M " Delete whitespace left of tag. nmap <S-F10> :call InsertStringLeftOfTag(" ")^M " Insert space to the left of tag. nmap <S-F11> :call InsertStringRightOfTag(" ")^M " Insert space to the right of tag. nmap <S-F12> :call TightenTagRight()^M " Delete whitespace right of tag.
If you cat this file, these lines are going to look strange, and in some editors, all the lines are going to break right after the closing parentheses in the call. If you look at it with vim, you can see that the closing parentheses are followed by ^M, a carriage return. When you cat the file, this causes part of the line to be erased. Some editors cause a line break here. These mappings work in command mode and the ^M ends the command.
Mitch Frazier is an Associate Editor for Linux Journal.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- Firefox 46.0 Released
- Ubuntu Online Summit
- Devuan Beta Release
- The Qt Company's Qt Start-Up
- May 2016 Issue of Linux Journal
- The US Government and Open-Source Software
- The Death of RoboVM
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- New Container Image Standard Promises More Portable Apps
- Open-Source Project Secretly Funded by CIA
In modern computer systems, privacy and security are mandatory. However, connections from the outside over public networks automatically imply risks. One easily available solution to avoid eavesdroppers’ attempts is SSH. But, its wide adoption during the past 21 years has made it a target for attackers, so hardening your system properly is a must.
Additionally, in highly regulated markets, you must comply with specific operational requirements, proving that you conform to standards and even that you have included new mandatory authentication methods, such as two-factor authentication. In this ebook, I discuss SSH and how to configure and manage it to guarantee that your network is safe, your data is secure and that you comply with relevant regulations.Get the Guide