Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<C-w><key> bind not working #67

Closed
yarinm opened this issue Dec 20, 2021 · 7 comments
Closed

<C-w><key> bind not working #67

yarinm opened this issue Dec 20, 2021 · 7 comments

Comments

@yarinm
Copy link

yarinm commented Dec 20, 2021

I'm trying to bind the following:

exmap focusleft :obcommand editor:focus-left
nmap <C-w>h :focusleft

But when I'm doing ctrl+w, h nothing happens.

If I change the bind from C-w to or some other key that doesn't involve the control key it seems to work.

@yarinm
Copy link
Author

yarinm commented Dec 24, 2021

@esm7 any idea why it doesn't work? This specific combination just being ignored

@pBorak
Copy link

pBorak commented Dec 25, 2021

@yarinm There was a similar thread related to this issue #17

@twio142
Copy link
Contributor

twio142 commented Jan 2, 2022

Hi, are you sure the command :obcommand editor:focus-left works? Nothing happens when I enter it...

@esm7
Copy link
Owner

esm7 commented Jan 2, 2022

@twio142 it's probably among the many things that broke in the new editor switch and I was unable to get to fix yet.
I'll work on as many of them this week, but can you open a separate issue so this won't get lost?

@esm7
Copy link
Owner

esm7 commented Jan 2, 2022

@yarinm please see #17 as pBorak mentioned. Unfortunately it's a CodeMirror limitation that's beyond the reach of this plugin, and you'll to work around it by choosing combinations that do happen to work or just choose other keys :(

@esm7 esm7 closed this as completed Jan 2, 2022
@pmbauer
Copy link

pmbauer commented Mar 10, 2022

I've no idea if upstream will accept a patch but ... not having <C-w> commands has been a bit of a drag. So here is my hack (works on Mac OS, will need modified for other platforms).

Execute this abomination (bash shell, will need npm installed)

MAIN_ASAR=/Applications/Obsidian.app/Contents/Resources/obsidian.asar
CACHE_DIR="/Users/$USER/Library/Application Support/obsidian"
TARGET_ASAR=$((ls -r "$CACHE_DIR"/obsidian-*.asar 2>/dev/null || echo "$MAIN_ASAR") | head -n 1)
TMP_ASAR=/tmp/obsidian.asar
UNPACKED_ASAR=/tmp/obsidian.asar.unpacked
TARGET_VIMJS=$UNPACKED_ASAR/lib/codemirror/vim.js

# cleanup
rm -rf $TMP_ASAR $UNPACKED_ASAR

npx asar extract "$TARGET_ASAR" /tmp/obsidian.asar.unpacked

# DOS->unix
sed -i s/$'\r'$// $TARGET_VIMJS

cat <<EOF | patch -r /dev/null -N $TARGET_VIMJS || true
--- vim.js	2022-03-10 00:54:21.000000000 -0500
+++ vim.patched.js	2022-03-10 01:02:05.000000000 -0500
@@ -183,7 +183,7 @@
     { keys: '<C-u>', type: 'operatorMotion', operator: 'delete', motion: 'moveToStartOfLine', context: 'insert' },
     { keys: '<C-w>', type: 'operatorMotion', operator: 'delete', motion: 'moveByWords', motionArgs: { forward: false, wordEnd: false }, context: 'insert' },
     //ignore C-w in normal mode
-    { keys: '<C-w>', type: 'idle', context: 'normal' },
+    //{ keys: '<C-w>', type: 'idle', context: 'normal' },
     // Actions
     { keys: '<C-i>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: true }},
     { keys: '<C-o>', type: 'action', action: 'jumpListWalk', actionArgs: { forward: false }},
EOF

npx asar pack $UNPACKED_ASAR $TMP_ASAR

# replace with patched asar
pkill Obsidian
cp $TMP_ASAR "$TARGET_ASAR"

And then in my .obsidian.vimrc

exmap focusRight obcommand editor:focus-right
nmap <C-w>l :focusRight

exmap focusLeft obcommand editor:focus-left
nmap <C-w>h :focusLeft

exmap focusTop obcommand editor:focus-top
nmap <C-w>k :focusTop

exmap focusBottom obcommand editor:focus-bottom
nmap <C-w>j :focusBottom

exmap splitVertical obcommand workspace:split-vertical
nmap <C-w>v :splitVertical

exmap splitHorizontal obcommand workspace:split-horizontal
nmap <C-w>s :splitHorizontal

@pmbauer
Copy link

pmbauer commented Mar 14, 2022

@esm7 @yarinm FYI

[!INFO]
As of [[2022-03-14]], release 0.14.0, this hack is no longer needed. [[licat]] modified the included vim.js so C-w leader shortcuts are supported natively.

To enable vim-native C-w window manipulation.

  1. Make sure the Ctrl-W hotkey is removed for Open Settings / Hotkeys > Close active pane
  2. Install the obsidian-vimrc-support plugin.
  3. Add the following to <VAULT_ROOT>/.obsidian.vimrc
" window controls
exmap wq obcommand workspace:close
exmap q obcommand workspace:close

exmap focusRight obcommand editor:focus-right
nmap <C-w>l :focusRight

exmap focusLeft obcommand editor:focus-left
nmap <C-w>h :focusLeft

exmap focusTop obcommand editor:focus-top
nmap <C-w>k :focusTop

exmap focusBottom obcommand editor:focus-bottom
nmap <C-w>j :focusBottom

exmap splitVertical obcommand workspace:split-vertical
nmap <C-w>v :splitVertical

exmap splitHorizontal obcommand workspace:split-horizontal
nmap <C-w>s :splitHorizontal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants