[PSPad] 複製游標列的內容的Script

[PSPad]
PSPad的Scripting功能初探

文說明了PSPad的Scripting環境,而本篇腳本的功用是按Ctrl+D複製目前游標列的內容到下一列,這個功能是比照IntelliJ-
IDEA的編輯鍵,有了這個按鍵,複製列的步驟:【標示→Ctrl+C→Enter鍵→Ctrl+V】就簡化成一個按鍵,對於寫程式非常方便。

另外,若標示數列的話,會複製標示列內的容。

dupLine.vbs
'***********************************************************

'$Id$

'Duplicate current line; like IntelliJ-IDEA's Ctrl+D

'emisjerry@gmail.com; http://blog.xuite.net/emisjerry/tech

'***********************************************************

const module_name  =
"dupLine"        
'this name must be unique !!!

const module_ver   =
"0.001a"           
'version

sub Init

  addMenuItem "Duplicate current line", "", "dupLine", "CTRL+D"

end sub

sub dupLine

  dim oEditor, iCaretX, iCaretY

 

  set oEditor =
newEditor()          
'new editor object

  oEditor.assignActiveEditor

  iCaretX = oEditor.caretX

  if oEditor.selText = "" then  'No selection area

    sLine = oEditor.lineText

    'Since the indent will add more leading
spaces, so we trim it first.

    sLine = Trim(sLine) + vbNewLine + sLine

    oEditor.lineText(sLine)

    oEditor.caretX(iCaretX)  'move
cursor to the same horizontal position

  else

    iCaretY = oEditor.caretY - 1

    sLine = oEditor.selText

    if InStr(sLine, Chr(13)) > 0 then

      sLine = Left(sLine,
Len(sLine)-2) + vbNewLine + sLine

    else

      sLine = sLine + sLine

    end if

   

    'echo("$" & sLine & "$,"
& iCaretY)

    oEditor.selText(sLine)

    oEditor.caretX(iCaretX)  'move
cursor to the same horizontal position   

   
'oEditor.caretY(iCatetY)   

  end if

end sub


##


您可能也會有興趣的類似文章

簡睿

服務於軟體業的資訊老兵。興趣廣泛,學習力佳,樂於分享所知所學。

您可能也會喜歡…

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *