Monday, 16 November 2009

 

Deleting all but first two fields in each line of a CSV File


In a csv file full of lines such
16 Prop_Description Property description, String 1000
(note that this is actually a space separated csv)

:%s#\(\d\+ \w\+\).*#\1#g

filters out all but the field number and name eg

16 Prop_Description

a regexp for normal comma separated csv would be

fred,joe,sid
"fred joe","sue","good boy

:%s/\([^,]\+\),\([^,]\+\).*/\1,\2/

Labels:


Sunday, 15 November 2009

 

VIM working with Paste Commands


The paste buffer is usually the easiest way to transfer text between VIM and another application.

" Redirection & Paste register *
:redir @* : redirect commands to paste buffer
:redir END : end redirect
:redir >> out.txt : redirect to a file
" Working with Paste buffer
"*yy : yank current line to paste
"+y} : yank to end of paragraph
"+yi{ : yank current paragraph
"*p : insert from paste buffer
" yank to paste buffer (ex mode)
:'a,'by* : Yank range into paste
:%y* : Yank whole buffer into paste
:.y* : Yank Current line to paster
" filter non-printable characters from the paste buffer
" useful when pasting from some gui application
:nmap p :let @* = substitute(@*,'[^[:print:]]','','g')"*pr

Sunday, 8 November 2009

 

Command Line Window q: or q/


One of original great improvements of VIM over Classic Vi was the ability to reuse/edit/correct commands laboriously typed in, you had only simple line edit commands available to do this, normally perfectly sufficient of course. However you can also open a command line window to gain full vim command line editing commands:-

Note these are normal-mode commands!
q:
Creates a small window of your most recent commands

q/
Creates a small window of your most recent searches

hitting "return" will execute whatever line you are editing

to close/leave the command window without executing the current line use :quit


Labels:


Wednesday, 4 November 2009

 

Using CVS with VIM


I'm now using the CVS that comes with Cygwin and the CVS plugin for VIM

and the plugin
http://www.vim.org/scripts/script.php?script_id=58

I used to save backups to a directory with a timestamp appended to the filename.

Now I'll have a proper system with version control, difference between version etc

Labels: , ,


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

Subscribe to Posts [Atom]