void (final Variable oldVar, final Variable newVar) { ApplicationManager.getApplication().runWriteAction(() -> CommandProcessor.getInstance().executeCommand(null, () -> { Document document = myEditor.getDocument(); String templateText = document.getText(); templateText = templateText.replaceAll("\\$" + oldVar.getName() + "\\$", "\\$" + newVar.getName() + "\\$"); document.replaceString(0, document.getTextLength(), templateText); }, null, null)); }