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

Creating bindings for certain modes and certain states #1771

Closed
geo7 opened this issue May 29, 2015 · 9 comments
Closed

Creating bindings for certain modes and certain states #1771

geo7 opened this issue May 29, 2015 · 9 comments
Labels

Comments

@geo7
Copy link
Contributor

geo7 commented May 29, 2015

It doesn't seem that theres anyway to have functionality like VIms after directory (or not an obvious one).

In vim, within ~/.vim/after/ftplugin/python.vim one could enter commands
which would only be active for python files.

" normal mode mapping
nnoremap gg dG
" insert mode mapping
inoremap j gg
" macros
let @s = "I'jfA'jfV:s: :', ':
,hlIsubprocess.call([jfA])jf"

Or whatever (probably something more sensible...)

Is there a way to get this behaviour from Evil / Spacemacs?

@syl20bnr
Copy link
Owner

This is called major-mode specific key bindings and they start with SPC m prefix or , which is a shortcut for it.

@syl20bnr
Copy link
Owner

For discoverability note that for now guide-key does not work with major-mode specific key bindings, you have to use SPC ? and enter SPC\ m to refine the search.
They should also be in the README file of the corresponding layer.

@geo7
Copy link
Contributor Author

geo7 commented May 29, 2015

@syl20bnr can you be explicit or point me to the right docs for this please?

As I'm reading that I can't map keys in the same way, I'm forced to use , or SPC m as a prefix.

TBH, using , as a major mode leader isn't a nightmare, I'm just trying to work out how this actually works....

Could one define a normal mode mapping just for python mode that had pp mapped to gg, or something trivial like that as an example?

@syl20bnr
Copy link
Owner

First you can choose the keys for the leaders: https://github.com/syl20bnr/spacemacs/blob/develop/core/templates/.spacemacs.template#L81-L94

Then you can set bindings for a specific mode using its key binding map:
In this case it is for C#

(evil-define-key 'normal omnisharp-mode-map (kbd "g R") 'omnisharp-rename)

Fore more info look at the code in spacemacs with SPC f e h and SPC /, this is the best source of example.

@geo7
Copy link
Contributor Author

geo7 commented May 29, 2015

This doesn't load for me @syl20bnr :

https://github.com/syl20bnr/spacemacs/blob/develop/elpa/omnisharp-20150505.1234/example-config-for-evil-mode.el#L11


(evil-define-key 'normal omnisharp-mode-map (kbd "g R") 'omnisharp-rename)

This example maps gR to omnisharp-rename in omnisharp-mode

so for python one would use

(evil-define-key 'normal python-mode-map (kbd "g R") 'python-check)

Not sure what python-check does, just for example


Thanks for the guidence though, I'll go through them

@syl20bnr
Copy link
Owner

This is because the map is not yet available, you have to defer the define with

(eval-after-load 'omnisharp
  `(evil-define-key 'normal omnisharp-mode-map (kbd "g R") 'omnisharp-rename))

With several expression you have to use a progn:

(eval-after-load 'omnisharp
  `(progn
      (evil-define-key 'normal omnisharp-mode-map (kbd "g R") 'omnisharp-rename)
      (evil-define-key 'normal omnisharp-mode-map (kbd "g R") 'omnisharp-rename)))

@geo7
Copy link
Contributor Author

geo7 commented May 29, 2015

when i said it didn't load I was referring to the hyperlink, I just got a 404 message from that.


I'm not finding this obvious from reading the .spacemacs file

@syl20bnr
Copy link
Owner

I forgot to remove the link :-)
You've got the idea now so you should be good to go.
For the leader keys we need a better documentation, right now it is documented but at different places.

@geo7
Copy link
Contributor Author

geo7 commented May 29, 2015

Oh right no worries :)

Yeah, I can have a play with what's here thanks

And yes I agree - I proposed here #1735 (comment) that there was a walk through of a basic .vimrc to .spacemacs conversion made. I think this would be really useful and cover many questions around this kind of thing. I know person808 has made a migration guide, perhaps integrating it to that would be the most appropriate place for it, or stand alone idk.

cheers though :)

@TheBB TheBB closed this as completed Aug 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants