Archive for the ‘vim’ Category

Vim, Cygwin, docx2txt, catdoc and antiword view Microsoft Word Documents as Text

October 10th, 2011 No comments

I wanted to quickly compare two versions of a Word document and realized I didn’t know how to do it. A quick Google revealed that catdoc was available with Cygwin (and I guess elsewhere) .

> catdoc report1a.doc > report1a.txt
> catdoc report1b.doc > report1b.txt
> diff report1*.txt

Alternatively use antiword
place the following 4 lines in your .vimrc file

” use antiword to allow VIM to view the text of a Word Document
autocmd BufReadPre *.doc set ro
autocmd BufReadPre *.doc set hlsearch!
autocmd BufReadPost *.doc %!antiword “%”

> vim -d report1a.doc report1b.doc

Remember neither catdoc or antiword allow you to update your word documents.

catdoc also works with PowerPoint etc.

Just found out that these don’t work with the XML based docs eg report.docx for these you need Perl based docx2txt

Categories: Cygwin, vim, windows Tips Tags:

Using Perl for Complex Edits

June 24th, 2011 No comments

All I use Vim 99% of the time whenever I want to do a really complex multiple edit I tend to use Perl.

So what’s the script doing ? It reads in one text file line by line and then operates on certain lines , and then writes out each line to an output file. You are only limited by your imagination as to what you do in the loop.

With a Perl script you can use Perl variables for counts, you can use a hash to store all the text and loop through it as often as required.

# description : Use for complex edits on a single file, adapt as required
# this trivial example is just incrementing a count
# zzapper
# v1.0
if ($#ARGV >= 0) { $file = $ARGV[0]; }
print "enter file:"; $file=;
chomp $file;
open (R,"$file") or die ("could not open $file ($!)");
$out = "c:/aaa/out.txt";
$out = "$file.txt";

open (W,">$out") or die ("could not open $out ($!)",__LINE__);
for $l ()
$l=~s/david1/david$cnt/gi; # do what you want here
print W $l;
close W; close R;
print "\nOutput in cnt: $cnt :: $out\n";

Categories: Coding Tips, vim Tags:

Creating and Using a VIM Scratch File

September 22nd, 2010 No comments

” put following in your _vimrc

” store for useful text, reusable stuff, code sections
map <f4> :tabe c:/aax/store.txt<CR>
imap <f4> :tabe c:/aax/store.txt<CR>

Hit the F4 key to open store.txt  in a separate tab.  I’ve currently  got a few snippets of Perl I need frequently , a few telephone numbers etc. I find it very useful. The VIM maps above are not rocket science and you will see how to vary them for your own requirements.

Categories: vim Tags:

VIM 7.3 Released

August 22nd, 2010 No comments

Vim 7.3 is a stability release integrating hundreds of patches. It does contain however some new enhancements.

The most notable additions since 7.2:
– Persistent undo and undo for reload
– Blowfish encryption, encryption of the swap file
– Conceal text
– Lua interface
– Python 3 interface

Persistent undo is probably the feature which most interests me. This allows you to undo changes you made last time you edited a file; a feature which must be used with some care obviously!. It works by saving the changes in a temporary file. A file is created for each file you modify, to avoid cluttering up your directories you can configure vim to use a special directory.

Download the latest VIM here

Windows Users can go directly to this link which is the simplest way to upgrade. By the way REMEMBER to backup your .vimrc file!!!

Recently I’ve been using the Cream version which maintains an up-to-date single click install version of VIM with all patches it is already at version 7.3.3. And just to confirm this is the version without Cream.

Categories: vim Tags: