Vim macros don't work when using viper + vimpulse in Emacs

和自甴很熟 提交于 2019-12-10 17:19:46

问题


Any other tweaks for making emacs as vim-like as possible would be appreciated as well.

Addendum: The main reason I don't just use vim is that I love how emacs lets you open a file in two different frames [ADDED: sorry, this was confusing: I mean separate windows, which emacs calls "frames"]. It's like making a vertical split but I don't have to have one enormous window.


回答1:


You could run VIM in client server mode, then you could have two windows connecting to one instance, hence removing the need for Emacs.




回答2:


I don't know how to make Vim macros work, but since you asked for tweaks for making emacs as vim-like as possible, here's a few additions to vimpulse I use everyday:

(define-key viper-vi-global-user-map [(delete)] 'delete-char)
(define-key viper-vi-global-user-map "/" 'isearch-forward-regexp)
(define-key viper-vi-global-user-map "?" 'isearch-backward-regexp)
(define-key viper-vi-global-user-map "\C-wh" 'windmove-left)
(define-key viper-vi-global-user-map "\C-wj" 'windmove-down)
(define-key viper-vi-global-user-map "\C-wk" 'windmove-up)
(define-key viper-vi-global-user-map "\C-wl" 'windmove-right)
(define-key viper-vi-global-user-map "\C-wv" '(lambda () (interactive)
                                                (split-window-horizontally)
                                                (other-window 1)
                                                (switch-to-buffer (other-buffer))))

(define-key viper-visual-mode-map "F" 'viper-find-char-backward)
(define-key viper-visual-mode-map "t" 'viper-goto-char-forward)
(define-key viper-visual-mode-map "T" 'viper-goto-char-backward)
(define-key viper-visual-mode-map "e" '(lambda ()
                                         (interactive)
                                         (viper-end-of-word 1)
                                         (viper-forward-char 1)))

(push '("only" (delete-other-windows)) ex-token-alist)
(push '("close" (delete-window)) ex-token-alist)

Of course, learning Emacs is very important too, but Emacs relies on customization to make it behave exactly like you want it to. And the default Vim key bindings are so comfortable that using Viper simply means that Viper does some Emacs customization for you.

As for using Vim instead of Emacs, I love Vim, but I love the interactiveness of the Lisp system that is Emacs. Nothing feels like typing a line of code anywhere in your editor and instantly evaluating it with a single keystroke, changing or inspecting the state of your editor from your editor (including the live documentation) with a single keystroke (C-M-x) while it is running.




回答3:


I don't have any viper or vimpulse tweaks for you, but I do recommend that you try follow-mode.

Of course I'd also recommend that you start learning Emacs too. I mean, if you're in this far you might as well go through the tutorial and maybe have a look at emacswiki.




回答4:


The version of VIM I use support (Window version) support splitting a file into 2 different frames using "Ctrl+W s"...




回答5:


Vim easily lets you open a file in two different frames:

:split to split it horizontally

:vsplit to split it vertically

You can split the screen as many times as you want between the same file, different files, or both.

CTRL-w-w switches frames.

:resize +n or :resize -n resizes the current frame.




回答6:


Emacs+vimpulse is awesome, but I think its right workflow is to liberally use emacs commands in combination to vim shortcuts. For example, emacs's macro shortcut F3 and F4 is easier than vim's qq and @q . Also emacs commands are accessed through Alt+x, not : commands. Though vimpulse support a few important vim commands, they are there just for compatibility.

Followings are my vimpulse specific customizations.

.emacs

   ; I use C-d to quit emacs and vim
   (vimpulse-global-set-key 'vi-state (kbd "C-d") 'save-buffers-kill-terminal)
   ; use ; instead of :
   (vimpulse-global-set-key 'vi-state (kbd ";") 'viper-ex)
   ; use C-e instead of $. This works for all motion command too! (e.g. d C-e is easier to type than d$)
   (vimpulse-global-set-key 'vi-state (kbd "C-e") 'viper-goto-eol)
   (defun t_save() (interactive)(save-buffer)(viper-change-state-to-vi)) 
   (global-set-key (kbd "\C-s") 't_save) ; save using C-s instead of :w<CR> or C-x-s

    (defun command-line-diff (switch)
          (let ((file1 (pop command-line-args-left))
                (file2 (pop command-line-args-left)))
            (ediff file1 file2)))

    ;; Usage: emacs -diff file1 file2 (much better then vimdiff)
    (add-to-list 'command-switch-alist '("-diff" . command-line-diff))

If you like terminal, you can use emacs -nw. In this case, this clipboard add-on is useful. http://www.lingotrek.com/2010/12/integrating-emacs-with-x11-clipboard-in.html

.viper

    (setq viper-inhibit-startup-message 't)
    (setq viper-expert-level '3)
    (setq viper-ESC-key "\C-c") ; use C-c instead of ESC. unlike vim, C-c works perfectly with vimpulse.

Almost everything vim does can be as easily done (if not the same way) in emacs+vimpulse but definitely not vice versa!

p.s. most of the suggestions above are supported by recent vimpulse BY DEFAULT.




回答7:


You could always start vim in a shell buffer and resize it so it filled the whole frame?




回答8:


If you want VIM functionality, it makes more sense to just install VIM!




回答9:


I'm not sure if I answer your question, as it is not entirely clear what you are asking (why the macro's are not working, or which tweaks are available for emulating vim in emacs)
so, is this your problem?:

  • One user who uses an ancient emacs-snapshot (from 2005) mentions
    that this mode causes all the keys on his keyboard to stop working unless he deletes the line that reads 'viper--key-maps from the macro my-get-emulation-keymap in this file

if it is, you can try the stated solution.

I got this information from the emacs wiki, and it's a known bug.



来源:https://stackoverflow.com/questions/98225/vim-macros-dont-work-when-using-viper-vimpulse-in-emacs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!