Best of Vim Tips
zzapper.co.uk
zzapper.co.uk
http://www.emacswiki.org/emacs/Evil
Seriously, to me it solved all my issues with Vim. Now I have several processes attached to my "Evil", heaps of plugins installed, yet everything blazing fast. And the configuring in elisp started as a little awkward, but now it feels so much more sensible then vim-script (especially knowing that development on Emacs started ding the 70s).
With Evil I can say that --for me-- the Vim/Emacs fight is over:
Emacs now has a great editor...
...and Vim a proper "operating system".
:)
i think this will be solved though (or is fixable), Vim on the other side does not seem very fixable to me.
https://bitbucket.org/lyro/evil/issues?kind=enhancement&sort...
With that said, is it really worth it if I already use vim along with tmux? This is probably what has kept me from trying out emacs before. Vim isn't an IDE, but with appropriate use of tmux it feels like it can be one.
The best thing would be to just check it out if you're ever in a playful mood but the chance is pretty big that just playing around with Emacs for an hour will not be enough to convince you to switch.
Feel free to mail me about Emacs so I can help you as Vim user on the way and if you keep notes you can write that "Emacs for Vim users" guide that you asked for.
(And the MacVim native Mac UI is pretty nice imho.)
Might be fun to do some light reading on it tonight
I haven't been told to STFU and I get to keep a close eye on progress so it's a benefit for me.
It's worth at least trying to build it on your platform to try and iron out the CMake weirdness.
The nice thing about the encryption in vim was that it was a cross platform way for encrypting and decrypting plain text. I use it nearly everyday on my (work) windows pc, headless ubuntu server, macbook pro and nexus 5. And the only thing I have to do is open the file with vim.
And personally I am fine using neovim on my dev box, and firing up vim on the server. Is that a non-starter for you? Do you really need automatic encryption on all your daily editing tasks on your dev machine? And if so, why are you not using full disk encryption?
set number
set relativenumber
This turns your line numbers into a hybrid mode that show the numbers relative to your cursor and the actual line number your cursor is currently on.For (a little) more, see:
In addition to counting motions, other great options for getting around include:
% jump to the matching brace/bracket/paren
( jump back a "sentence"
) jump forward a "sentence"
{ jump back a "paragraph"
} jump forward a "paragraph"
Also, getting around by searching can be hugely worthwhile. n jump to the next occurrence of the last search
N " " " previous " " " " " "
* jump to the next occurrence of the word under cursor
# " " " previous " " " " " "I'm now off to read "cmdline.txt" (:help Command-line).
BTW, I just accidentally closed my browser tab (latest version of Firefox) by hitting Ctrl-W when I wanted to delete the previous word in this textbox. That used to drive me mad but when Firefox restored the tab, it also restored the text I'd typed. :)
Is this for real? Do you count the number of lines or characters before you move? Do you look at line numbers and do the arithmetic in your head? This can't be right, right?
I think most people use commands like f) (move to to the next ')' on the current line) more often than something like 12k (move twelve chars to the right), because, like you say, counting chars is slower than mashing 'k'.
People just use 12k because it's a simple example of how vim commands can be chained together. As a less-contrived example, you can do 2f) to move to the second ')' on the current line.
I "bookmark" important lines with named markers "ma", "mb", etc for "a" and "b" markers respectively, available as 'a, 'b.
Not to mention cscope or ctags for finding function declarations, various call chains, etc., etc.
There are quite a few ways to get around.
For example, if you want to delete 3 words, there is an action to delete (d) and a motion to move forward one word (w): 3dw (read (3) times, (d)elete (w)ord)
If you want to delete everything up to a closing bracket, there's a motion to move to the next occurrence of a character (t): dt) (read (d)elete (t)o ')')
It becomes much more productive when you're thinking in terms of composing actions and motions to achieve a goal rather than memorizing situational key combos. The hardest part is getting over the hump of memorising the actions and motions.
Relative line numbers aren't even too important, given that there is a motion to jump to a line number. If you have a function that you can see starts at line 6 and ends at line 14 and I want to move it to the top of the file. You want to go to line 6 (6G), delete (d), go to line 14 (14G - thus applying the delete action to the motion of moving from line 6 to line 14) then go to line 1 (1G) and paste (P).
I prefer to use d3w since it feels more like English. It's also more compatible with other combinations like ci" ('change inside quotes', e.g. to change a string), ca" ('change around quotes', e.g. to replace a string with a constant), or yt{ ('yank to brace').
Various semantic movements help a lot, too. But I never stress on hitting the target exactly, I'd rather get nearby without thinking than stop and think to get there in one command.
Grok vim!
http://stackoverflow.com/questions/1218390/what-is-your-most...
It's nice to not "read more after the jump" or "below the fold", no over-pagination, no 100% width 400px deep semi-relevant banner image, no pull quotes in 30px ultra-bold fonts floated over to the sides, no "you may also be interested in" and no asinine comments, .. oh, wait!
A lot of pages I find frustrating are often trying to spin a narrative around what amounts to reference material, or vice-versa & results are often framed with the tropes I mentioned above.
Wow, thanks for the tip, any ideas on what it does?
A lot of these seem to be learn to use regular expressions and not really vim related other than vim supports regular expressions. I.E. the 4 or 5 different ways to find an exactly 4 digit number that mostly seem to boil down to '/' does search by regular expressions and here is a regular expression that finds 4 digit numbers.
Between mark `a' and `b'
> g/fred
If the line contains the pattern Fred, execute the following command (s/dick/joe/igc)
> s/dick/joe/
Replace dick with joe
> /igc
i: Case insensitive
g: Replace multiple occurrences on the same line
c: Ask for confirmation on each substitution
I may be wrong about some detail, but I believe that's it.
https://github.com/nosami/Omnisharp
It provides intellisense, find-usages, and other features.
That said, it's really beneficial to learn how to form these commands yourself. For instance, if you know regexes, a good chunk of the commands presented would be relatively easy to come up with yourself. Is it worth learning regexes, Vim shortcuts (basically a lot of arcane things)? Maybe, maybe not. If you spend (or plan on spending) a huge amount of time manipulating text files it's probably worthwhile. For me at least, it's much more satisfying to do most text manipulations (e.g. remove trailing whitespace) by running a concise command, than doing it manually.
For what it's worth, it's even fun to sit and think of how you can avoid doing some manual task. Vim shortcuts + regexes are a really good way of avoiding silly work.
Also, this:
ggVGg? : rot13 whole file (toggles)
So g?<motion> applies ROT13 to text. But... why?Edit: Make that "a couple of useful tricks in there". These are the ones I can actually see myself using:
@@ last recording
@: last command-mode commandSome of us still do that. I <3 nmh.
I must admit to setting $EDITOR to nano for mutt.
Thanks for the insight!
Are you asking the motivation? I presume it's because someone wanted to be able to easily obscure things like spoilers in messages to mailing lists.
As a mnemonic, it doesn't seem unreasonable.
At the moment the ease and frictionlessness of refactoring like this (instead of manually moving text objects around) beats Vim's productivity gains. It's a shame because I still often think in terms like "ci(" when using an IDE.
I've tried Vim emulators in IDEs (not recently, mind) but they're not the same.
Anyone have any suggestions to get the best of both worlds?
I suspect my usage of Vim itself is fairly basic, making this workable. What issues did you find with this approach?
I started using vim only recently, and when I was running through vimtutor, I was telling myself how I'd never be able to remember or understand what is w, W, B, E, {, dib, ci(, ma{{{yy`a"bddp (maybe there's a better one than this) or :%s/a/b/g.
After only a month or so of usage, I've come to use commands and sequences like this by heart. And when I read useful tips or watch screencasts, I'm just remembered how I've barely even scratched the surface of productivity with vim.
That's why I don't fear I won't be able to remember more and more new, complex commands. I think it will all come naturally, like the first ones I learned. The same should happen not only with me, but with you or anyone else who is dreadful of remembering increasingly complex workflows of commands with vim.
I guess i am using vim only because it is most often available on 3rd party systems and because of the occasional need for those last 10%.
And to be honest, i used to use vim on the desktop for some time, but now we have this variety of options.. from fast loading textadept, gedit, sublime text3 to full-blown IntelliJ.. Why vim? Because it's "cool"? Feels more like ancient and antiquated.
Nice list though, it's bookmarked for those 10%! :)
- A just booted VM with with no window manager installed. You have very few choices, but can always count on vi being there.
- Abstraction: One builds up the knowledge of different things over a period of time. For exaxmple, once you learn 'w' is next word, it can be combined with the new knowledge of 'd' for delete quite intuitively. Not saying other editors don't have that.
- Each popular editor I know of has a VI mode built in (or easily available). So, being comfortable with vi means being able to use any of the mainstream editors with vi mode, but not the other way around.
I'll also add: So, one person puts up a long-ish page of examples. Is there anything inherently wrong with this? Presumably, it's useful to them and perhaps to some others. Doesn't that suffice -- it's the Internet!
Not every page needs to be carefully curated for global karma-whoring.
[0]: http://delvarworld.github.io/blog/2013/03/16/just-use-sublim...
That blog post reads like a rant, do the author really know anything?
As far as a business case goes, there's no real "vendor lock in" with a plaintext editor like this. You can always switch to something else and your files will be fine/the same. You're investing (potentially non trivial) time to learn using it, but it didn't take me long to learn ST2 to a depth that made it really handy.
I will say I'd buy a lot more into that argument for people who develop plugins.
That said I can respect the "open source" only mindset. I'm just not sure I'm that concerned about it in this particular case.
For example there was a time when I switched a Linux distribution each month, then at some point I realized that it is getting me nowhere: I didn't know either of them in-depth or how to deal with their specific problems. So then I made a choice: I'll use only Debian, and actually learn about how to deal with problems when I encounter them, instead of jumping ship to another distro.
Its the same with text editors, I eventually settled on Vim (for a long time without any plugins), then started using plugins as well.
Sure every now and then I check what new alternatives are out there (for example there are some interesting ideas in http://leoeditor.com/ but not really comparable to Vim), but closed-source tools are never on my list. I only ever heard about Sublime Text here on HN, and even then for a long time I thought its a Mac only tool.
But with closed-source tools I just wouldn't have been motivated to stick with any of them: if there were problems with it then I wouldn't know how to work them around, or implement missing functionality, not to mention I wouldn't trust them to begin with etc.
I should say that I can't really settle on VIM right now because I'm doing full time .net work at this point. I still use it reasonably often when I'm mucking about in C at home, and I used it as my primary editor for at least five years prior to that, but my use-case was me trying to get a decent haskell environment up and running on a fresh linux VM as quickly as I could. ST2 worked really well for that.
If you work on closed-source software then you probably don't care about this / doesn't matter there, but as someone who spends most of his time working on open-source software I definitely want my editor to be open-source.
I'm not going to be forking an open source text editor if development stagnates.
With closed source you don't have much choice except running an outdated chroot with an old distribution, or stop using it.
And honestly even with open source if the main devs stop updating or doing something you don't like you're time is almost certainly better spent doing what you're doing on a different editor or the old version then taking over development on yet another text editor.
So then why not just open-source it? Seems to me there are only drawbacks in keeping it closed.
HOWEVER: The article you linked is similarly bad. There are excellent reasons to use vim outside of "keep your fingers on the home row". Very common operations such as "delete the next 30 lines", "Move these 10 lines to just after line 150" and so on are much faster in vim and this is why I use it. I don't use it for hjkl (which is only there because of the presence of arrow keys on those specific keys in the 80s) and I certainly don't use it so I can write plugins in the god-awful vimscript. Although it's nice these things are there, that is really not why I use vim.
No, I use vim because it has a comfortable set of basic keybindings, which you will use a lot while you get used to the more complex ones.
Besides, it's not so much about using vim, but about using a good GUI editor with vim mapping.
A lot like Regexes. The first n attempts at a regex always fail, and fail for human reasons - I didn't spot that the pattern I'm matching on actually appears earlier in the writing, the pattern has a typo but I spelled it correctly, the pattern used a unicode character that looked like an apostrophe, etc.
And Vim composability suffers in exactly the same way. "Delete back eight words" works on paper, but eight words isn't a thing you can glance at, it means stopping and counting - especially not if it goes back over a linewrap. And does what about the word boundaries? If the cursor is in the word, at the end, at the start but still has to cross the word boundary to get to the previous word?
Combined with that, the way Vim commands have instant and unbounded effects means that the wrong command or a misspress of a key, and suddenly there's a huge change to the text and you don't know what happened. This leads to the effect where even if a change looks right, if it was a big change ("add a comma to every line just before the last word") needs a lot of careful verification to make sure it worked as intended.
In real world use, almost everything I try to do in Vim outside the everyday patterns of habit, takes enormously longer, works less well, is more fiddly and stressful, than 'just' doing it by hand or in Python.
Regarding the 'I pressed the wrong key' problem there is undo (and if you enable undofile you can undo even after saving or reopening the file), and there is git history.
Having said that I agree that there are often situations where automating something (or using a more complex Vim command) would take more time than doing it by hand.
(As for "just use Sublime", I'd say just use Emacs :P -- but seriously both are probably OT for this.)
It's always the first plugin I install in Visual Studio, I cannot work without it. It might not suit the needs of more advanced Vim users, though.
[1]. http://visualstudiogallery.msdn.microsoft.com/59ca71b3-a4a3-...
[2]. https://github.com/jaredpar/VsVim/wiki/Supported-Features
[3]. https://github.com/jaredpar/VsVim/wiki/Settings-Reference
I can still use vim shortcuts comfortably and such, but setting up the environment was always a pain for me.
I was setting up an editing environment on a linux VM at home to write some Haskell, and started looking through vim plugins, etc. I got sick of it after five minutes because I didn't really want it to be a big thing, so I installed ST2 and the various haskell plugins. It took about ten minutes to get it running in a state where I could compile/build/repl from the text editor and have basic vim motions (which is really all I need from it right now). It also has a few things I really dig like the fuzzy command palette and multiple cursors (which are now available in a lot of editors, but ST2 still has the cleanest implementation that I've used so far).
I think the package manager/extensible side of vim is what really bugs me. Sure I can get in and figure it out, but I just don't want to most of the time.
Obviously this is a really superficial look at what vim has to offer and a very narrow use-case/problem; ymmv dramatically. I contributed a pretty solid chunk of change to the neovim project and I'm really a big fan of vim in general, but for that specific use case, I wasn't terribly happy.
I have never understood this argument. Copying my local .vimrc and .vim from one machine to another has always been enough to create an _exact duplicate_ of my environment. What's missing?
I'm not that it's necessarily excessively complicated; it's just not particularly straight forward, either. This could just be a failing on my part, but I haven't set up a vim environment in about a year, and there were enough confusing parts to do a little head scratching to get haskell plugins working to make me grab something else for now. With ST2, it's been about the same amount of time since I've set it up and only took around ten minutes to finish (that's with plugins to integrate HLint, compilation, a repl, type checking, etc).
Again, keep in mind that I said this was a very narrow use-case/situation. I'm not arguing that VIM is more difficult to set up for any case outside of the exact one I said. I'm not saying it is or isn't a generalizable point. I'd really have to do more digging to find out. What I am saying is that in this situation ST2 was easier to setup.
I'm also not arguing against VIM because of setup time/difficulties. Setting up a coding environment should be a relatively small chunk of the total time you spend using it to code. I'm just noting a relevant experience I had last night.
I haven't written anything here that says I won't use vim, or that I don't plan on using vim. I used it for years before, and even given those issues, I'm sure I'll end up using it again. I love the feel of the modal editing and how far people go with plugins/extensions.
That said, everything I noted can be fixed and made to go away. It's all accidental complexity. Package management, plugin management, and installation are all problems that don't necessarily have much essential complexity. If the Neovim project keeps traction, it looks like it'll go a long way toward making all of those substantially easier, or at least toward making it substantially easier to create solutions to those problems.
Either way I'll continue to use vim, but I'll also probably use ST2 a bit as well. The next time I set up an environment, I'll just be much more careful to set it up in a way that makes it much easier to migrate to another computer.
you keep a list of plugins in your .vimrc, beats dropboxing hands down.
They're things that aren't horrifyingly difficult to setup or remember, but they make it a little more complicated and don't feel straight forward.
They're not things that would keep me from using vim, but for this particular context, they're things that made me decide to just throw ST2 on the vm
Vim is a hot mess in some regards, especially the scripting and plugin system. However, it's available virtually everywhere. I'm holding out hope that modern versions like neovim will address some of the legacy issues.