From: "Y.T.Lim - Ericsson"
Brad Roberts wrote on Tuesday, July 08, 1997:
> I don't mind using VI.. kinda like it (call me sick), but I still miss
tse.. though not enough to setup dos emulators.
I guess quite a lot of people work with Unix but go home to Windows and Dos
and Linux. It's good to have this combination so that good ideas can flow
between two worlds. vi is one of those things that looks terrible until
you get to know it. It's probably the text editor most optimized for no.
of key strokes for its tasks.
Since there have been quite a few of messages about CUAMARK, I'm going to
post a vi style yank/delete macro. You can copy/cut text with or without TSE
blocks.
There are some differences from the real vi commands:
(1) named buffers are from a-z except w. w/W is used for Windows clipboard.
(2) extend vi commands to support TSE blocks
(3) active named buffers are displayed as part of the message while
the macro is Ask()-ing for vi command.
I bind the macro to Ctrl-Z as they are the keys closest to your left hand.
After
you compile and execute it, hit Ctrl-Z and enter the vi yank/delete commands
...
/Y.T.
/***************************************************************************
*
* File : NameBuffer.S
*
* Author : Y.T.Lim
*
* Description : Implementation of vi yank/delete commands in TSE.
* Tested on 2.6 and 2.8.
*
* Commands supported are:
*
* +---------------------------------------------------------------------+
* | command | Action | Buffer | Remarks |
* +=====================================================================+
* | yy | copy curr line | default | |
* +---------------------------------------------------------------------+
* | nyy | copy n lines | default | |
* +---------------------------------------------------------------------+
* | yb | copy block | default | block must be marked |
* +---------------------------------------------------------------------+
* | yw | copy curr word | default | |
* +---------------------------------------------------------------------+
* | "qyy | copy curr line | q | buffer=a..v,x..z(Not w,W) |-+
* +---------------------------------------- | |
* | "Qyy | copy & append | q | Note: w and W are reserved | |
applicable
* +---------------------------------------- for Windows Clipboard |
+-to word &
* | "qnyy | copy n lines | q | | |
block
* +---------------------------------------- | |
* | "Qnyy | copy & append | q | |-+
* +---------------------------------------------------------------------+
* | "wnyy | copy n lines | WinClip | buffer=w or W |
* +=====================================================================+
* | dd | cut curr line | default | |
* +---------------------------------------------------------------------+
* | ndd | cut n lines | default | |
* +---------------------------------------------------------------------+
* | db | cut block | default | block must be marked |
* +---------------------------------------------------------------------+
* | dw | cut curr word | default | |
* +---------------------------------------------------------------------+
* | "qdd | cut curr line | q | buffer=a..v,x..z(Not w,W) |-+
* +---------------------------------------- | |
* | "Qdd | cut & append | q | Note: w and W are reserved | |
applicable
* +---------------------------------------- for Windows Clipboard |
+-to word &
* | "qndd | cut n lines | q | | |
block
* +---------------------------------------- | |
* | "Qndd | cut & append | q | |-+
* +---------------------------------------------------------------------+
* | "wndd | cut n lines | WinClip | buffer=w or W |
* +=====================================================================+
* | p | insert after | default | |
* +---------------------------------------------------------------------+
* | "qp | insert after | q | |
* +---------------------------------------------------------------------+
* | P | insert before | default | |
* +---------------------------------------------------------------------+
* | "qP | insert before | q | |
* +---------------------------------------------------------------------+
* | "wp | insert after | WinClip | enhanced to support paste |
* +---------------------------------------| |
* | "wP | insert before | WinClip | before/after curr line |
* +---------------------------------------------------------------------+
*
*
* NOTE: block is implemented differently in vi(i.e. between two marks),
* the implementation of block yank/delete is just an extension of the
* vi commands with TSE blocks.
*
**************************************************************************/
constant _PASTE = 1, _COPY = 2, _COPYAPPEND = 3, _CUT = 4,
_CUTAPPEND = 5
string ActBuff[26] = ""
/***************************************************************************
Purpose: Returns the percentage of text in the file with respect to
current line
***************************************************************************/
string proc ShowPercentage()
return(str((100 * CurrLine()) / NumLines())+"%")
end
proc YankTasks(integer operation)
case operation
when _COPY Copy()
when _COPYAPPEND Copy(_APPEND_)
when _PASTE Paste()
when _CUT Cut()
when _CUTAPPEND Cut(_APPEND_)
endcase
end
proc NameBuffer(integer operation, string buff)
integer cid, id, SaveClipBoardId
string BufferName[10] = buff
if (length(buff) == 0) // no name, default buffer
YankTasks(operation)
return() // get out of here
elseif (upper(buff) == "W")
case operation
when _COPY CopyToWinClip()
when _PASTE PasteFromWinClip()
when _CUT
CopyToWinClip()
DelBlock()
endcase
return()
endif
BufferName = "+++" + BufferName // Fudge for scratch
id = GetBufferId(BufferName) // See if already there
if operation _PASTE and id == 0
cid = GetBufferId()
id = CreateBuffer(BufferName, _SYSTEM_) // create a buffer
GotoBufferId(cid)
endif
if id 0 // if it worked
SaveClipBoardId = Set(ClipBoardId, id) // save old, set new
lipBoard
YankTasks(operation) // do the yank job
Set(ClipBoardId, SaveClipBoardId) // restore ClipBoard
else
warn("Could not create/find buffer")
endif
return ()
end
/***************************************************************************
Main routine.
**************************************************************************/
//proc main()
proc vi_cmd()
integer i,n, old_InsLineBlksAbove, WinClipPaste = 0
string cmd[10] = "", op[1]
string buff[10] = ""
string unknown[50] = "vi command unknown: "
if ask(" ["+ShowPercentage()+"]"+" vi command ("+ActBuff+") ",cmd)
AND length(cmd)
unknown = unknown + cmd
op = cmd
PushBlock()
if cmd[1] == '"' // buffer has been specified
buff = SubStr(cmd,2,1)
// remember the buffer
if (length(ActBuff) == 0)
ActBuff = ActBuff + lower(buff)
elseif (pos(lower(buff),ActBuff) == 0)
ActBuff = ActBuff + lower(buff)
endif
cmd = SubStr(cmd,3,length(cmd)-2)
op = SubStr(cmd,1,1)
if (buff[1] < 'a') // upper case = append
if (cmd[1] == 'y')
op = 'Y' // copy + append
elseif (buff[1] == 'd')
op = 'D' // cut + append
endif
endif
endif
i = 1
n = 0
while (cmd[i] >= '0') AND (cmd[i] <='9')
i = i + 1
endwhile
if (i > 1) // no. has been specified
n = val(SubStr(cmd,1,i-1)) // extract the no.
cmd = SubStr(cmd,i,length(cmd)-1)
op = cmd
endif
if (upper(op) "P")
PushBlock()
endif
i = n
case cmd
when "yy" // yank line
UnmarkBlock()
MarkLine()
PlaceMark("Q")
while (n > 1) // no. is specified
down()
n = n - 1
endwhile
MarkLine()
GotoMark("Q")
if (i == 0) i = 1 endif
message(i," line(s) yanked (",buff,")")
when "yw", "dw" // yank word, cut word
PlaceMark("Q")
BegWord()
MarkStream()
EndWord() // already marked one word
while (n > 1) // no. is specified
WordRight()
EndWord()
n = n - 1
endwhile
MarkStream()
GotoMark("Q")
when "yb", "y" // yank block
message("Block yanked (",buff,")")
when "dd" // delete line
UnmarkBlock()
MarkLine()
while (n > 1)
down()
n = n - 1
endwhile
MarkLine()
if (i == 0) i = 1 endif
message(i," line(s) cut (",buff,")")
when "db", "d" // delete block
message("Block cut (",buff,")")
when "p" // paste after
when "P" // paste before
otherwise
message(Unknown)
PopBlock()
return()
endcase
case op[1]
when 'p'
old_InsLineBlksAbove =
set(InsertLineBlocksAbove,OFF)
// paste from WinClip always puts the text above
// current line, so we have to do the hard work to
// implement this "paste after"
if (upper(buff) == "W")
if (CurrLine() == NumLines())
AddLine()
WinClipPaste = 1
else
down()
endif
endif
NameBuffer(_PASTE,buff)
set(InsertLineBlocksAbove,old_InsLineBlksAbove)
if (WinClipPaste)
EndFile()
DelLine()
Up()
if (isCursorInBlock())
GotoBlockBegin()
endif
endif
when 'd'
NameBuffer(_CUT,buff)
when 'D'
NameBuffer(_CUTAPPEND,buff)
when 'y'
NameBuffer(_COPY,buff)
when 'Y'
NameBuffer(_COPYAPPEND,buff)
when 'P'
old_InsLineBlksAbove =
set(InsertLineBlocksAbove,ON)
NameBuffer(_PASTE,buff)
set(InsertLineBlocksAbove,old_InsLineBlksAbove)
otherwise
message(Unknown)
endcase
if (upper(op) "P")
PopBlock()
endif
endif
end
vi_cmd()
/****************************************************************************/
---
---------------
* Origin: apana>>>>>fidonet [sawasdi.apana.org.au] (3:800/846.13)
|