TextMate - Find & Replace Selected Text - macos

In TextMate, does anyone know how you find & replace selected text?

Is this what you're looking for? http://manual.macromates.com/en/working_with_text
4.5.2 Find Clipboard
Two useful key equivalents are ⌘E and
⌘G. The first copies the selection to
the shared find clipboard. This works
in the majority of applications and
allows you to find the next occurrence
of that string by then pressing ⌘G.
The find clipboard works across
applications so whether in Safari,
TextEdit, Mail, TextMate, Terminal,
Console, or similar, one can copy the
selected text to the find clipboard,
switch application and use ⌘G to find
that string.
In addition TextMate offers ⇧⌘E to
copy the selection to the replace
clipboard. This is often useful to
save a trip to the find dialog, for
example if you want to replace
newlines with the pipe character (|)
for a list of items, select a newline,
press ⌘E to use that as the find
string. Now type a |, select it and
press ⇧⌘E so that it is copied to the
replace clipboard.
The next step is then to either press
⌃⌘F to perform the replacement in the
entire document, or select the range
in which you want the replacement to
occur and use ⌃⇧⌘F instead.

Related

How to insert/copy+paste unicode whitespace into a text file using editors like Textmate?

I am trying to create a test csv file for a file cleaning script that is supposed to normalize all whitespace into "normal"/ "regular" whitespace character. The idea is I will insert a bunch of these oddball whitespace characters into this test file in some various locations.
Here are some sites that show these various and oddball whitespaces
https://en.wikipedia.org/wiki/Whitespace_character
http://jkorpela.fi/chars/spaces.html
I've tried to copy and paste from sources like that website but it seems like they always paste in as a normal space in Textmate. It could be that I am not copying what I think I am copying. In the past I've been able to copy and paste into Textmate special / unicode characters when I can clearly see what I am copying but with whitespace characters, I can't confirm since I can can't see it, so I am not sure if the problem is where I am copying from or that Textmate is converting it to the normal space when I paste it in.
If it is easier to use Textedit (the built in editor) or nano (command line editor) to do this I could use those. Or if there is another way other than copying and pasting that is better to get these into Textmate that would be an option.
I am on a MacbookPro running High Sierra MacOS.
If you have LibreOffice installed you can use the spreadsheet application to create these using their hexidecimal equivalent in 1 cell then doing a conversion using
=unichar(hex2dec(cell_ref_to_1rst_cell)).
Far less confusing and you can save the spreadsheet complete with comments as a handy reference. Then you should just be able to copy paste the cell with the unicode character when required.
If you’re using TextMate, various functions provided by the Unicode bundle could be helpful here (install via Preferences → Bundles → Unicode).
With this bundle installed you can use Insert Unicode Character ⌃⌥⌘I to insert a character by name. Search for “space” to get a list of all space characters, then simply click on the desired character (the full title of a character is shown on hover):
Of course once inserted all the space characters look almost identical. To identify them, use Show Unicode Name(s) ⌃⌥⌘U 6. This will display a tooltip showing the unicode of name of the character directly before the cursor (or the names of all selected characters, if a selection is active).
Also have a look at Show Character Inventory (press ⌃⌥⌘U and then select the command from the popup menu): This provides a convenient overview of all the characters in your document (or in the selected text, if a selection is active).

Remove spaces from a string of text in clipboard

This is maybe a weird request but hear me out:
I have a huge database at my shop containing product codes, like 87 445 G 6 which I need to check for availability on a supplier's website. The problem is, the supplier's website consists of a web form in which I have to enter the code without spaces, so imagine that I have to manually delete spaces every time I paste a code or write it manually without.
I can't edit the database from which I copy the codes.
I wonder if some sort of plugin, script, or trick can be used directly in browser on the supplier's web form, or some software to modify how the windows clipboard works, maybe some option to copy text without spaces. Using Windows XP.
The OP has probably moved on, but for anyone else looking here, my approach was to tackle this from the windows clipboard side.
For background: I keep a list of my credit card info in Keepass. Sometimes (poorly coded) shopping cart checkout forms don't like spaces in between card numbers. I like storing them with spaces since it's easier to read off that way.
There's various Windows clipboard utilites out there, but it took me a while to find one that could do some processing on the clipboard contents and pasting it out - Clipboard Help and Spell
The program has a way to "save" a bunch of text transformations, and even assign the action to a hotkey.
For reference, my "Find and Replace" action is to find "\s" (without quotes) and leave the Replace textbox empty. "\s" will match whitespace character.
Use the javascript console
You could use the javascript console for your browser to edit the textarea after you paste.
Using Google Chrome (or Firefox)
Paste your text in the text area.
Right click the text area and click Inspect Element
Look at the id for the element
Now switch to the console view
then run these lines (making sure to replace with 'the-id' with your id)
var my_text_area = document.getElementById('the-id'); // Put your id in here
my_text_area.value = my_text_area.value.replace(/ /g,"") // Deletes just spaces
It's even simpler if you have access to jQuery:
$('#the-id').val($('#the-id').val().replace(/ /g, ""))
The replace function is simply using regular expressions to convert spaces to nothing. If you want to replace all whitespace (including newlines) you would use .replace(/\s/g,"").
For firefox, the names are the same but the UI is a little bit different.
Use greasemonkey
You can either write a greasemonkey plugin or try to find one that fits your needs.

Are these NotePad++ features available in TextMate?

I'm a NotePad++ user, new to TextMate.
There are some features that I really like in NP++ but couldn't figure out if TextMate support them.
Double click on a variable and have all instances highlighted
View 2 text windows side by side
Drag a file onto another opened Window
For this one, I don't know how to generate a screenshot ;-p. Basically, you can drag a file from Windows Explorer and drop it into NP++ to have it opened.
A lot of long time TextMate users are leaving TextMate land, actually. So, I'm not sure it's the right time to move to TextMate.
Emacs and Vim both do what you want and more. If you can afford the learning curve it's definitely worth it.
As for your question:
View 2 text windows side by side
You can have two or more windows for the same document. Assuming you are in a "project" right-click your file in the drawer and choose Open "foo.ext" in New Window. The two "views" contents are more or less in sync but doing cool things like columnar editing tends to break the syncing.
Due to how Mac OS X manages windows, the new window will probably be too large/too small and/or placed in a less than useful place. I use ShiftIt system wide to manage my windows and in such a case have them the same size side by side.
Double click on a variable and have all instances highlighted
What do you use this for? Is this visual highlight or non-contiguous selection?
Type ctrlw to select the word, then ⌘e to make the word your search term, then ⇧⌘f or Edit > Find > Find in Project… It will show all instances of the search term in another window. You can then "jump" to any occurence and do whatever you want.
If you only want to jump from occurence to occurence, select the word then type ⌘e then ⌘g to jump to the next occurence.
Another way is to type ctrls, a little text field appears at the bottom of your window where you can type a word and see its first occurence selected in real time. Repeatly typing ctrls will cycle through the occurences.
Drag a file onto another opened Window
You can drag & drop a file on TextMate's icon in the Dock. You can also right-click the file and choose Open with TextMate *or Open with…*. If you are in a "project" you can right-click and choose Add Existing Files…. Opening multiple files in TextMate will automatically create a "project" for you.
View 2 text windows side by side
I just tried this and it doesn't seem to recognize this functionality. the only time any sort of "add" icon came up was when I dragged the file into an open document and then released, but that resulted in adding the contents of the file into the document.
I just did a quick google search for "textmate split view" and it still doesn't seem to be supported according to some of the answers i found (one from macromates wiki).
Double click on a variable and have all instances highlighted
This also doesn't seem to be supported. This post suggests using the command + f (find), put the word into find, then command + g to jump to the next instance of that word.
There are definitely some things that can be added to textmate to make it more robust. If you are looking for something similar and are on a windows machine, you should check out e text editor. I loved that editor when I was working on a windows machine - split view is supported, but not sure about the highlighting. One thing that e also beats out textmate is the real time regular expression highlighting.

Conventions for the behavior of double or triple "click to select text" features?

Almost any mature program that involves text implements "double click to select the word" and, in some cases, "triple click to select additional stuff like an entire line" as a feature. I find these features useful but they are often inconsistent between programs.
Example - some programs' double clicks do not select the ending space after a word, but most do. Some recognize the - character as the end of a word, others do not. SO likes to select the entire paragraph as I write this post when I triple click it, VS web developer 2005 has no triple click support, and ultra-edit 32 will select one line upon triple clicking. We could come up with innumerable inconsistencies about how double and triple click pattern matching is implemented across programs.
I am concerned about how to implement this behavior in my program if nobody else has achieved a convention about how the pattern matching should work.
My question is, does a convention (conventions? maybe an MS or Linux convention?) exist that dictates how these features are supposed to behave to the end user? What, if any, are they?
I don’t believe there is a standard to the level of specification you want, and there probably shouldn’t be. Apple Human Interface Guidelines are the most complete. With respect to selecting content (as opposed to controls or discrete data objects), they say:
Double-clicking is most commonly used as a shortcut for other actions, such as… to select a word. Triple-clicking selects the next logical unit, as defined by the application. In a word-processing document, triple-clicking in a word selects the paragraph containing the word…. Double-clicking within a word selects the word. The selection should provide “smart” behavior; if the user deletes the selected word, for example, the space after the word should also be deleted… In some contexts—in a programming language, for example—it may be appropriate to allow users to select both the left and right parentheses (or braces or brackets) in a pair, as well as all the characters between them, by double-clicking either one of them.” (p115-116)
Apple is quite specific about what characters are and aren’t included in a word.
Microsoft’s Windows User Interaction Experience Guidelines say:
For some types of selectable objects, each click expands the effect of the click. For example, single-clicking in a text box sets the input location, double-clicking selects a word, and triple-clicking selects a sentence or paragraph. (p430)
Java Swing Look and Feel Design Guidelines say:
Double-clicking (clicking a mouse button twice in rapid succession without moving the mouse) is used to select larger units (for example, to select a word in a text field)…. Triple-clicking (clicking a mouse button three times in rapid succession without moving the mouse) is used to select even larger units (for instance, to select an entire line in a text field)…. A triple click in a line of text deselects any existing selection and selects the line.
The Gnome Human Interface Guidelines don’t say much about what double- and triple-clicking should do.
This gives you the freedom to choose whatever is best for your users. Double and tripling clicking are expert shortcuts, so their behavior should aim to maximize efficiency. Consider why the user is selecting something and design to make that easiest and fastest.
For example, apparently the rationale behind including the trailing space when double-clicking a word is that users usually select a word in order to copy or paste it in another position in the text. This implies you automatically include the trailing space in order keep the user from having to manually delete a remaining extra space at the source and add a word-separating space at the destination.
Likewise if users are selecting a line of code or paragraph to copy or move it somewhere else, then you probably want to include the newline characters so the user isn’t left with an empty line at the source and force to manually add a newline at the destination (assuming they didn’t want to take the line/paragraph and combine it with another line/paragraph.
If selection is for something other than copying and moving text in sentences, then none of this may apply and you don’t necessarily want to include trailing spaces or newlines. That’s why there shouldn’t be a standard.
An alternative is to do what Apple calls Intelligent Cut and Paste (see the Human Interface Guidelines), or Microsoft Word’s Smart Cut and Paste, where spaces, newlines and other adjustment are algorithmically figured out when cutting, copying, pasting, and deleting, not when selecting.
In my perfect world I would have it work like this.
Double click on a word selects the word only (a word according to the grammar rules of the locale), no trailing space (this is for easier copying between programs so that I would not need to remove any spaces when pasting)
If I remove the selected word my text editor is aware of my content and removes any additional spaces left over
A triple click selects a line with no trailing newlines. (A paragraph is a long line that has been wrapped)
In Windows, Linux and OS X double-click selects the word under cursor triple-click selects the entire line of text (single line only, i.e., wrapped line)
Finding answers and come up with a alternative solution:
I like to write code or command in text, and copy them to shell prompt without the ending \n
1. use notepad
2. surround each line with ()
3. use ctrl + double click.
Fine...

Fastest way to "jump back" to a file in TextMate?

Often, when I am reading code or debugging, I want the ability to quickly jump around files. I especially want to "go back" to where I was. I know about "Command+T", "Command+Shift+T", and, bookmarks. But, I cannot figure out a way to jump around files quickly.
UPDATE: I do not think I my question was clear enough judging by two answers given. Specifically, I am looking for a way to "jump back" to where I was in a file. I know how to navigate in TextMate (in general). I want to know if TextMate has a "jump back" key binding.
It's subtle.
The command-T thing has the files listed in Most Recently Used order.
So, you can go command-T return to get back to your last file real quick. At first I couldn't find it either.
I don't think there's a go to last edit location as there is in, say, IDEA/RubyMine.
Courtesy of MacroMates.com
2.3 Moving Between Files (With Grace)
When working with projects there are a few ways to move between the open files.
The most straightforward way is by clicking on the file tab you need. This can also be done from the keyboard by pressing ⌘1-9, which will switch to file tab 1-9.
You can also use ⌥⌘← and ⌥⌘→ to select the file tab to the left or right of the current one.
It is possible to re-arrange the file tabs by using the mouse to drag-sort them (click and hold the mouse button on a tab and then drag it to the new location). This should make it possible to arrange them so that keyboard switching is more natural.
One more key is ⌥⌘↑ which cycles through text files with the same base name as the current file. This is mainly useful when working with languages which have an interface file (header) and implementation file (source).
When you want to move to a file which is not open you can use the Go to File… action in the Navigation menu (bound to ⌘T). This opens a window like the one shown below.
Go To File
This window lists all text files in the project sorted by last use, which means pressing return will open (or go to) the last file you worked on. So using it this way makes for easy switching to the most recently used file.
You can enter a filter string to narrow down the number of files shown. This filter string is matched against the filenames as an abbreviation and the files are sorted according to how well they match the given abbreviation. For example in the picture above the filter string is otv and TextMate determines that OakTextView.h is the best match for that (by placing it at the top).
The file I want is OakTextView.mm which ranks as #2. But since I have already corrected it in the past, TextMate has learned that this is the match that should go together with the otv filter string, i.e. it is adaptive and learns from your usage patterns.
If you have a project window open, you can leave frequently-accessed files open (in tabs), and then use ⌘+1-9 to jump to open tabs.

Resources