4 ms·
Not to troll -- indeed, I am attempting to be constructive -- but in case anyone was interested in (what I know of) vim's equivalent functionality, here's what
by fallintothis 18y ago
Not to troll -- indeed, I am attempting to be constructive -- but in case anyone was interested in (what I know of) vim's equivalent functionality, here's what I have so far:
1) Several options:
:help <something>
:h <something>
Shift-K to run a program to lookup the keyword currently under the cursor (the program defaults to man). On that note, you could just
:! man <whatever>
if so compelled.
2) qq = record macro to register q. @q = replay macro at register q. 100@q = repeat macro q 100 times. @@ = repeat the previous @<whatever>.
The author notes that you can tell Emacs to "please repeat this macro until it would cause Emacs to start beeping", which I found interesting. I'm not sure if there's a specific way to do this in vim; I often just go with, e.g., 1000@q (or whatever arbitrarily large number you want. You can check how many lines are in a file, among other statistics, with g<ctrl-g>). So long as the macro ended with a j (or whatever motion you wanted, technically) it would continue carrying down the lines. It seems as though you could be able to execute macros on some chunk of text, perhaps with visual line select. Hm...
Another interesting feature the author notes is "counters let you insert a different number every time a macro is run." I've had some annoying experiences bending over backwards for this, so I'd like to know an easier way, but it's certainly possible using the C-A and C-X keys, which increment and decrement a number under the cursor, respectively.
3) Ctrl-v for visual block mode (remapped to Ctrl-q for :behave mswin, since Windows captures this as Paste); then, simply move around with the regular keys and perform fancy editing to your heart's content. I use this often, for instance, to insert comment marks in a chunk of text. Go to the first column & line of the block, ctrl-v, hold down j till the region reaches the last line you'd like, then shift-I, type your comment characters (e.g., "//" or ";" or "#"), then <esc> and the insert takes effect on all lines of the previous region.
Also useful during the many adventures in the different visual-select modes, use gv to re-select the previous visual area, should it happen to become deselected. For instance, when I am holding down j in the previous example and prematurely hit Shift before letting go of j, it joins the lines up. Argh! u (undo) then gv to continue on my way.
4) When I first read about this, I was immediately interested. For similar functionality (couldn't claim whether or not it was the SAME, strictly, as I don't actually use Emacs), there's the extension that I now adore: YankRing. http://www.vim.org/scripts/script.php?script_id=1234 http://www.vim.org/scripts/script.php?script_id=1234
5) I tend to use :diffsplit, though there are other ways to work with this. As per item 1, :help diff.
6) Sad to say I'm at a loss here -- not to say vim couldn't do this, but rather I've never needed to do this in my range of experiences (clearly limited compared to that of the author's). If anyone could fill this in, I'd be interested.
7) The few times I work with a language that doesn't have a shell:
:make
Though there are parameters and options to tweak with. For instance, which program to use by default, whether or not to create a temp file for the errors, jumping to the first line containing an error, etc. As stated, I do most of my work in languages with shells anyways, so I'm not an expert with this command. :help make, for more info.
8) Admittedly not built-in (being against vim's Do One Thing Right philosophy, I suppose), but the plugin I use for this is vcscommand: http://www.vim.org/scripts/script.php?script_id=90 http://www.vim.org/scripts/script.php?script_id=90 with a Mercurial backend, since the base plugin is for CVS, SVN, SVK and git: http://www.vim.org/scripts/script.php?script_id=1898 http://www.vim.org/scripts/script.php?script_id=1898 Then, it's a matter of :VCSVimDiff, :VCSCommit, :VCSAdd, which you can remap to whatever keystrokes you like by editing your .vimrc (see item 10).
9) Again, I've never done such things, so if anyone could step in for our fellow vimmers, that'd be great.
10) You can edit your .vimrc to remap keys as you'd like -- including binding them differently per mode you're in.
Taking some silly examples from my .vimrc:
"Maps ctrl-enter in insert mode to open a line below your current line:
imap <C-CR> <esc>o
"Maps ctrl-enter in normal mode to simply o, in case my muscle memory goofs and
"doesn't notice I'm in normal mode:
nmap <C-CR> o
You can also set abbreviations, which will expand as you type:
"Fix typo
abbr teh the
"automatically expand {{ into a curly-brace block, the idea being to hit Enter
"after typing the {{
ab {{ {<cr>}<esc>kA
- PieSquared 18y agoI've been using Vim for about a year and a half now and actively trying to learn it well, and I think I am somewhere near knowing most of what it can do. Not all, of course, but definitely most. However, I've been thinking about trying Emacs as well, because unlike Vim (it seems) it has a [more] complete scripting language and a few other neat things. On the other hand, it's hard to give up a year's worth of experience of learning one editor, just to stop using it and go to another one. Does anyone have significant experience in both, enough to know the peculiarities and such of each editor? I'd love to hear what you have to say on how they compare. Is learning Emacs worth it any more than learning everything Vim has to offer? Since I plan on using this for many years, I'd like to choose the optimal tool, even if it means wasting a year of experience.
- silentbicycle 18y agoI used vi (vim) for about five years, before switching to emacs (gnu emacs), which I've used for about two. They're both excellent text editors, but are clearly optimized for different things, and have tremendous differences in interface, extensibility, and culture. The big advantage for Emacs lies in being a sort of Lisp virtual machine. It's extensible enough to be nearly an OS in its own right (certainly a "desktop environment" or whatever), and has decades of extensions already available for it. Where vi(m) has two fundamental modes (with replace being a submode of insert, I suppose), emacs has modes specific to most tasks -- if you want a mode that integrates with an external Common Lisp (slime), OCaml (tuareg), or Ruby (ruby-mode), it's there. This doesn't just mean syntax highlighting and indenting, it means more abstract things like being able to insert the type signature for a Haskell function under the cursor, jump to the definition of an object's superclass, or check/edit/archive your email. (For a really good example, check out this screencast of Marco Baringer using Slime: http://common-lisp.net/~mbaringer/slime.torrent http://common-lisp.net/~mbaringer/slime.torrent ) Emacs Lisp is not the greatest as Lisp implementations / dialects go, but it has a lot of advantages for extending an editor compared to something like Python or Perl. (I have a suspicion Smalltalk or Forth would work well, though.) I know that vim is extensible, but typically you process a region by typing :%!some_cmd to pipe it back and forth; most integration between vim and external programs that I've observed has been at the level of piping text (in the quintessentially Unixy way). This loses a lot of deeper context that could better tie things together. The main strength of vi, I think, is in its ubiquity. While I use emacs to do most things, I also have a heavily customized environment that I carry around with me. (It's under version control, etc.) I can be extremely productive with it, once I've moved in, but vi is available everywhere. I'm talking about a basic vi (nvi?) with one level of undo and no syntax highlighting, perhaps, but it's still pretty good for editing text, particularly if you're a touch-typist and the interface has become second nature. It edits text. It doesn't tie things together into one harmonious environment, but it edits text, and it's really efficient once you know it. For what its worth, there's an editor called "mg" which has the default emacs keyboard config out of the box, but is not really very programmable. While I'm very familiar with the basic keyboard controls, it feels crippled to me. I use it while doing computer setup stuff, because it's in the default OpenBSD install, and it's a decent pager, but it's really not the same. Anyway, that's my experience with each. Emacs seems far more powerful in the long run, but it takes quite a bit more time to learn to use it to anywhere near its full capacity, and doing so will rely on carrying around your configuration. (It also has a relatively alien culture and vocabulary, which takes some getting used to.) Vi does what it does everywhere, but cannot grow indefinitely to fit your needs. It's focused on just being a good text editor, rather than a full environment. If you're talking years, though, I would definitely give emacs a shot. (Incidentally, I think emacs is quite reasonable under the Dvorak keyboard layout (better than qwerty, I think), while vi feels far more awkward. The hjkl keys get scattered badly, for one thing. That, a growing fascination with Lisp, and being utterly blown away by the Slime screencast were why I ultimately switched.)