Handy gEdit Snippet How To: Comment

I regularly use gEdit but up until recently I have never messed with Snippets. Many editors support Snippets in some fashion or another. So I thought I would share a quick Snippet with you and how to create it. Much of my time is spent with ColdFusion and CFEclipse. There you may know about the Ctrl+Shift+M comment snippet, but it would be nice if gEdit had this functionality for php, javascript, and css. Well here is how to implement it with gEdit. First off open gEdit. If you don't have the Snippets plugin installed just go to Edit->Preferences->Plugins and check the Snippets plugin.


Now we can open our Snippet Manager by going to Tools->Manage Snippets. A large window opens. Our languages are listed down the left hand side, click to expand PHP. Now click the button to add a new Snippet. I named mine "/ comment /". On the right column you will have a large text area to type your snippet code. Enter the following:


And click into the Shortcut Key Field and press the key combination "Ctrl+Shift+M". It should resemble the following:


Thats it! Now in your code you can highlight a selection and press the Ctrl+Shift+M keys and comment out that section of code. I'll briefly explain the syntax of the snippet. $GEDIT_SELECTED_TEXT is a variable gEdit supplies to you. If you have nothing selected it will be an empty string. $0 is the end place holder. When the snippet is finished executing you cursor will wind up here. You can also use Python , but the easiest way to learn the snippets is to dig right into the ones provided by default, or to read up on them at GNOME Live. Enjoy!