Jun 092013

When I’ve got multiple files open in Vim , some in different directories, I can eventually lose track of which directory I/Vim is in. Well I’ve just learnt that there is vim command pwd
:pwd to display your current directory (print working directory) and :chdir .. to change your directory!!

 Posted by at 10:05 pm
Feb 052013

Funny I’ve never thought of it before but I’ve just created a short shell script to grep my .vimrc configuration file. My .vimrc is over long and contains so much I forget what’s in there. The script is just another way of fishing out the useful stuff.

function gvix()
grep -i “$1″ c:/vim/.vimrc

and dont forget:-

:ab php : list of abbreviations beginning php
:map , : list of maps beginning ,
” where was an option set
:scriptnames : list all plugins, _vimrcs loaded (super)
:verbose set history? : reveals value of history and where set
:function : list functions

 Posted by at 5:48 pm
Dec 082012

If you are a Vi user you get incredibly frustrated when you have to use the in built editors available in other applications and in particular when writing posts on websites!
Well you can use VIM everywhere using a marvelous and versatile Windows Utility called AutoHotKey. You just need the following AutoHotKey script.It is really just a automatic way of copy/pasting but works like charm! www.autohotkey.com . BTW I am using the WordPress Plug-in wp-syntax for the first time

Allows the use of Vim in any other application

; Edit only selected text in vim
^!v:: ; press  Control+Alt+V
   MsgBox vim
   Send ^{ins down}
   FileDelete, c:\aax\vtmp
   FileAppend, %Clipboard%, C:\aax\vtmp 
   runwait, c:\vim\vim\gvim.exe c:\aax\vtmp, c:\
   FileRead, contents, c:\aax\vtmp
   StringRight, ending, contents, 2
   if ending = `r`n
      StringTrimRight, contents, contents, 2 ; remove last crlf from clipboard
   Clipboard := contents 
   Send +{ins down}
   contents = 
   ;FileDelete, c:\aax\vtmp
 Posted by at 7:52 pm
Jul 142012

:g/^/m0 : Reverse file (m = move)
:g/^/m$ : No effect! [N]
:'a,'bg/^/m'b : Reverse a section a to b
:g/^/t. : duplicate every line
:g/fred/t$ : copy(transfer) lines matching fred to EOF
:g/stage/t'a : copy (transfer) lines matching stage to marker a (cannot use .) [C]
:g/^Chapter/t.|s/./-/g : Automatically underline selecting headings [N]

What I find tricky to remember is which one MOVES and which one COPIES/DUPLICATES well it’s not that difficult ‘m’ MOVES and ‘t’ duplicates. Transfer ‘t’is useful when say I’ve been writing code ans creating Constants,Variables,Defines etc and I now want to declare or initialize them I go to the top of the code, place a marker ‘a’ and then gather up the declarations with a :g/CAR_TYPE_/t’a

 Posted by at 4:45 pm
Apr 142012

I’ve been working on various Linux servers recently (Centos) which had just the standard installs and have had to use console vim. When you type vi on a Linux console you still get vim but it may be tiny-vim or may be vim in original vanilla vi compatibility mode which will drive you crazy as many common commands you use frequently just won’t be there.

What you need is

> yum install  vim-common vim-enhanced vim-minimal


and then add an alias or whatever


alias vi=’vim’

 Posted by at 1:16 pm
Jan 272012

Vim’s visual block mode is a feature that I hardly ever use but is extremely useful when I do need it.
You can highlight a column of text or numbers in the center of a page and perform various edit operations on that text. It is unbelievably powerful and I realize on writing this that I only use a fraction of the blockwise possibilities.

You enter Visual Blockwise mode with Control V however I uses that for Paste so have it remapped to Control Q

” Visual is the newest and usually the most intuitive editing mode

” Visual basics

v : enter visual mode

V : visual mode whole line

: enter VISUAL BLOCKWISE mode (remap on Windows to say C-Q *C*

gv : reselect last visual area (ultra)

o : navigate visual area

“*y or “+y : yank visual area into paste buffer [C]

V% : visualise what you match

V}J : Join Visual block (great)

V}gJ : Join Visual block w/o adding spaces

`[v`] : Highlight last insert

:%s/\%Vold/new/g : Do a substitute on last visual area [N]

:help blockwise-visual

 Posted by at 8:16 pm
Dec 122011
The following should all be on one line

:sav! $VIMRUNTIME/doc/vimtips.txt|:1,/^__BEGIN__/d|:/^__END__/,$d|:w!|:helptags $VIMRUNTIME/doc

Save the Vim Tips Web Page as an HTML file edit with VIM then execute the above line. This strips off the unwanted stuff outside the __BEGIN__ and __END__ tags, writes the remainder to the VIM Help Tags folder and then runs helptags to generate the tags. Note the above line of Vim commands is to be found in the VIMTips file execute it with yy@”

” A VIM Help file requires a line such at the start:

*vimtips.txt* For Vim version 7.3. Last change: 2011 Dec 11

” and a line such at the end

The Searchable Helptags are generated from any text enclosed by stars, replace any spaces by a hypen.
I’m used a leading “best to help me find my own help tags. eg

:help best will list my tags

This tip suggested by Fredrik Acosta

 Posted by at 11:13 pm
Nov 202011

Some Vim experts have a practically empty .vimrc file (the config file) others like me have a huge one unfortunately in my case that means there is a lot of dead wood in it. To counteract that I now comment my .vimrc file (the doublequote ” is the comment delimiter) and am gradually commenting older parts of my vimrc and deleting stuff that is no longer relevant or is just plain junk. Remember you can use conditionals in your .vimrc so that particular parts of the config only apply to say php files or distinguish whether you are on your laptop or PC. Finally be aware of the danger that something in your config could “hide” or counteract some of Vim’s functionality.

I regularly backup my .vimrc and also have a copy stashed away on the Internet that I can download and use should I have to set up with a new PC.

 Posted by at 12:01 pm