Mac OS X iterm2: backward delete word - macos

I've been trying to customize a key shortcut to delete backspace entire word.
I've tried everything online and still this doesn't work.
I'm using iterm2, using Natural Text Editing keys preset and still - doing command + delete will delete the entire line, and doing option + delete will delete the last word up until a certain special character (this could be slash, hyphen, underscore, semicolon, etc...).
Doing control + W gives the same result as option + delete.
I do want the functionality of deleting backwards until a certain special character, but I would also like to be able to delete entire word (until space).

You may add corresponding keybinding to iterm2, or globally:
'Iterm2 preferences -> 'Keys' (or 'Profiles' -> 'Keys' - global | per-profile setting):
add desired keyboard shortcut (e.g. option + shift + backspace),
add Action - Under 'Send Keystrokes' select 'Send Hex Code' and type '0x17'

Related

How to delete whitespace backward in Xcode

I would like to use Xcode editor instead of others for swift typing but I am missing basic functionality of deleting whitespace backward.
Normally in the world of code editors, you just press option + backspace or something similar and thats it, it deletes whitespace just until next character starts, eating new line in the way as everyone needs.
But xCode is doing some wired unusable staff and is deleting not just whitespace and new line, but also part of text on previous line, until it considers some character start of word, basically making it unusable.
I don't need to know how to use "Delete subword backward" !
All key bindings can be edited in Xcode -> Preferences -> Key Bindings.
By default the combination you're interested in is assigned to something like Delete Subword Forward. Just remove the combination from the action that you don't need and add it to the action called Delete Forward (or whatever action you're looking for, it's not very clear).
To add a key binding you double click on existing Key value, click +, press Option+Backspace, click somewhere outside the field to save new value.

Mac Terminal Bug With [ Character After Changing Colors

I just changed my colors in ~/.bash_profile using:
export PS1="\[\033[1;96m\]\u\[\033[0;0m\]:\[\033[1;33m\]\W\[\033[1;0m\]$ "
The problem is, I see a strange character on the previous lines of the prompt:
(before "Pedro")
How can I fix this?
These “square bracket” indicators surrounding a line are called “marks”. These indicate that the line was marked as a “prompt line”. They are not characters, they are visual markers drawn in the margins of the terminal view.
Marks provide structure to the terminal contents, enabling you to navigate, select, copy, delete, etc. lines of text in the terminal. By default, Terminal automatically marks prompt/input lines when you type Return, enabling you to perform operations on command lines and their output.
Marks were added to Terminal in OS X 10.11 El Capitan.
See the menu items in the Edit menu—especially the Marks, Bookmarks, and Navigate submenus—for Mark-related commands.
For example:
Edit > Navigate > Jump to Previous/Next Mark ⌘↑/⌘↓ : navigate to the previous/next command line. Add the Shift ⇧ modifier to select text between marks.
Edit > Clear to Previous Mark ⌘L : delete the last command line and its output. This is context-sensitive and will clear the terminal content up to a mark selected via a Jump to… command, or to the start of the selection.
Edit > Select Marked Output ⇧⌘A : select the output of the last command (or between a selected mark and the next mark).
Note that many of the commands are designed to be used in combination, as well. For example, if you Select Marked Output then Clear to Start of Selection (⇧⌘A, ⌘L), it will delete the last command's output while leaving its command-line in place.
A Bookmark is a heavier-weight mark. Bookmarks are indicated with thick vertical lines in the view margins. The Edit > Bookmarks > Insert Bookmark ⇧⌘M command inserts a bookmarked line with the date and time (add the Option ⌥ modifier to customize the text). Many of the Mark-related commands operate on (or restrict themselves to) Bookmarks if you add the Option ⌥ modifier.
You can show or hide the visual mark indicators with View > Show/Hide Marks. All the Mark operations still work whether or not the indicators are displayed.

How to not get special characters in place of meta key combinations for VIM on OS X

On OS X, at any program, when I type option-p I get π, option-P I get ∏ and there's a bunch of alt/option bindings that just return greek and other special characters.
Is there a way to disable that?
Currently I'm using the Auto Pairs VIM plugin and it has the following default mappings:
<M-p> : Toggle Autopairs (g:AutoPairsShortcutToggle)
<M-e> : Fast Wrap (g:AutoPairsShortcutFastWrap)
<M-n> : Jump to next closed pair (g:AutoPairsShortcutJump)
<M-b> : BackInsert (g:AutoPairsShortcutBackInsert)
It seems I can't use these and other meta key based VIM mappings while this special input is turned on.
EDIT
From this cnet article, in truth I need to know how to disable that special input shown at the bottom of the page.
Use the macmeta setting: :set macmeta
From :help 'macmeta'
'macmeta' Use option (alt) as meta key. When on, option-key presses are not interpreted, thus enabling bindings to <M-..>. When off, option-key presses are interpreted by the selected input method and inserted as text.
Obviously this is a MacVim-only setting.
In Terminal.app Settings there's a setting for "Use option as meta key", under the Keyboard tab which disables e.g. Option-p printing π. You may need to start a new terminal window to see the effect. But for some reason even after disabling this I'm having trouble setting mappings for <M-p>, but mappings using Ctrl-v and inserting the character literally do work.
Well, it seems that with MacVim, in my .vimrc I can just map these special characters and it will work both at GUI and at Terminal.
Since they are generated by the corresponding meta key combinations, it'll look just as a meta key mapping.
EDIT
Some special characters are accents and it may not work well for them.
I've done this at my .vimrc:
if has("gui_macvim")
let g:AutoPairsShortcutToggle = 'π' " <m-p>
let g:AutoPairsShortcutFastWrap = '∑' " <m-w>
let g:AutoPairsShortcutJump = '∆' " <m-j>
let g:AutoPairsShortcutBackInsert = '∫' " <m-b>
endif
has("gui_macvim") is true both at GUI as at Terminal, when running MacVim.

How do you do the "therefore" (∴) symbol on a Mac or in Textmate?

Is there a way to write the ∴ therefore symbol with keyboard shortcuts in Textmate or just on a mac?
If you want to do this often, you can create a keybindings file in your Library to map it to a key combination.
In ~/Library create a directory named KeyBindings. Create a file named DefaultKeyBinding.dict inside the directory. You can add key bindings in this format:
{
"x" = (insertText:, "\U23CF");
"y" = (insertText:, "hi"); /* warning: this will change 'y' to 'hi'! */
}
The LHS is the key combination you'll hit to enter the character. You can use the following characters to indicate command keys:
# - Command
~ - Option
^ - Control
You'll need to look up the unicode for your character (in this case, ∴ is \U2234). So to type this character whenever you typed Control-M, you'd use
"^m" = (insertText:, "\U2234");
You can find more information here: http://www.hcs.harvard.edu/~jrus/site/cocoa-text.html
First you use a full stop, then you hold down alt and press the letter H and put in another full stop.
.˙.
From System Preferences, turn on the "Show Keyboard & Character Viewer in menu bar" setting.
Then, the "Character Viewer" menu will pop up a tool that will let you search for any unicode character (by name) and insert it ∴ you're all set.
If using WORD for mac
enable 'use maths autocorrect rules outside maths regions'
Type \therefore
If you are trying to insert the therefore symbol into a WORD DOCUMENT
Hold down the ALT key and type 8756
Hope the answer ur question
Regards Al~Hash.

Mac OS X Terminal: Map option+delete to "backward delete word"

Tried to map it from Preferences -> Settings -> Keyboard, but the "key" combo box has only "forward delete" but no "delete". My keyboard on the other hand has only "delete" and no "forward delete"!
Is there some other way to do it except from the preferences?
Enable option key as meta key
Go to Terminal > Preferences > Profiles > Keyboard
Check Use option key as meta key.
Image
On macOS High Sierra 10.13.6, captured on October 23, 2018.
Notes
Many applications (including bash and tcsh) treat Meta-Delete as "backward delete word."
OS X's terminal runs bash, which includes readline support. Follow Glomek's advice and tell terminal to use option as meta key (or else use Esc) and then you've got a bunch of handy options: Ctrl+w deletes prev word (as does Meta+delete as mentioned), but you can also use Meta+f and Meta+b to walk forward and backwards thru words, Ctrl+a and Ctrl+e to beginning and end of line, Ctrl+k delete (kill) from cursor to end of line, and a bunch more.
See http://www.bigsmoke.us/readline/shortcuts for a nice little reference table.
Delete a word going back:
Ctr-w.
Command Editing Shortcuts
Ctrl + a – go to the start of the command line
Ctrl + e – go to the end of the command line
Ctrl + k – delete from cursor to the end of the command line
Ctrl + u – delete from cursor to the start of the command line
Ctrl + w – delete from cursor to start of word (i.e. delete backwards one word)
Ctrl + y – paste word or text that was cut using one of the deletion shortcuts (such as the one above) after the cursor
Ctrl + xx – move between start of command line and current cursor position (and back again)
Alt + b – move backward one word (or go to start of word the cursor is currently on)
Alt + f – move forward one word (or go to end of word the cursor is currently on)
Alt + d – delete to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + c – capitalize to end of word starting at cursor (whole word if cursor is at the beginning of word)
Alt + u – make uppercase from cursor to end of word
Alt + l – make lowercase from cursor to end of word
Alt + t – swap current word with previous
Ctrl + f – move forward one character
Ctrl + b – move backward one character
Ctrl + d – delete character under the cursor
Ctrl + h – delete character before the cursor
Ctrl + t – swap character under cursor with the previous one
Command Recall Shortcuts
Ctrl + r – search the history backwards
Ctrl + g – escape from history searching mode
Ctrl + p – previous command in history (i.e. walk back through the command history)
Ctrl + n – next command in history (i.e. walk forward through the command history)
Alt + . – use the last word of the previous command
Command Control Shortcuts
Ctrl + l – clear the screen
Ctrl + s – stops the output to the screen (for long running verbose command)
Ctrl + q – allow output to the screen (if previously stopped using command above)
Ctrl + c – terminate the command
Ctrl + z – suspend/stop the command
Bash Bang (!) Commands
Bash also has some handy features that use the ! (bang) to allow you to do some funky stuff with bash commands.
!! – run last command
!blah – run the most recent command that starts with ‘blah’ (e.g. !ls)
!blah:p – print out the command that !blah would run (also adds it as the latest
command in the command history)
!$ – the last word of the previous command (same as Alt + .)
!$:p – print out the word that !$ would substitute
!* – the previous command except for the last word (e.g. if you type _find somefile.txt /, then !* would give you _find somefile.txt)
!*:p – print out what !* would substitute
⌃W (control+W) is not the same thing than meta + delete (ESC+delete if you don't have checked use option as meta key)
meta+delete will treat / _ as word delimiter where ^W will consider space as delimiter.
e.g.
using ESC+Bakcspace on (cursor at the end)
rm /dira/dirb/file1
gives
rm /dira/dirb/
while ^W on the same will give
rm
So it is better to use \033\177 rather than ^W when defining the modifying the terminal profile.
That way you are really mapping ⌥⌫ to what esc⌫ is doing and you keep having ^W to erase word based on space delimiter.
I would love to be able to post an image on how do this but as a newbies I can't.
refer to bouke comment to see how to modify terminal profile.
By default meta backspace does a backwards word yank in most shells. If you press escape and then press backspace, that pretty much works everywhere.
In your Terminal's profile, you can bind ⌥⌫ (option+delete) to ⌃W (control+W), so it works similar to other apps.
If you are using Iterm2 (which is like the regular terminal of OSX just better :)
you can use this like to change this behavior:
You need to set your left ⌥ key to act as an escape character. This can be done going to iTerm2 > Preferences > Profiles > Keys.
With Natural Text Editing preset enabled in Profile -> Keys.
You can simply remove the word
Backward with alt + delete
Forward with fn + alt + delete

Resources