-
-
Save ttscoff/1349738 to your computer and use it in GitHub Desktop.
// Add to (or create) ~/Library/KeyBindings/DefaultKeyBinding.dict | |
// Incorporated change by Lri to not require additional words on the line to work | |
// fixed to handle first character of list item being non-alphanumeric | |
// Issues: | |
// If there are more than one symbols ([[, ![, etc.) at the beginning of the line, anything beyond the first one is captured and added to new line | |
// FIXED: Entering more than one blank item in a row and then using ⌘Z leaves a placeholder character on the previous line. | |
{ | |
// Command Option Enter | |
// continue a list item with indentation and | |
// include the same delimiter as the current line | |
"~@\U000D" = ( breakUndoCoalescing, | |
moveToEndOfParagraph:, | |
insertText:, "x", | |
moveToBeginningOfParagraph:, | |
selectWord:, | |
moveRightAndModifySelection:, | |
moveWordForwardAndModifySelection:, | |
moveWordBackwardAndModifySelection:, | |
moveLeftAndModifySelection:, | |
setMark:, | |
deleteToMark:, | |
yank:, | |
moveToEndOfParagraph:, | |
deleteBackward:, | |
insertNewlineIgnoringFieldEditor:, | |
yank:, | |
insertText:, " ", | |
selectWord:, | |
insertText:, " "); | |
} |
This little part is my favorite:
insertText:, " ",
moveLeft:,
selectWord:,
insertText:, " "
Removes extra space that might show up after the intial character by padding it with a space and selecting word (which will grab all adjoining space) and then replacing the whole selection with a single space.
For more: http://brettterpstra.com/keybinding-madness/
I have about 30 more new ones. I'll be blogging a few more soon.
Lri, you're such a spoilsport sometimes. I messed around a lot with using placeholders to stop the selectWord from going too far, but always ran into problems. I'll give yours a shot in a bit, though. You're usually right :).
Yours doesn't work with numbered lines (1.), which is what took me so long to figure out. Seems like the placeholder works perfectly, though, so I'll try to blend the two.
I should specify: it doesn't work with indented numbered lists. If there's not whitespace, it's fine.
"~@\U000D" = (moveToEndOfParagraph:, insertText:, "x", moveToBeginningOfParagraph:, selectWord:, moveRightAndModifySelection:, moveWordForwardAndModifySelection:, moveWordBackwardAndModifySelection:, setMark:, deleteToMark:, yank:, moveToEndOfParagraph:, deleteBackward:, insertNewlineIgnoringFieldEditor:, yank:);
Fixed
Oh man, I just learned that breakUndoCoalescing works in keybindings. And you know where? From Lri.
P.S. the extra "x" problem is fixed now.
It looks messy, but it takes advantage of the quirks of word movement in OS X. Preserves indentation of the current list item and picks up the same delimiter (*,+,-,1.,etc.) and repeats it. Works for Markdown because if the first item is any number, it doesn't matter what the following items are. It just becomes an ordered list.
This keybinding works from anywhere in the line, selected text or no. It won't break the line, just starts a new item below it.