4 ms·
Vim is a modal editor, which means one keystroke doesn’t have the same meaning in one mode and in another. Emacs, on the other hand, doesn’t have all these mode
by hk__2 12y ago
Vim is a modal editor, which means one keystroke doesn’t have the same meaning in one mode and in another. Emacs, on the other hand, doesn’t have all these modes, which is why you have to use modifier keys like ctrl/shift/alt to tell it what to do. That’s two paradigms, I’m not sure one is better than the other (note: I’m a Vim user).
- aerique 12y agoI switched from Vim to Emacs 15+ years ago because I did not like modal editing. Now I am using evil-mode in Emacs :-| I'm not sure which one is better either.
- pyre 12y agoI'm currently in the middle of attempting to gain proficiency in Emacs. I have to admit that it's difficult being someone that's spent 10+ years using Vim. I'm used to being able to just hit HJKL as a nervous habit, which doesn't go over so well in Emacs. I feel like there are many things in Vim that seem superior at first glance. For example, if I want to do a regexp search/replace in Vim, I can do this from Normal Mode (which will replace throughout the whole file): :%s/regxp/replacement/g<enter> Emacs (by default) has `replace-regexp`: M-x replace-regexp<enter>regexp<enter>replacement<enter> My only problem? This only replaces from the cursor to the end of the file/buffer, so to replace over the whole file I would need to do: M-< M-x replace-regexp<enter>regexp<enter>replacement<enter> It just seems that much more complicated, and now I've lost my place, so I'm at the top of the buffer rather than wherever I was in the file. On the other hand, I find Emacs Lisp to be much easier to deal with then VimScript/VimL even as someone that has written my own Vim plugins, and created plugins to patch issues with files in the standard Vim dist (too lazy to submit a patch and wait for the next Vim release).
- baddox 12y agoThis obviously isn't a solution to your valid complaint, but you can use C-u C-SPC to navigate to your previous cursor position. It can band-aid your issue, but it's also quite useful in general. https://www.gnu.org/software/emacs/manual/html_node/emacs/Mark-Ring.html https://www.gnu.org/software/emacs/manual/html_node/emacs/Ma...
- inclemnet 12y agoAre you aware of evil-mode? One of the many things it implements is the :%s/stuff/otherstuff/g syntax.
- pyre 12y agoI'm aware of evil-mode. I'm attempting to try 'the Emacs way' first. I'm not attempting to just throw myself in. When I need to be proficient I'll fallback to Vim, but I want to gain access to things like org-mode, for instance.
- klibertp 12y ago"The Emacs way" is very much "learn some elisp and write whatever you want". I switched from Vim to Emacs and in the beginning there were some things I really missed. One that I remember was "*", which in Vim/my config highlights current word in whole buffer and let's you n/N between matches. In Emacs, doing the same with M-left C-s C-w felt just wrong. Fixing this was a matter of 2-3 lines of very straightforward elisp. I since started relying more on Occur mode and IEdit mode for this, but the experience of lacking a feature and adding it absolutely painlessly remained with me. Writing simple elisp and simple editing-related features is a joy under Emacs. It's much easier than in Vim, for a number of different reasons. This makes me think that "the Emacs way" is about scripting and programming it to do whatever you need it to do.
- Wilfred 12y agoYou may also be interested in https://github.com/nschum/highlight-symbol.el https://github.com/nschum/highlight-symbol.el which provides highlighting of the current symbol, and provides highlight-symbol-{next,prev} commands to move between occurrences of a symbol.
- dustym 12y agoHere's some elisp I use to do this (assuming I understand your issue correctly and it's the same as mine): (defun replace-regexp-g () (interactive) (save-excursion (goto-char 0) (call-interactively 'replace-regexp)))
- barrkel 12y agoI find that you need to be willing to write your own little elisp routines to get the best out of Emacs. If whole-file replacements is how you like your search and replace, then write a routine for that. My bugbear with regex replace - apart from rebinding it to M-r - was that, when applied to a region, it didn't keep the region. So I wrote a macro that "advised" the function (and any other function I choose) with code that restored the region after the command was finished. Be aware, however, of iedit-mode. Select a region of text and enable iedit-mode, and any change to the selected region will be propagated to every other instance of the region's text throughout the document. Using iedit-mode in combination with rgrep (recursive grep) and wgrep (editable grep buffer that propagates changes to the underlying documents) is a decent way of doing project-wide refactorings. And of course, neither iedit nor wgrep are part of the base emacs install. Using the package manager is essential.
- ChickeNES 12y agoHave you taken a look at NeoVim (https://github.com/neovim/neovim https://github.com/neovim/neovim)? They plan on replacing VimScript with Lua.
- pyre 12y agoI'm watching NeoVim, but I'm skeptical about their ambitious goals (i.e. refactoring internal Vim code). I do wish them luck though.
- foobarqux 12y agoM-< C-M-% regexp RET replacement RET C-u C-space If you are just replacing plain text (no regexps) then take a look at iedit. Then C-; will edit all occurrences of the word at cursor.
- jasonm23 12y agoIedit mode works beautifully with wgrep + rgrep/ack/ag results.
- tuhdo 12y agoYou can check https://github.com/syl20bnr/spacemacs https://github.com/syl20bnr/spacemacs if you want to use Evil mode not just for editing but for everything else in Emacs. Just clone to your ~/.emacs.d and start Emacs then everything will be automatically installed for you. Most key bindings outside of editing are Vim-like, created by Vim users. You already stick with Vim for 10 years and learned many things about, so I suggest you to keep that knowledge. But then, aside of editing text, if some Emacs utility does not have Evil key bindings, you should also learn the default, because most of the utilities are always in normal mode, so you only need to press a single key to execute most commands. spacemacs also has extensive documentation, so you can learn key bindings easily and be productive with Emacs immediately without any extra configuration.
- pmoriarty 12y agoEmacs does have modes (even if we set aside vi/vim emulation modes like evil, which is discussed elsewhere in this thread). When you use certain major or minor modes in emacs, you get to use a whole new set of keystrokes, by which you're effectively doing modal editing. One well-known example is magit.[1] When you activate magit, you can type all sorts of new one- or two-key commands. This is comparable to modes in vim. [1] - http://www.emacswiki.org/emacs/Magit http://www.emacswiki.org/emacs/Magit
- hk__2 12y agoThanks. As a Vim-only user I don’t know all these Emacs things (but am willing to learn).
- sjm 12y agoExactly right! All input in Emacs is just a key-bind. In a buffer focused on text-editing, letter keys (e.g. "a") are actually bound to a function called self-insert-command which inserts the last character typed. Modes like magit just re-bind keys to different functions (e.g. "s" gets bound to magit-stage-item).