:args **/*.groovy --> this will set to all *.groovy files :argdo %s/text_want_to_replace/text to replace/ge | update
Tag Archive for editor
search and replace on multiple files
Rubber Band on AWT/Swing Component
import java.awt.Component;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class RubberBand {
private Rectangle rectangle;
private final List rubberBandListeners = new ArrayList();
private final Component component;
private int maxWidth;
private int maxHeight;
public RubberBand(Component component) {
this.component = component;
addListeners();
}
private void addListeners() {
component.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseDragged(MouseEvent event) {
reactOnMouseDragged(event);
}
});
component.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent event) {
reactOnMousePressed(event);
}
public void mouseClicked(MouseEvent event) {
reactOnMouseClicked();
}
});
}
public int getX() {
return rectangle.width >= 0 ? rectangle.x : (rectangle.x + rectangle.width);
}
public int getY() {
return rectangle.height >= 0 ? rectangle.y : (rectangle.y + rectangle.height);
}
public int getWidth() {
return Math.abs(rectangle.width);
}
public int getHeight() {
return Math.abs(rectangle.height);
}
public void addRubberBandListener(Runnable rubberBandListener) {
rubberBandListeners.add(rubberBandListener);
}
public void notifyRubberBandListeners() {
Iterator iterator = rubberBandListeners.iterator();
while (iterator.hasNext()) {
((Runnable)iterator.next()).run();
}
}
public void kill() {
rectangle = null;
notifyRubberBandListeners();
}
private void reactOnMouseDragged(MouseEvent event) {
if (rectangle == null) createRubberBand(0,0);
int x = Math.min(event.getX(), maxWidth-1);
x = Math.max(0, x);
int y = Math.min(event.getY(), maxHeight-1);
y = Math.max(0, y);
rectangle.width = x - rectangle.x;
rectangle.height = y - rectangle.y;
notifyRubberBandListeners();
}
private void createRubberBand(int x, int y) {
rectangle = new Rectangle(x, y, 0, 0);
}
private void reactOnMousePressed(MouseEvent event) {
createRubberBand(event.getX(), event.getY());
notifyRubberBandListeners();
}
private void reactOnMouseClicked() {
kill();
}
public boolean isActive() {
return rectangle != null;
}
public void setMaxBounds(int width, int height) {
this.maxWidth = width;
this.maxHeight = height;
}
}
Editing files from a find result
vim `find . -name *.html -exec grep -l search_str {} ;`
PHP File Editor
<?php
$loadcontent = "test-edit.php";
if($_POST['save_file']) {
$savecontent = stripslashes($_POST['savecontent']);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
print "<html><head><META http-equiv="refresh" content="0;URL=$_SERVER[PHP_SELF]"></head><body>";
}
}
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$lines = explode("
", $loadcontent);
$count = count($lines);
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a
";
}
?>
<p><font face="tahoma">Simply edit the page and hit save!</font></p>
<form method=post action="<?=$_SERVER[PHP_SELF]?>">
<input type="submit" name="save_file" value="Save"><br /><br />
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; overflow: auto; border: 0px groove; font-size: 12px; font-face:verdana;" name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre></td>
<td width="97%" align="left" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px; font-face:verdana;" name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF"><?=$loadcontent?>
Add custom/user-defined function highlighting to the default PHP.plist for e text editor
<!-- added after the definition for "language_constant" near the bottom --> <key>numeric_constant</key> <dict> <key>match</key> <string>([0-9]+)</string> <key>name</key> <string>constant.language.php</string> </dict> <!-- added as the last definition in the main "patterns" array --> <dict> <key>begin</key> <string>([0-9a-zA-Z_-]+)s*(</string> <key>beginCaptures</key> <dict> <key>1</key> <dict> <key>name</key> <string>entity.name.function.php</string> </dict> <key>2</key> <dict> <key>name</key> <string>punctuation.definition.parameters.begin.php</string> </dict> </dict> <key>end</key> <string>)</string> <key>endCaptures</key> <dict> <key>1</key> <dict> <key>name</key> <string>punctuation.definition.parameters.end.php</string> </dict> </dict> <key>name</key> <string>meta.function.php</string> <key>patterns</key> <array> <dict> <key>include</key> <string>#string-double-quoted</string> </dict> <dict> <key>include</key> <string>#numeric_constant</string> </dict> <dict> <key>include</key> <string>#string-single-quoted</string> </dict> <dict> <key>include</key> <string>#string-backtick</string> </dict> <dict> <key>include</key> <string>#var_global</string> </dict> <dict> <key>include</key> <string>#var_global_safer</string> </dict> <dict> <key>include</key> <string>#var_basic</string> </dict> <dict> <key>include</key> <string>#language_constant</string> </dict> </array> </dict> <!-- added in the "patterns" array for the original function definition (near line 450 in the default PHP.plist --> <dict> <key>include</key> <string>#numeric_constant</string> </dict>
Easy (un)commenting out of source code with vi editor
#" lhs comments map ,# :s/^/#/<CR> map ,/ :s/^////<CR> map ,> :s/^/> /<CR> map ," :s/^/"/<CR> map ,% :s/^/%/<CR> map ,! :s/^/!/<CR> map ,; :s/^/;/<CR> map ,- :s/^/--/<CR> map ,c :s/^//|^--|^> |^[#"%!;]//<CR> #" wrapping comments map ,* :s/^(.*)$//* 1 *//<CR> map ,( :s/^(.*)$/(* 1 *)/<CR> map ,< :s/^(.*)$/<!-- 1 -->/<CR> map ,d :s/^([/(]*|<!--) (.*) (*[/)]|-->)$/2/<CR>
set default editor in linux
#vi export EDITOR="vi" #nano export EDITOR="nano"
Create New Instance of FCKEditor
include("FCKeditor/fckeditor.php");
$oFCKeditor = new FCKeditor('description');
$oFCKeditor->BasePath = 'FCKeditor/';
$oFCKeditor->Value = $descripion;
$oFCKeditor->Height = 400;
$oFCKeditor->Create();
PHP File Editor
The original code was meant to be used with registerglobals=on. If you cannot or don’t want to turn that on, then I have modified the code to work with registerglobals=off.
<?php
$loadcontent = "test-edit.php";
if($_POST['save_file']) {
$savecontent = stripslashes($_POST['savecontent']);
$fp = @fopen($loadcontent, "w");
if ($fp) {
fwrite($fp, $savecontent);
fclose($fp);
print "<html><head><META http-equiv=\"refresh\" content=\"0;URL=$_SERVER[PHP_SELF]\"></head><body>";
}
}
$fp = @fopen($loadcontent, "r");
$loadcontent = fread($fp, filesize($loadcontent));
$lines = explode("\n", $loadcontent);
$count = count($lines);
$loadcontent = htmlspecialchars($loadcontent);
fclose($fp);
for ($a = 1; $a < $count+1; $a++) {
$line .= "$a\n";
}
?>
<p><font face="tahoma">Simply edit the page and hit save!</font></p>
<form method=post action="<?=$_SERVER[PHP_SELF]?>">
<input type="submit" name="save_file" value="Save"><br /><br />
<table width="100%" valign="top" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="3%" align="right" valign="top"><pre style="text-align: right; padding: 4px; overflow: auto; border: 0px groove; font-size: 12px; font-face:verdana;" name="lines" cols="4" rows="<?=$count+3;?>"><?=$line;?></pre></td>
<td width="97%" align="left" valign="top"><textarea style="text-align: left; padding: 0px; overflow: auto; border: 3px groove; font-size: 12px; font-face:verdana;" name="savecontent" cols="150" rows="<?=$count;?>" wrap="OFF"><?=$loadcontent?>