6

I have heard of the power of Emacs, but I have a ton more experience with vim and an extensive amount of shortcuts in my .vimrc file. I would like to transfer these mappings over to Emacs evil-mode. What would be the best way to do this? One example would be mapping tab to >> (indenting the current line). Which looks like nnoremap <tab> >> in my .vimrc.

PythonNut
  • 10,243
  • 2
  • 29
  • 75
Jason Basanese
  • 215
  • 2
  • 7
  • 4
    In general, this translation is not going to be trivial. Things are done very differently in Emacs, but I think you'll find that Emacs is much cleaner and more powerful in the long-run, although it's a good deal more verbose. – PythonNut Feb 24 '16 at 04:51
  • 4
    I think it might be better for you to ask questions about specific corresponding lines from your `.vimrc`, rather than a catch-all question. – PythonNut Feb 24 '16 at 04:57
  • 1
    so one cannot just "run the `.vimrc` script I had when text editor in Evil opens up? – Charlie Parker Jan 20 '19 at 19:57

1 Answers1

4

Taken literally, your sample line would translate to the following:

(define-key evil-normal-state-map (kbd "<tab>") (kbd ">>"))

Although I don't personally recommend this. It's much cleaner to reference the function you want to run by name instead of using a keyboard macro. This clears up the need for a distinction between nmap and nnoremap, and is more fault-tolerant.

(define-key evil-normal-state-map (kbd "<tab>") #'evil-shift-right-line)
PythonNut
  • 10,243
  • 2
  • 29
  • 75
  • 1
    How did you know the command was evil-shift-right-line? Experience or is there a library? – Jason Basanese Feb 24 '16 at 04:57
  • 2
    In general, you can use `C-h k` to determine what command a key runs. **However** `evil` does hide some things behind proxy-commands (e.g. `evil-shift-right`) to make the composable grammar easier. In this case, you just have to know that an `evil` operation that works on a whole line is usually `-line`. Examples include `evil-delete-line`, `evil-yank-line`. Some operations, like `evil-downcase` do not define such convenient aliases, so you need more magic to get them to work. Ask if you need help for those. – PythonNut Feb 24 '16 at 05:00
  • 1
    so one cannot just "run the `.vimrc` script I had when text editor in Evil opens up? – Charlie Parker Jan 20 '19 at 19:57
  • @Pinocchio that is correct. – PythonNut Jan 22 '19 at 19:58
  • Why cant i run it? – Charlie Parker Jan 22 '19 at 19:59