Source Insight常用快捷键及注释快捷键设置

来源:互联网 发布:网络彩票代理怎么做的 编辑:程序博客网 时间:2024/04/30 07:45

在使用SI过程中,我根据自己的使用习惯修改了它的默认快捷键,并且在配置文件中添加了一些人性化功能,下面一一介绍:

修改快捷键:Options->Key Assignments...

1.main window:Esc       2.Hight light:Middle Mouse

3.Go Back:Alt+z              4.Go Forward:Alt+x              

5.Caller:Alt+c                  6.Reference:Alt+r

7.Previous Link:Alt+a    8.Next Link:Alt+s

9.First Link:Alt+d          

10.Go Line:Alt+g           11.Select Line:Alt+l

12.Symbol Win:Alt+q    13.Activate SW:Alt+w

14.Projcet Win:Alt+[       15.Activate PW:Alt+]

16.Contex Win:Alt+,     17.Activate CW:Alt+.

18.Relation Win:Alt+;   19.Activate RW:Alt+'

20.Select All:Ctrl+a          21.Save All:Ctrl+Shift+a

22.Browse Project Symbols:Alt+b


添加一些配置文件宏,比如:注释掉代码:单行注释、多行注释,将选中内容注释掉;在一行代码的前、后添加注释性文字等。

打开Projcet->Open project,选择base,可以看到utils.em文件,将下列宏添加到该文件中,并在其他工程里加入该文件,

在上面介绍的快捷键添加方式里找到该宏并自定义快捷键。

单行、多行注释:


将上面的代码保存到utils.em文件,打开source insight,将该文件添加到工程中,然后在Options->Key Assignments中你就可以看到这个宏了,宏的名字是MultiLineComments,然后我们为它分配快捷键“Ctrl + /”,然后就可以了。

这是一份添加“#ifdef 0”和“#endif”的宏代码,定义快捷键为Ctrl+#

这份宏的代码可以把光标所在的行注释掉,定义快捷键为Ctrl+*:

将一行中鼠标选中部分注释掉,定义快捷键为Ctrl+shift+*:



在一行代码前添加注释性文字,定义快捷键为Alt+/:

在一行代码前添加注释性文字,定义快捷键为Alt+\:


最后是source insight与宏有关的资源:

  • source insight官方的宏库
  • source insight官方帮助文档

 

 

 

转另一博客中的宏

使用“Options” -- “Menu Assignments” 新建一个菜单项Work,然后把Macro:SetAuthorName, Macro:NewHeaderFileStruct, Macro:NewSrcFileStruct, Macro:InsertFileHeader, Macro:InsertFunctionHeader加入这个自定义的菜单里。

 

/* Utils.em - a small collection of useful editing macros */macro SetAuthorName(){szAuthorName = Ask("Please Input Your Name:")szAuthorName = StrTrim(szAuthorName)SetReg(REG_AUTHOR_NAME, szAuthorName)}/*-----------------------------------------------------------------------------I N S E R T   H E A D E RInserts a comment header block at the top of the current function.This actually works on any type of symbol, not just functions.To use this, define an environment variable "MYNAME" and set itto your email name.  eg. set MYNAME=raygr-------------------------------------------------------------------------*/macro InsertFunctionHeader(){// Get a handle to the current file buffer and the name// and location of the current symbol where the cursor is.hbuf = GetCurrentBuf()szFunc = GetCurSymbol()nLine = GetSymbolLine(szFunc)szMyName   = GetReg(REG_AUTHOR_NAME)szDate     = GetCurDate()InsBufLine(hbuf, nLine,      "  ")InsBufLine(hbuf, nLine + 1,  "/******************************************************************************")InsBufLine(hbuf, nLine + 2,  "  Function: @szFunc@")InsBufLine(hbuf, nLine + 3,  "  Description: ")InsBufLine(hbuf, nLine + 4,  "  INPUT: ")InsBufLine(hbuf, nLine + 5,  "  OUTPUT: ")InsBufLine(hbuf, nLine + 6,  "  Return: ")InsBufLine(hbuf, nLine + 7,  "  Revision: ")InsBufLine(hbuf, nLine + 8,  "         1. Author: @szMyName@")InsBufLine(hbuf, nLine + 9,  "            Date: @szDate@")InsBufLine(hbuf, nLine + 10, "            Changes: First create ")InsBufLine(hbuf, nLine + 11, " ******************************************************************************/")// put the insertion point inside the header commentSetBufIns(hbuf, nLine, 12)}macro InsertMaintenanceComment(){// Get a handle to the current file buffer and the name// and location of the current symbol where the cursor is.hbuf = GetCurrentBuf()nLine = GetBufLnCur(hbuf)szCurLine = GetBufLine(hbuf, nLine)szMyName   = GetReg(REG_AUTHOR_NAME)szDate     = GetCurDate()if (IsBlankLine(szCurLine)){szBlank = szCurLine}else{szBlank = GetBlankString(szCurLine)InsBufLine(hbuf, nLine + 1,  szBlank)nLine = nLine + 1}InsBufLine(hbuf, nLine + 1,  "@szBlank@/*Sart:     ID: SVN: ,@szMyName@ @szDate@ */")InsBufLine(hbuf, nLine + 2,  szBlank)InsBufLine(hbuf, nLine + 3,  "@szBlank@/*End :     ID: SVN: ,@szMyName@ @szDate@ */")}/* InsertFileHeader:   Inserts a comment header block at the top of the current function.   This actually works on any type of symbol, not just functions.   To use this, define an environment variable "MYNAME" and set it   to your email name.  eg. set MYNAME=raygr*/macro InsertFileHeader(){hbuf = GetCurrentBuf()szFilePath = GetBufName(hbuf)szFileName = GetFileNameFromPath(szFilePath)szMyName   = GetReg(REG_AUTHOR_NAME)szDate     = GetCurDate()InsBufLine(hbuf,  0, "  ")InsBufLine(hbuf,  1, "/******************************************************************************")InsBufLine(hbuf,  2, "  Copyright (c), 1991-2007, My Company.")InsBufLine(hbuf,  3, "  ")InsBufLine(hbuf,  4, "  File: @szFileName@")InsBufLine(hbuf,  5, "  Description: ")InsBufLine(hbuf,  6, "  Function List: //List main functions")InsBufLine(hbuf,  7, "  Revision:")InsBufLine(hbuf,  8, "         1. Author: @szMyName@")InsBufLine(hbuf,  9, "            Date: @szDate@")InsBufLine(hbuf, 10, "            Changes: First create file")InsBufLine(hbuf, 11, " ******************************************************************************/")return 12 /* line number of inserted */}macro NewHeaderFileStruct(){hbuf = GetCurrentBuf()szFilePath = GetBufName(hbuf)szFileName = GetFileNameFromPath(szFilePath)szFileMainName = GetFileMainName(szFileName)szFileExtName  = GetFileExtName(szFileName)szFileMainName = toupper(szFileMainName)szFileExtName  = toupper(szFileExtName)InsBlankLine(hbuf,  0, 2)InsBufLine(hbuf,  0, "#endif /* __@szFileMainName@_@szFileExtName@__ */")InsBlankLine(hbuf,  0, 2)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                                 END                                        * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 10)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                               FUNCTION                                     * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 10)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                                STRUCT                                      * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 10)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                                 ENUM                                       * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 10)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                                 MACRO                                      * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 2)InsBufLine(hbuf,  0, "#define __@szFileMainName@_@szFileExtName@__")InsBufLine(hbuf,  0, "#ifndef __@szFileMainName@_@szFileExtName@__")InsBlankLine(hbuf,  0, 2)InsertFileHeader()}macro NewSrcFileStruct(){hbuf = GetCurrentBuf()szFilePath = GetBufName(hbuf)szFileName = GetFileNameFromPath(szFilePath)szFileMainName = GetFileMainName(szFileName)szFileExtName  = GetFileExtName(szFileName)szFileMainName = toupper(szFileMainName)szFileExtName  = toupper(szFileExtName)InsBlankLine(hbuf,  0, 2)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                                 END                                        * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 10)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                               FUNCTION                                     * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 10)InsBufLine(hbuf,  0, " ******************************************************************************/")InsBufLine(hbuf,  0, " *                                GLOBAL                                      * ")InsBufLine(hbuf,  0, "/****************************************************************************** ")InsBlankLine(hbuf,  0, 4)InsertFileHeader()}macro GetCurDate(){stCurTime  = GetSysTime(1)szDate     = cat(stCurTime.Year, "-")szDate     = cat(szDate, stCurTime.Month)szDate     = cat(szDate, "-")szDate     = cat(szDate, stCurTime.Day)return szDate}macro StrTrim(szSrc){szDst = StrTrimLeft(szSrc)szDst = StrTrimRight(szDst)return szDst}macro StrTrimLeft(szSrc){len = strlen(szSrc)i = 0while (i < len){if (" " != szSrc[i] &&    "/t" != szSrc[i]){szDst = strmid(szSrc, i, len)    return szDst}i = i + 1}return ""}macro StrTrimRight(szSrc){len = strlen(szSrc)i = len - 1while (i >= 0){if (" " != szSrc[i] &&    "/t" != szSrc[i]){szDst = strmid(szSrc, 0, i + 1)    return szDst}i = i - 1}return ""}macro GetFileNameFromPath(path){namelen = strlen(path)i = namelenwhile (i > 0){if ("//" == path[i]){break;}i = i -1}if (i <= 0){return path}j = namelen - ifile = strmid(path, i + 1, namelen)return file}macro GetFileMainName(fileName){namelen = strlen(fileName)i = namelenwhile (i > 0){if ("." == fileName[i]){break;}i = i -1}if (i <= 0){return fileName}file = strmid(fileName, 0, i)return file}macro GetFileExtName(fileName){namelen = strlen(fileName)i = namelenwhile (i > 0){if ("." == fileName[i]){break;}i = i -1}file = strmid(fileName, i + 1, namelen)return file}macro InsBlankLine(hbuf, startLine, lineCount){i = lineCountwhile (i > 0){InsBufLine(hbuf,  startLine, "")i = i -1}}macro IsBlankLine(szLine){len = strlen(szLine)i = 0while (i < len){if (" " != szLine[i] &&    "/t" != szLine[i])    return Falsei = i + 1}return True}macro GetBlankString(szLine){len = strlen(szLine)i = 0while (i < len){if (" " != szLine[i] &&    "/t" != szLine[i]){szBlank = strmid(szLine, 0, i)    return szBlank}i = i + 1}return szLine}// Inserts "Returns True .. or False..." at the current linemacro ReturnTrueOrFalse(){hbuf = GetCurrentBuf()ln = GetBufLineCur(hbuf)InsBufLine(hbuf, ln, "    Returns True if successful or False if errors.")}/* Inserts ifdef REVIEW around the selection */macro IfdefReview(){IfdefSz("REVIEW");}/* Inserts ifdef BOGUS around the selection */macro IfdefBogus(){IfdefSz("BOGUS");}/* Inserts ifdef NEVER around the selection */macro IfdefNever(){IfdefSz("NEVER");}// Ask user for ifdef condition and wrap it around current// selection.macro InsertIfdef(){sz = Ask("Enter ifdef condition:")if (sz != "")IfdefSz(sz);}macro InsertCPlusPlus(){IfdefSz("__cplusplus");}// Wrap ifdef <sz> .. endif around the current selectionmacro IfdefSz(sz){hwnd = GetCurrentWnd()lnFirst = GetWndSelLnFirst(hwnd)lnLast = GetWndSelLnLast(hwnd)hbuf = GetCurrentBuf()InsBufLine(hbuf, lnFirst, "#ifdef @sz@")InsBufLine(hbuf, lnLast+2, "#endif /* @sz@ */")}// Delete the current line and appends it to the clipboard buffermacro KillLine(){hbufCur = GetCurrentBuf();lnCur = GetBufLnCur(hbufCur)hbufClip = GetBufHandle("Clipboard")AppendBufLine(hbufClip, GetBufLine(hbufCur, lnCur))DelBufLine(hbufCur, lnCur)}// Paste lines killed with KillLine (clipboard is emptied)macro PasteKillLine(){PasteEmptyBuf(GetBufHandle("Clipboard"))}// delete all lines in the buffermacro EmptyBuf(hbuf){lnMax = GetBufLineCount(hbuf)while (lnMax > 0){DelBufLine(hbuf, 0)lnMax = lnMax - 1}}// Ask the user for a symbol name, then jump to its declarationmacro JumpAnywhere(){symbol = Ask("What declaration would you like to see?")JumpToSymbolDef(symbol)}// list all siblings of a user specified symbol// A sibling is any other symbol declared in the same file.macro OutputSiblingSymbols(){symbol = Ask("What symbol would you like to list siblings for?")hbuf = ListAllSiblings(symbol)SetCurrentBuf(hbuf)}// Given a symbol name, open the file its declared in and// create a new output buffer listing all of the symbols declared// in that file.  Returns the new buffer handle.macro ListAllSiblings(symbol){loc = GetSymbolLocation(symbol)if (loc == ""){msg ("@symbol@ not found.")stop}hbufOutput = NewBuf("Results")hbuf = OpenBuf(loc.file)if (hbuf == 0){msg ("Can't open file.")stop}isymMax = GetBufSymCount(hbuf)isym = 0;while (isym < isymMax){AppendBufLine(hbufOutput, GetBufSymName(hbuf, isym))isym = isym + 1}CloseBuf(hbuf)return hbufOutput}macro SuperBackspace(){    hwnd = GetCurrentWnd();    hbuf = GetCurrentBuf();    if (hbuf == 0)        stop;   // empty buffer    // get current cursor postion    ipos = GetWndSelIchFirst(hwnd);    // get current line number    ln = GetBufLnCur(hbuf);    if ((GetBufSelText(hbuf) != "") || (GetWndSelLnFirst(hwnd) != GetWndSelLnLast(hwnd))) {        // sth. was selected, del selection        SetBufSelText(hbuf, " ");  // stupid & buggy sourceinsight :(        // del the " "        SuperBackspace(1);        stop;    }    // copy current line    text = GetBufLine(hbuf, ln);    // get string length    len = strlen(text);    // if the cursor is at the start of line, combine with prev line    if (ipos == 0 || len == 0) {        if (ln <= 0)            stop;   // top of file        ln = ln - 1;    // do not use "ln--" for compatibility with older versions        prevline = GetBufLine(hbuf, ln);        prevlen = strlen(prevline);        // combine two lines        text = cat(prevline, text);        // del two lines        DelBufLine(hbuf, ln);        DelBufLine(hbuf, ln);        // insert the combined one        InsBufLine(hbuf, ln, text);        // set the cursor position        SetBufIns(hbuf, ln, prevlen);        stop;    }    num = 1; // del one char    if (ipos >= 1) {        // process Chinese character        i = ipos;        count = 0;        while (AsciiFromChar(text[i - 1]) >= 160) {            i = i - 1;            count = count + 1;            if (i == 0)                break;        }        if (count > 0) {            // I think it might be a two-byte character            num = 2;            // This idiot does not support mod and bitwise operators            if ((count / 2 * 2 != count) && (ipos < len))                ipos = ipos + 1;    // adjust cursor position        }    }    // keeping safe    if (ipos - num < 0)        num = ipos;    // del char(s)    text = cat(strmid(text, 0, ipos - num), strmid(text, ipos, len));    DelBufLine(hbuf, ln);    InsBufLine(hbuf, ln, text);    SetBufIns(hbuf, ln, ipos - num);    stop;}macro AddStruct(){hbuf = GetCurrentBuf()ln = GetBufLnCur(hbuf)var szTypeNameszTypeName = Ask("请输入结构名称:")szTypeName = toupper(szTypeName)InsBufLine(hbuf, ln, "typedef struct tag_@szTypeName@")ln = ln + 1InsBufLine(hbuf, ln, "{")ln = ln + 1InsBufLine(hbuf, ln, "    ")ln = ln + 1InsBufLine(hbuf, ln, "} @szTypeName@;")ln = ln + 1}/*=========================================================================*//*  Function: UniformCommentStyle                                          *//*  Description: Change all // to /* */                             *//*=========================================================================*/macro UniformCommentStyle(){    var hbuf    hbuf = GetCurrentBuf ()  // current filevar dwTotalLinedwTotalLine = GetBufLineCount(hbuf)var dwLinedwLine = 0while (dwLine < dwTotalLine){var szLineszLine = GetBufLine(hbuf, dwLine)var nLineLenvar nPosnLineLen = strlen(szLine)nPos = 0while (nPos < nLineLen){if (nPos > 0){if (szLine[nPos] == "/" && szLine[nPos - 1] == "/"){szLine[nPos] = "*"szLine = Cat(szLine, "*/")PutBufLine (hbuf, dwLine, szLine)break;}}nPos = nPos+1;}dwLine = dwLine + 1;}}/*=========================================================================*//*  Function: AddCodeGroup                                               *//*  Description: Add {} and auto indent                                    *//*=========================================================================*/macro AddCodeGroup(){hbuf = GetCurrentBuf()ln = GetBufLnCur(hbuf) + 1    szText = GetBufLine (hBuf, ln-1)    nIndent = 0;    nSpace  = 0;    while (nIndent < strlen(szText))    {if (szText[nIndent] == " "){    nIndent = nIndent + 1;    nSpace  = nSpace + 1;    }else if (szText[nIndent] == ""){    nIndent = nIndent + 1;    nSpace  = nSpace + 4;    }else    break;    }    szDate = GetCurDate()szSpace = ""nIndent = 0;    while (nIndent < nSpace)    {szSpace = Cat(szSpace, " ");nIndent = nIndent + 1;    }szBrace = Cat(szSpace, "{");InsBufLine(hbuf, ln, szBrace)ln = ln + 1szBrace = Cat(szSpace, "    ");InsBufLine(hbuf, ln, szBrace)ln = ln + 1szBrace = Cat(szSpace, "}");InsBufLine(hbuf, ln, szBrace)ln = ln - 1;SetBufIns(hbuf, ln, nSpace + 4)}


 

原创粉丝点击