compare to text selections in gedit - text

I'm using gedit. I have multiple tabs open, some are simply text that I have copied from other tabs, and haven't been saved to any file.
Is there a way to compare text that is selected in one tab to text selected in another tab? I know that I can use meld, diffuse, diff, etc., but those (afaik) require the selections to be saved to files first.
I remember using an editor (maybe emacs?) many years ago that could do something similar. But now I almost exclusively use gedit for text file editing.
Any ideas anyone?
TIA
ken

Okay, got a pointer from google:
In gedit, I created a new external tool that will run diff with the clipboard contents against the currently selected text.
Here's the bash code for the tool:
#!/bin/bash
SEL=$(cat)
diff -B <(echo -en "$SEL") <(xclip -selection c -o)
Note that this requires xclip, which is in most linux's repos. Sorry, don't know about Windoze.

Related

How to add dictionary words for auto-completion in TextMate 2?

TextMate's Esc auto-complete is great, but it's limited by default to words only in the current document when using the Plain Text grammar. Is it possible to add standard dictionary words to this? E.g., auto-complete to "dictionary" when I press Esc after "dict"?
The old manual references completions as "an array of additional candidates when cycling through completion candidates from the current document." But I don't see how to set this up in the Plain Text bundle settings, and no references to this online. Using 2.0-beta.8.5.
You could use the Avian Missing TextMate2 Bundle to gain access to the "Auto-complete Across Current Tabs" command.
You could then make and keep your_dictionary.txt open in a tab, and just add the words you wish TextMate had to that file.
Although I haven't tested this, it stands to reason that if you opened "Auto-complete Across Current Tabs" in the bundle editor, made a copy, and change line 11:
open_files = `lsof +D "#{project_dir}" -a -c TextMate -Fn`.split("\n").map do |line|
to
open_files = `cat ~/your_dictonary.txt" -a -c TextMate -Fn`.split("\n").map do |line|
Then the script search that file even when it wasn't opened in a tab.
IMHO: I don't think expanding this list to include every word is going to be a good idea. That's basically spell check's job.

Where is the clipboard data stored in bash?

In bash, I can type Ctrl+u it "cuts" text behind my cursor.
Then when I press Ctrl+y it pastes the text back.
Is there a file where the cut text is stored?
The "clipboard" -- actually called the kill ring -- is implemented by the readline library. It is not persistent, so it is not saved in a file.
There are lots of keystroke commands for "kill"ing and "yank"ing text, which are described in the bash manual:
Killing text means to delete the text from the line, but to save it away for later use, usually by yanking (re-inserting) it back into the line. (‘Cut’ and ‘paste’ are more recent jargon for ‘kill’ and ‘yank’.)
More complete documentation is in this section of the manual.
xsel can copy and paste to three different "clipboards". By default, it uses the X Window System primary selection, which is basically whatever is currently in selection. The X Window System also has a secondary selection (which isn't used much), and a clipboard selection. You're probably looking for the clipboard selection, since that's what the desktop environment (e.g. Gnome, KDE, XFCE) uses for its clipboard. To use that with xsel:
xsel --clipboard < new-clipboard-contents.txt
xsel --clipboard > current-clipboard-contents.txt
or use this link

How do I make commands like cat and less keep tab characters?

Is there a way to make cat, less etc. print tab characters instead of tabs being converted to spaces? I am annoyed by this when I copy code from the terminal to an editor.
I am seeing two problems here.
First, destination editor can covert TAB to number of spaces. Some
editor has default feature to convert TAB to number of spaces. If
you disable this feature TAB character you copied from terminal will
be copied as TAB(instead of space) to an editor.
Windows Notepad++ has similar feature
. If you are using vim, this page will be helpful for
vim tab and space conversion
Another, source file in your case terminal may be representing tab
as spaces, please check that first. You can use cat -t filename to
see if you have any TAB in source file or not. That command will
display TAB character as ^I.
It seems this is not possible with less (see answer to the same question on unix.stackexchange).
As a workaround, it works with cat or, for some minimal paging capabilities, with the more command.

run perl script on file I'm editing with vim (macvim)

I have been using bluefish to edit text that are to be published in html. Bluefish has an external filter function that allows me to call on scripts that I have written in perl to "filter" the text I am editing and format them basically using regex.
Having started exploring vim and macvim, I find the program to be very powerful and worth learning. I just would like to be able to use those scripts I already have without having to rewrite them as vim plugins. I have spent the past 2 hours searching but answers seem to be only for running perl as an external command or incorporating perl inside vim scripts.
Just to be clear: I want to get perl scripts I already have to act on text that I am presently editing inside vim/macvim, either the whole text or (better) selected text only.
You can use
:%!command
for example
:%!sort
to sort the whole file being edited.
If you have a range selected it will be added automatically and you complete the command
:'<,'>!command

Opening default text editor in Bash?

I was writing a shell script and ran into a problem: Is there a way to open a file using the user's specified text editor?
The user's chosen editor should be in $EDITOR, but you must still choose a sane default.
"${EDITOR:-vi}" file.txt
Ignacio's right (though arguably, the fallback should be ed, which POSIX requires to be present, although it's essentially only useful to old-timers).
If you're thinking about graphical editors, xdg-open file.txt is what you're after.
note: xdg-open file.xml will open in a Web-Browser, most likely.
So, try;
# select your default sensible-editor from all installed editors, or not.
select-editor
# Open Default Text Editor
sensible-editor file.xml

Resources