Source Insight自定义快捷键

来源:互联网 发布:淘宝商家发货流程 编辑:程序博客网 时间:2024/05/18 19:45

这里就介绍一下,如何修改Source Insight注释快捷键

注释有两种:

//行注释在Eclipse中的快捷键是:Ctrl+/

/*段落注释*/在Eclipse中的快捷键是:Ctrl+Shift+/

相信你使用Source Insight来查看代码时,你应该会编程,那么,在Source Insight里添加注释,就要写代码了,其语法跟C语言差不多,里面内置很多函数,只要调用就行了,建议先看遍Help,这里面有详细的函数说明


其实Source Insight里面的快捷键都是对应一段宏代码,这些代码就放在

D:\用户目录\Documents\Source Insight\Projects\Base\utils.em

这个文件里,当然这个目录可能跟你的不一样,但你可以这样找到:

Progect->Open progect->Base

这个Base是安装完成后,就会有的一个项目,选中它,就会显示其路径

utils.em里面就是一堆的宏代码

用任何一款文本编辑器都可以打开它,

添加一段宏:

这段代码是 //行注释

实现的功能是对选中的行加/取消行注释

[cpp] view plain copy
print?
  1. //添加注释  
  2. macro MultiLineComment()      
  3. {  
  4.   
  5.     hwnd = GetCurrentWnd()     
  6.     selection = GetWndSel(hwnd)     
  7.     LnFirst = GetWndSelLnFirst(hwnd) //取首行行号  
  8.     LnLast = GetWndSelLnLast(hwnd)   //取末行行号  
  9.     hbuf = GetCurrentBuf()      
  10.     if(GetBufLine(hbuf, 0) == "//magic-number:tph85666031"){     
  11.         stop     
  12.     }     
  13.   
  14.     Ln = Lnfirst     
  15.     buf = GetBufLine(hbuf, Ln)     
  16.     len = strlen(buf)     
  17.     while(Ln <= Lnlast) {     
  18.         buf = GetBufLine(hbuf, Ln)  //取Ln对应的行  
  19.         if(buf == ""){                    //跳过空行  
  20.             Ln = Ln + 1     
  21.             continue     
  22.         }     
  23.         if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行  
  24.             if(StrMid(buf, 1, 2) == "/"){     
  25.                 PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))     
  26.             }     
  27.   
  28.         }     
  29.   
  30.         if(StrMid(buf,0,1) != "/"){          //需要添加注释  
  31.             PutBufLine(hbuf, Ln, Cat("//", buf))     
  32.         }     
  33.         Ln = Ln + 1     
  34.     }     
  35.     SetWndSel(hwnd, selection)     
  36. }   
添加完成,保存!再给这段宏加个快捷键:Ctrl+/

方法:

Options->Key Assignments

弹出一个对话框,在Command下面的输入框中,输入刚保存的宏名 MultiLineComment (不要用复制,手动输入最好)

其实只要输入前几个字符,下面的选择框里就会过滤掉其他的宏名,选中要添加快捷键的宏,如果没有添加快捷键的话,在Keystrokes下面是没有按键名的,单击Assign New Key...,弹出一个对话框,

Press the key-combination you want to assign,or click a mouse.....

大致的意思就是请按组合键或点击鼠标,最好不要按鼠标,可以使用Ctrl Alt Shift组合,按我们的意思,只要按下Ctrl+/就可以了,在Keystrokes 下面就会出现Ctrl+/,如果有重复的,就会有一个提示,

Do you want to remove that keystroke from the "XXXXXXX" command?

如果你希望当前宏使用这个快捷键,点 是 ,其他可以再换个组合


下面再添加/*段落注释*/

[cpp] view plain copy
print?
  1. //注释选中行/* */  
  2. macro CommentSelStr()    
  3. {    
  4.     hwnd=GetCurrentWnd()    
  5.     //sel=GetWndSel(hwnd)    
  6.       
  7.     lnFirst=GetWndSelLnFirst(hwnd)    
  8.     lnLast=GetWndSelLnLast(hwnd)    
  9.     hbuf=GetCurrentBuf()    
  10.       
  11.     Ln = Lnfirst     
  12.     buf = GetBufLine(hbuf, Ln)   
  13.     //msg(buf)  
  14.     if(buff==""||Strlen(buf)==0){  
  15.     //msg("buf is null")  
  16.     }else{  
  17.       
  18.         if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行  
  19.                 if(StrMid(buf, 1, 2) == "*"){     
  20.                     PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))     
  21.                 }else{  
  22.                     str=cat("/*",buf)  
  23.                     PutBufLine (hbuf, ln, str)  
  24.                 }     
  25.   
  26.             } else{  
  27.                 str=cat("/*",buf)  
  28.                 PutBufLine (hbuf, ln, str)  
  29.         }  
  30.               
  31.         ln=lnLast  
  32.         buf=GetBufLine(hbuf, Ln)  
  33.         len_s=strlen(buf)  
  34.         //msg(len_s)  
  35.         //msg(buf)  
  36.         //msg(StrMid(buf, strlen(buf)-1, strlen(buf)))  
  37.         //msg(StrMid(buf, strlen(buf)-2, strlen(buf)-1))  
  38.         if(StrMid(buf, strlen(buf)-1, strlen(buf)) == "/"){  
  39.             if(StrMid(buf, strlen(buf)-2, strlen(buf)-1) == "*"){  
  40.                 PutBufLine(hbuf, Ln, StrMid(buf, 0, Strlen(buf)-2))  
  41.             }else{  
  42.                 str=cat(buf,"*/")  
  43.                 PutBufLine (hbuf, ln, str)  
  44.         }  
  45.           
  46.         }else{  
  47.             str=cat(buf,"*/")  
  48.             PutBufLine (hbuf, ln, str)  
  49.         }  
  50.         //SetWndSel( hwnd, sel )      
  51.     }  
  52. }    



添加快捷键:Ctrl+Shift+/,方法如上面所述


下面是几个常用的宏,建议快捷键:

AddMacroComment:Ctrl+Shift+3

[cpp] view plain copy
print?
  1. //添加“#ifdef 0”和“#endif”  
  2. macro AddMacroComment()    
  3. {    
  4.     hwnd=GetCurrentWnd()    
  5.     sel=GetWndSel(hwnd)    
  6.     lnFirst=GetWndSelLnFirst(hwnd)    
  7.     lnLast=GetWndSelLnLast(hwnd)    
  8.     hbuf=GetCurrentBuf()    
  9.      
  10.     if(LnFirst == 0) {    
  11.             szIfStart = ""    
  12.     }else{    
  13.             szIfStart = GetBufLine(hbuf, LnFirst-1)    
  14.     }    
  15.     szIfEnd = GetBufLine(hbuf, lnLast+1)    
  16.     if(szIfStart == "#if 0" && szIfEnd == "#endif") {    
  17.             DelBufLine(hbuf, lnLast+1)    
  18.             DelBufLine(hbuf, lnFirst-1)    
  19.             sel.lnFirst = sel.lnFirst – 1    
  20.             sel.lnLast = sel.lnLast – 1    
  21.     }else{    
  22.             InsBufLine(hbuf, lnFirst, "#if 0")    
  23.             InsBufLine(hbuf, lnLast+2, "#endif")    
  24.             sel.lnFirst = sel.lnFirst + 1    
  25.             sel.lnLast = sel.lnLast + 1    
  26.     }    
  27.      
  28.     SetWndSel( hwnd, sel )    
  29. }   
  30.   
  31. //注释光标所在行  
  32. macro CommentSingleLine(){      
  33.     hbuf = GetCurrentBuf()      
  34.     ln = GetBufLnCur(hbuf)      
  35.     str = GetBufLine (hbuf, ln)      
  36.     str = cat("/*",str)      
  37.     str = cat(str,"*/")      
  38.     PutBufLine (hbuf, ln, str)  
  39. }  




转自:http://blog.csdn.net/ytmfdw/article/details/43487453





原创粉丝点击