Home Download Buy Blog Forum Support

override the default key binding

override the default key binding

Postby vim on Mon Sep 28, 2009 9:36 am

i try to override the default key binding, on the user key binding, but i find that only changing the default helps.

for example: ctrl+c under Default/Default.sublime-keymap is:

Code: Select all
<binding key="ctrl+c" command="copy"/>


and i place under User/Default.sublime-keymap
Code: Select all
<binding key="ctrl+c" command="copy">
   <context name="allSelectionsEmpty" value="false"/>
</binding>


well, it doesn't work. only if i override the definition on Default/Default.sublime-keymap it works.
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: override the default key binding

Postby vim on Mon Sep 28, 2009 10:55 am

good tip nick, it will become handy i am sure, but now after trying this, i can better say what i want (if possible). i got used to the copy/paste when there is no selection in sublime - very useful actually for duplicating lines.

what i want to change is only when i use empty-selection on empty-line - i don't want it to get into the copy/paste buffer at all. so standing on a text line with no selection - i do want it to be copy/pasted, but standing on an empty line (i'll be greedy and say only with whitespace) won't affect the clipboard buffer (i.e. won't override previous item on clipboard), does it make any sense? any ideas?
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm

Re: override the default key binding

Postby jps on Mon Sep 28, 2009 11:11 am

Try:

Code: Select all
<binding key="ctrl+c" command="noop">
   <context name="allSelectionsEmpty" value="true"/>
   <context name="allPrecedingText" value="$^"/>
   <context name="allFollowingText" value="$^"/>
</binding>


This means the key binding will only run when the text before and after the selection, on the same line, matches the given regexes. This could easily be extended to not copy if the line consists of whitespace only, if desired.
jps
Site Admin
 
Posts: 3058
Joined: Wed Mar 19, 2008 12:33 pm

Re: override the default key binding

Postby vim on Mon Sep 28, 2009 11:43 am

great thanks!

Code: Select all
   <binding key="ctrl+c" command="noop">
      <context name="allSelectionsEmpty" value="true"/>
      <context name="allPrecedingText" value="^[\s]*$"/>
      <context name="allFollowingText" value="^[\s]*$"/>
   </binding>
   <binding key="ctrl+x" command="runMacroFileSilently 'Packages/User/DeleteLine.sublime-macro'">
      <context name="allSelectionsEmpty" value="true"/>
      <context name="allPrecedingText" value="^[\s]*$"/>
      <context name="allFollowingText" value="^[\s]*$"/>
   </binding>


and this macro at User/DeleteLine.sublime-macro:
Code: Select all
expandSelectionTo line
leftDeleteCharacters
vim
 
Posts: 298
Joined: Tue May 27, 2008 6:51 pm


Return to Technical Support

Who is online

Users browsing this forum: Yahoo [Bot] and 9 guests