欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > 内容正文

Source Insight自定义快捷键,sourceinsight

来源: 开发者 投稿于  被查看 7752 次 评论:285

Source Insight自定义快捷键,sourceinsight


鄙人一直用的是Eclipse来开发,如果只是做java的话,这个就够了,但因时不时要查C/C++的代码,这个时候这个工具就有点力不从心了,因为C/C++的代码非常多,一般放在服务器上,就得用Source Insight来看了,Source Insight非常强大,它能够把服务器上的代码直接导入到项目中,但开始用的时候,有点不习惯,觉得不如Eclipse方便,特别是快捷键方面,其实这一点,Source Insight比Eclipse强多了,我觉得就好像是Photoshop与美图秀秀一样,这里就介绍一下,如何修改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里面就是一堆的宏代码

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

添加一段宏:

这段代码是 //行注释

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

//添加注释
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?

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


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

//注释选中行/* */
macro CommentSelStr()  
{  
    hwnd=GetCurrentWnd()  
    //sel=GetWndSel(hwnd)  
    
    lnFirst=GetWndSelLnFirst(hwnd)  
    lnLast=GetWndSelLnLast(hwnd)  
    hbuf=GetCurrentBuf()  
    
    Ln = Lnfirst   
<span style="white-space:pre">	</span>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

//添加“#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)
}




注:段落注释是本人自己写的,其他是网络上复制下来的,这里面涉及到的函数都很简单,





相关频道:

用户评论