MuPDF The PDF Reader for VIM Fans

mupdf official siteMuPDF is a very great pdf visualization tool. Check it out on its main site at http://www.mupdf.com/ . Let’s look at its key advantages:

  • Lean – it only shows you the document.
  • Fast (very!).
  • Its commands almost completely resemble those of less, vi, and vim‘s!
  • Linux and Windows.

I.e., the perfect choice for any situation. Get yours now at http://code.google.com/p/mupdf/downloads/list

The vi / vim command similarity comprises the best feature. The manual is as short as this:

The main viewer application is mupdf. Left click to pan, right click to select and copy text. Hold down shift when scrolling to zoom. Your navigation history is saved when following links, use ‘T’ to go back.
L, R rotate page
h, j, k, l scroll page
+, - zoom in or out
w shrinkwrap
r reload file
. pgdn right space next page
, pgup left b previous page
<, > skip back/forth 10 pages
m mark page for snap back
t pop back to latest mark
1m mark page in register 1
1t go to page in register 1
123g go to page 123
/ search for text
n, N find next/previous search result
c toggle between color and grayscale
pdfdraw
Rendering tool to convert a PDF file to a series of image files.
pdfclean
Tool to rewrite PDF files. Can be used to repair, decrypt, and decompress PDF files.
pdfshow, pdfextract, pdfinfo
Debugging tools to show internal objects, extract fonts and images, and display information about resources in a PDF file.

Enjoy! :)

Xfce Thunar Explorer Custom Actions

This post is intended for you fellow users of Xfce, a window manager and suite of applications.

The Thunar file browser is a very interesting of these applications:

  • It is extremely lightweight.
  • It has a pleasant interface.

The one awesome feature we discuss here is about incrementing your configuration with custom actions for files and directories that are made accessible via their context menu.

  • Open Thunar.
  • Go to Edit -> Configure custom actions…
  • Click on the “+” button on the right hand side of the dialog window (see the figure below).
  • Now give in the name, description and choose the icon for your action.

Now for the 3rd field, “Command” here is the very nice and handy part:

Insert a command of yours to do something. In my case, I want to rename files so that they do not have special characters. I will do this by invoking the xfce4-terminal (obviously, also from the Xfce suite of applications) which in turn invokes bash with its -c option (which receives an argument string comprised of commands to be evaluated i.e. executed).

Here ‘s the code:

xfce4-terminal -x bash -c '/path_to_script/renameok.sh %f'

The script renameok.sh iterates through directories renaming their files stripping special characters. Soon a post will be included containing its source code and explanation.

If your script (generally referred to as script.sh instead of the specific renameok.sh) depends on stuff setup in .bashrc (the shell resource file) then just call bash with -i (bash -ic “command(s)”) which sets the interactive mode on and calls the resource file before executing the -c option commands. Also realize that when in an interactive session, if script.sh is in a PATH setup by .bashrc you are safe to remove the /path_to_script/ part of script.sh ‘s call as it will be thus found. And last, as my .bashrc can have some echo commands in it, I will deliberately add a clear command before the script call so that the resulting code will look like:

xfce4-terminal -x bash -ic 'clear; renameok.sh %f'

Now, in the Appearance Conditions tab uncheck every options but Directories as in this example we use the directory in which the context menu was invoked as the script ‘s argument (as it wants a directory path). This indeed causes the action to be available only for directories’ context menus in Thunar. The main purpose in this tab is for you to choose which type(s) of files (directories are a type of file) you want the action to be executable.

In the custom action entry edition dialog, still, notice the bottom of the window, which explains the meanings of the expansions including the %f shown in the examples herein. One interesting and awesome thing is that Thunar is also smart enough to realize that the actions must not be made available if more than one file (or directory, as in these examples) are selected in case you are using %f. Conversely, the action is selectable both for just one file or for multiple files when using %F instead.

To know more check the official wiki entry.

Enjoy! ;)

vi: global search and some regular expressions

The global search a.k.a. “the g command” performs a global search, through the file and marks those lines for you to do something with them (default is the p command i.e. print).

Example:

:g/riding my bike/

will print every line containing the pattern enclosed within the slashes. If you want to delete those lines append that instruction with the delete command or its contracted form d:

:g/riding my bike/d

you could also combine it with the move, copy or even the substitution command. Substitution example:

:g/riding my bike/s/riding my bike/riding my ferrari/g

will substitute “riding my bike” for “riding my ferrari” on those lines that match the pattern “riding my bike”. Repeating the pattern seems silly, and it really is. You can omit the second pattern (in the substitution command) like this:

:g/riding my bike/s//riding my ferrari/g

which (the empty pattern) means “use the last pattern used”, in this case, the one belonging to the g command (“riding my bike”).

You could also use the hold buffer functionality (a.k.a. capturing group):

:g/\(riding my \)bike/s//\1ferrari/g

The hold buffer is used in the replacement text as \n with n varying from 1 to 9. This 1-9 hold buffer index is based on the order that the parenthesis appears on the pattern. Such parenthesis represent the boundaries of the hold buffer (capturing group). In the example, since we have only one such buffer, we use it in the replacement text as \1. This way we save typing.

An important note to the form of the g command combined with substitution with empty pattern (same as the g command’s) i.e. the g/pattern/s//replace/g form, is that it is equivalent to that substitute command applied for all lines:

:%/s/pattern/replace/g

The % on the start is the symbol that is equivalent to 1,$ i.e. from the first (1) to the last ($) lines (including them) or put it simple “the whole file”. Both these are what is known as ex’ line addressing. This subject is out of this post’s scope (vi/vim documentation and books cover this subject well).