Skip to content

Commit

Permalink
restore vim line motion and add ~p yank commands
Browse files Browse the repository at this point in the history
- Restore hjkl paragraph motion commands
- Add yank versions of the paste before/after commands
- Make outdent commands only outdent the first character, rather than first word, preserving non-alphanumeric prefixes
  • Loading branch information
ttscoff committed Dec 21, 2023
1 parent 10fe60f commit 5059fb9
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 15 deletions.
30 changes: 18 additions & 12 deletions DefaultKeyBinding.dict
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Set a binding for repeating action (e.g.: opt-r, 5, right arrow)
// $ defaults write -g NSRepeatCountBinding -string "\~r"

// $ defaults write -g NSRepeatCountBinding -string "~r"
{
// General
// > defaults write -g NSTextKillRingSize -int 6
// replace yank: command with yankAndSelect for use with the kill ring
"^y" = (yankAndSelect:);
// Regular yank, only insert last register and don't select
"^~y" = (yank:);
// Uppercase word
"^U" = (uppercaseWord:, moveWordForward:, moveWordBackward:);
// Lowercase word
Expand Down Expand Up @@ -34,14 +35,20 @@
"^~S" = (moveToEndOfParagraph:, insertText:, " ", selectWord:, moveBackward:, moveToBeginningOfParagraphAndModifySelection:, moveWordForwardAndModifySelection:, moveWordBackwardAndModifySelection:);
// delete line/paragraph
"~d" = (selectParagraph:, delete:, moveToBeginningOfParagraph:);
// delete to beginning of paragraph (if this isn't already defined?)
"^u" = (deleteToBeginningOfParagraph:);
// copy paragraph
"~y" = (setMark:, moveToBeginningOfParagraph:, moveToEndOfParagraphAndModifySelection:, copy:, swapWithMark:);
// cut paragraph
"~x" = (moveToBeginningOfParagraph:, moveToEndOfParagraphAndModifySelection:, cut:);
// paste paragraph below
"~p" = (moveToEndOfParagraph:,moveRight:,insertNewline:,moveLeft:, paste:);
// yank (from kill ring) paragraph below
"^~p" = (moveToEndOfParagraph:,moveRight:,insertNewline:,moveLeft:, yank:);
// paste paragraph above
"~P" = (moveToBeginningOfParagraph:, moveLeft:, paste:);
// yank (from kill ring) paragraph above
"^~P" = (moveToBeginningOfParagraph:, moveLeft:, yank:);
// select to beginning of paragraph and copy
"^A" = (moveToBeginningOfParagraphAndModifySelection:, copy:);
// select to end of paragraph and copy
Expand All @@ -56,15 +63,14 @@
// blank line before current
"~O" = (moveToBeginningOfParagraph:, moveLeft:, insertNewline:);


// // move line up
// "^@k" = (selectParagraph:, setMark:, deleteToMark:, moveLeft:, moveToBeginningOfParagraph:, yank:, moveLeft:, selectToMark:, moveLeft:);
// // move line down
// "^@j" = (selectParagraph:, setMark:, deleteToMark:, moveToEndOfParagraph:, moveRight:, setMark:, yank:, moveLeft:, selectToMark:);
// // indent line
// "^@l" = (setMark:, moveToBeginningOfParagraph:, insertText:, "\t", swapWithMark:, moveRight:);
// // outdent line (one tab or char)
// "^@h" = (setMark:, moveToBeginningOfParagraph:, moveWordRight:, moveWordLeft:, deleteBackward:, swapWithMark:, moveLeft:);
// move line up
"^@k" = (selectParagraph:, setMark:, deleteToMark:, moveLeft:, moveToBeginningOfParagraph:, yank:, moveLeft:, selectToMark:, moveLeft:);
// move line down
"^@j" = (selectParagraph:, setMark:, deleteToMark:, moveToEndOfParagraph:, moveRight:, setMark:, yank:, moveLeft:, selectToMark:);
// indent line
"^@l" = (setMark:, moveToBeginningOfParagraph:, insertText:, "\t", swapWithMark:, moveRight:);
// outdent line (one tab or char)
"^@h" = (setMark:, moveToBeginningOfParagraph:, moveRight:, deleteBackward:, swapWithMark:, moveLeft:);

// > same commands but with arrow keys
// move line up
Expand All @@ -74,7 +80,7 @@
// indent line
"^@\UF703" = (setMark:, moveToBeginningOfParagraph:, insertText:, "\t", swapWithMark:, moveRight:);
// outdent line (one tab or char)
"^@\UF702" = (setMark:, moveToBeginningOfParagraph:, moveWordRight:, moveWordLeft:, deleteBackward:, swapWithMark:, moveLeft:);
"^@\UF702" = (setMark:, moveToBeginningOfParagraph:, moveRight:, deleteBackward:, swapWithMark:, moveLeft:);

// > Control-shift-command-left arrow
// Full outdent - Deletes all leading space of line/paragraph (updated)
Expand Down
36 changes: 34 additions & 2 deletions keybindings.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ project_tag: keybindings
icon: /images/projecticons/keybindings.png
info: My OS X KeyBindings experiments.
ranking: 5
updated: 2023-12-19
updated: 2023-12-21
tags:
- mac
- utilities
Expand All @@ -29,7 +29,7 @@ effect --- or log out and log back in.
The repository includes a script to generate a Dash docset from your customized version of the file.
[See here for details.](https://brettterpstra.com/2022/02/18/keybindings-cheat-sheet-for-dash/)

**Documentation** _(last updated 12/19/2023.)_
**Documentation** _(last updated 12/21/2023.)_

*Grouped items begin with the groups shortcut (if exists), followed by a subgroup (if exists) followed by the keys specified.*

Expand All @@ -54,6 +54,10 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌃y</td>
<td style="text-align:left;">Replace yank: command with yankAndSelect for use with the kill ring (defaults write -g NSTextKillRingSize -int 6)</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌥y</td>
<td style="text-align:left;">Regular yank, only insert last register and don&#8217;t select</td>
</tr>
<tr>
<td style="text-align:center;">⌃⇧u</td>
<td style="text-align:left;">Uppercase word</td>
Expand Down Expand Up @@ -102,6 +106,10 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌥d</td>
<td style="text-align:left;">Delete line/paragraph</td>
</tr>
<tr>
<td style="text-align:center;">⌃u</td>
<td style="text-align:left;">Delete to beginning of paragraph (if this isn&#8217;t already defined?)</td>
</tr>
<tr>
<td style="text-align:center;">⌥y</td>
<td style="text-align:left;">Copy paragraph</td>
Expand All @@ -114,10 +122,18 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌥p</td>
<td style="text-align:left;">Paste paragraph below</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌥p</td>
<td style="text-align:left;">Yank (from kill ring) paragraph below</td>
</tr>
<tr>
<td style="text-align:center;">⌥⇧p</td>
<td style="text-align:left;">Paste paragraph above</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌥⇧p</td>
<td style="text-align:left;">Yank (from kill ring) paragraph above</td>
</tr>
<tr>
<td style="text-align:center;">⌃⇧a</td>
<td style="text-align:left;">Select to beginning of paragraph and copy</td>
Expand All @@ -142,6 +158,22 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌥⇧o</td>
<td style="text-align:left;">Blank line before current</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘k</td>
<td style="text-align:left;">Move line up</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘j</td>
<td style="text-align:left;">Move line down</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘l</td>
<td style="text-align:left;">Indent line</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘h</td>
<td style="text-align:left;">Outdent line (one tab or char)</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘↑</td>
<td style="text-align:left;">Move line up (same commands but with arrow keys)</td>
Expand Down
34 changes: 33 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ effect --- or log out and log back in.
The repository includes a script to generate a Dash docset from your customized version of the file.
[See here for details.](https://brettterpstra.com/2022/02/18/keybindings-cheat-sheet-for-dash/)

**Documentation** _(last updated 12/19/2023.)_
**Documentation** _(last updated 12/21/2023.)_

*Grouped items begin with the groups shortcut (if exists), followed by a subgroup (if exists) followed by the keys specified.*

Expand All @@ -34,6 +34,10 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌃y</td>
<td style="text-align:left;">Replace yank: command with yankAndSelect for use with the kill ring (defaults write -g NSTextKillRingSize -int 6)</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌥y</td>
<td style="text-align:left;">Regular yank, only insert last register and don&#8217;t select</td>
</tr>
<tr>
<td style="text-align:center;">⌃⇧u</td>
<td style="text-align:left;">Uppercase word</td>
Expand Down Expand Up @@ -82,6 +86,10 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌥d</td>
<td style="text-align:left;">Delete line/paragraph</td>
</tr>
<tr>
<td style="text-align:center;">⌃u</td>
<td style="text-align:left;">Delete to beginning of paragraph (if this isn&#8217;t already defined?)</td>
</tr>
<tr>
<td style="text-align:center;">⌥y</td>
<td style="text-align:left;">Copy paragraph</td>
Expand All @@ -94,10 +102,18 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌥p</td>
<td style="text-align:left;">Paste paragraph below</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌥p</td>
<td style="text-align:left;">Yank (from kill ring) paragraph below</td>
</tr>
<tr>
<td style="text-align:center;">⌥⇧p</td>
<td style="text-align:left;">Paste paragraph above</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌥⇧p</td>
<td style="text-align:left;">Yank (from kill ring) paragraph above</td>
</tr>
<tr>
<td style="text-align:center;">⌃⇧a</td>
<td style="text-align:left;">Select to beginning of paragraph and copy</td>
Expand All @@ -122,6 +138,22 @@ The repository includes a script to generate a Dash docset from your customized
<td style="text-align:center;">⌥⇧o</td>
<td style="text-align:left;">Blank line before current</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘k</td>
<td style="text-align:left;">Move line up</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘j</td>
<td style="text-align:left;">Move line down</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘l</td>
<td style="text-align:left;">Indent line</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘h</td>
<td style="text-align:left;">Outdent line (one tab or char)</td>
</tr>
<tr>
<td style="text-align:center;">⌃⌘↑</td>
<td style="text-align:left;">Move line up (same commands but with arrow keys)</td>
Expand Down

0 comments on commit 5059fb9

Please sign in to comment.