Source Insight自定义快捷键

这里就介绍一下,如何修改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里面就是一堆的宏代码

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

添加一段宏:

这段代码是 //行注释

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

  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. }   
//添加注释
macro MultiLineComment()    
{

	hwnd = GetCurrentWnd()   
	selection = GetWndSel(hwnd)   
	LnFirst = GetWndSelLnFirst(hwnd) //取首行行号
	LnLast = GetWndSelLnLast(hwnd)   //取末行行号
	hbuf = GetCurrentBuf()    
	if(GetBufLine(hbuf, 0) == "//magic-number:tph85666031"){   
   		stop   
	}   

	Ln = Lnfirst   
	buf = GetBufLine(hbuf, Ln)   
	len = strlen(buf)   
	while(Ln <= Lnlast) {   
		buf = GetBufLine(hbuf, Ln)  //取Ln对应的行
		if(buf == ""){                    //跳过空行
			Ln = Ln + 1   
			continue   
		}   
		if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行
			if(StrMid(buf, 1, 2) == "/"){   
				PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))   
 			}   

		}   

		if(StrMid(buf,0,1) != "/"){          //需要添加注释
      		PutBufLine(hbuf, Ln, Cat("//", buf))   
   		}   
  		Ln = Ln + 1   
	}   
	SetWndSel(hwnd, selection)   
} 
添加完成,保存!再给这段宏加个快捷键: 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?

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


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

  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. }    
//注释选中行/* */
macro CommentSelStr()  
{  
    hwnd=GetCurrentWnd()  
    //sel=GetWndSel(hwnd)  
    
    lnFirst=GetWndSelLnFirst(hwnd)  
    lnLast=GetWndSelLnLast(hwnd)  
    hbuf=GetCurrentBuf()  
    
    Ln = Lnfirst   
    buf = GetBufLine(hbuf, Ln) 
	//msg(buf)
	if(buff==""||Strlen(buf)==0){
	//msg("buf is null")
	}else{
	
		if(StrMid(buf, 0, 1) == "/") {       //需要取消注释,防止只有单字符的行
				if(StrMid(buf, 1, 2) == "*"){   
					PutBufLine(hbuf, Ln, StrMid(buf, 2, Strlen(buf)))   
	 			}else{
					str=cat("/*",buf)
					PutBufLine (hbuf, ln, str)
				}   

			} else{
				str=cat("/*",buf)
				PutBufLine (hbuf, ln, str)
		}
			
		ln=lnLast
		buf=GetBufLine(hbuf, Ln)
		len_s=strlen(buf)
		//msg(len_s)
		//msg(buf)
		//msg(StrMid(buf, strlen(buf)-1, strlen(buf)))
		//msg(StrMid(buf, strlen(buf)-2, strlen(buf)-1))
		if(StrMid(buf, strlen(buf)-1, strlen(buf)) == "/"){
			if(StrMid(buf, strlen(buf)-2, strlen(buf)-1) == "*"){
				PutBufLine(hbuf, Ln, StrMid(buf, 0, Strlen(buf)-2))
			}else{
				str=cat(buf,"*/")
				PutBufLine (hbuf, ln, str)
		}
		
		}else{
			str=cat(buf,"*/")
			PutBufLine (hbuf, ln, str)
		}
	    //SetWndSel( hwnd, sel )    
    }
}  



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


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

AddMacroComment:Ctrl+Shift+3

  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. }  
//添加“#ifdef 0”和“#endif”
macro AddMacroComment()  
{  
    hwnd=GetCurrentWnd()  
    sel=GetWndSel(hwnd)  
    lnFirst=GetWndSelLnFirst(hwnd)  
    lnLast=GetWndSelLnLast(hwnd)  
    hbuf=GetCurrentBuf()  
   
    if(LnFirst == 0) {  
            szIfStart = ""  
    }else{  
            szIfStart = GetBufLine(hbuf, LnFirst-1)  
    }  
    szIfEnd = GetBufLine(hbuf, lnLast+1)  
    if(szIfStart == "#if 0" && szIfEnd == "#endif") {  
            DelBufLine(hbuf, lnLast+1)  
            DelBufLine(hbuf, lnFirst-1)  
            sel.lnFirst = sel.lnFirst – 1  
            sel.lnLast = sel.lnLast – 1  
    }else{  
            InsBufLine(hbuf, lnFirst, "#if 0")  
            InsBufLine(hbuf, lnLast+2, "#endif")  
            sel.lnFirst = sel.lnFirst + 1  
            sel.lnLast = sel.lnLast + 1  
    }  
   
    SetWndSel( hwnd, sel )  
} 

//注释光标所在行
macro CommentSingleLine(){    
	hbuf = GetCurrentBuf()    
	ln = GetBufLnCur(hbuf)    
	str = GetBufLine (hbuf, ln)    
	str = cat("/*",str)    
	str = cat(str,"*/")    
	PutBufLine (hbuf, ln, str)
}




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





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值