Saturday, 6 March 2010

 

Useful VIM Abbreviations for debugging Perl

iab perlb print "<p>debug ::: $_ :: $' :: $` line ".__LINE__."\n";exit;
iab perlbb print "<p>debug ::: <C-R>a line ".__LINE__."\n";exit;
iab perlbd do{print "<p>debug :: <C-R>a line ".__LINE__."\n";exit} if $_ =~ /\w\w/i;
iab perld use Data::Dumper;$Data::Dumper::Pad="<br>";print Dumper @product_array;exit;

the <C-R>a automatically inserts whatever variable you had previously stored in register a
Dumper allows you to display arrays and hashes, you really should be using it.

Perl can be debugged using the Perl debugger eg > perl -d test.pl

or with the tk gui

perl -d:ptkdb test.pl

Labels: , , ,


Monday, 18 January 2010

 

Reading MS Word Documents with VIM

Put this in your .vimrc
autocmd BufReadPost *.doc %!antiword "%"

install antiword on your PC, comes with Cygwin and as a win32 executable.

then vou can do

gvim cv.doc

Remember this is READY ONLY you cannot Modify a Word Document but nevertheless very useful for fishing out the text you need from a Microsoft Word document or alternatively reading a Word document with all the advantages of Vims powerful search options

" set up vim to read MS Word documents read only
autocmd BufReadPre *.doc set ro
autocmd BufReadPre *.doc set hlsearch!
autocmd BufReadPost *.doc %!antiword "%"

Labels: ,


Wednesday, 9 December 2009

 

How to Get the Latest Patched Version of VIM

The Cream project maintains the latest version of VIM you can download it here . On the download page you can get latest version of VIM with or without Cream.

Cream is a free, easy-to-use configuration of the famous Vim text editor for Microsoft Windows, GNU/Linux, and FreeBSD. It uses common menus, standard keyboard shortcuts, and has extensive editing functions for the beginner and expert alike.

The current version for win32 is gvim-7-2-303.exe they call this a one-click install

Labels: ,


Wednesday, 2 September 2009

 

Substitute Text in Last Visual Area

Got this from VIM Wiki


:%s/\%Vold/new/g # Substitute Text in Last Visual Area
# Now imagine you'd selected a visual block with (Control V, or Control Q (Windows)) you could do a column based substitute!

gv # revisualise last visual area

Labels: , , ,


Wednesday, 19 August 2009

 

Useful ZSH Commands for Vim

(When I used bash, I wrote small scripts to achieve the following)

We frequently re-edit the most recent files, I have aliases/scripts for many of following as they are a bit clunky to type.

vi *(.om[1]) # vi newest file
vi -p *(.om[1,3]) # open 3 newest files in tabs (gvim)
vi *(m0) # re-edit all files changed today!
ls *(^m0) # files NOT modified today
ls -l *(m4) # list files modified exactly 4 days ago
vi **/main.php # where ever it is in hierarchy
ls (x*~x[3-5]) # list files x* except x3 to x5
vi !$ # vi last parameter
vi !-2:2 # second parameter of second but last command
vi !$:r.php # vi last parameter but change extension to .php
^mian^main # modify previous command (good for correcting typos)
^php^cfm # modify previous command replace php by cfm

more zsh tips and tricks here

Labels: , ,


Sunday, 2 August 2009

 

Clean up a Mucky Text File with a VIM function

We are often required to clean up a text file usually from kind of export to text from a database , Word file etc. These text files can be full of superfluous white space, non-asciis, control-M etc

Insert the following function into your .vimrc or load directly into the file you editing. Adapt it as necessary .
Execute with

: call Clean()

function! Clean()
" Clean up a text file
" delete pesky (MSDOS) control-M 's
exe ':%s/\r//ge'
" delete pesky non-asciis
exe ':%s/[\x00-\x1f\x80-\xff]/ /eg '
" compress multiple spaces
exe ':%s/\s\s\+/ /eg'
" delete end of line spaces
exe ':%s/\s\+$//e'
" compress multiple blank lines
exe ':silent! v/./,/./-j'
endfunction

Labels: , ,


Tuesday, 21 July 2009

 

VIM : Register Tricks

When you use the useful ct" (change till " character) (:help t - motion command) it can be annoying that you cannot . repeat it if the limiting character is not a "

Well not to worry the last text you inserted is still in the . register and can thus be retrieved with a <C-R>.

ie ct'<C-R>.

Don't forget it's brother the small delete register -

Or the other special registers which you can display with the following command

:reg "/-.:%*

Nor forget how to dump your numeric registers

"1p....... (normal mode)

Labels: , , ,


Wednesday, 1 July 2009

 

VIM: Creating Your Own Commands with a Map or a Recording

Customizing your own commands using a map or recording.

A Map is generally used for stored commands.

A Recording is used for one off jobs.

Recordings are more intuitive ie you simply record a sequence of commands.

Maps require a little more knowledge of map special characters <CR><ESC> etc

While it is possible to "save" a recording for future use it's a little tricky

:let @w="<C-R>q" ie read recording q (same as register q) and store in register w, which if put in your .vimrc will be preserved for future use

With experience you should find yourself preferring to create disposable recordings and relying less and less on maps; one well known Vimmer (Peppe) has a practically empty .vimrc.

Labels: , , ,


Wednesday, 24 June 2009

 

Vim: Including a register's contents in a substitute

"sub "fred" with contents of register "a" (Control R)
:s/fred/<c-r>a/g

or from the paste buffer

s/fred/<c-r>*/g

Here you actually do a Control-R.

It is often preferable to do use the following

:s/fred/\=@a/g : better alternative as register not displayed

unfortunately the \=@a must be at the beginning of replacement string

zzapper

Labels: ,


Saturday, 20 June 2009

 

vim dat cat with yat or dat

I've been using the following HEAVILY recently as I've been working on some spaghetti html pages with mysql,php,Javascript and HTML sprinkled sometimes on the same line. The following help me to precisely "grab" the code I need to alter. I've been favoring VISUAL MODE as this confirms or otherwise that I've selected just what I intend.

Note how the "a" and "i" inner variants differ the 'i' grabs less than
the outer 'a'

vat,dat,yat,cat (visualize,delete,yank,change) a tag

ie dat will delete a whole table if cursor anywhere over < table>

ie yat will yank a whole table row if cursor over < tr>

vit,dit,yit,cit will empty a tag pair

da< just deletes a single tag

di< empties a tag

:help text-objects

seems to work with XML as well

Also quote based text objects (single line only though for some odd reason)

va"
da"
va'
da'
vi"
di"
vi'
di'
di<
and don't forget
di(
da{
etc


zzapper

Labels: , , ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]