Vim: revisited
mislav.uniqpath.com
mislav.uniqpath.com
I've been using Vim for a while, and this is one of the best-organized overviews of Vim I've seen, partly because he doesn't try to enumerate every single key combination (which is the wrong way to learn Vim - the right way is to synthesize the way that the individual operations are logically combined, though that admittedly takes some time). The best two pieces of advice he gives are (1) not to put anything in .vimrc without knowing exactly what it does, and (2) don't use too many plugins.
At this point, I actually don't think I really use any plugins regularly. I have nothing against Vim plugins in general. It might be a bit faster to install a choice few, sure, and someday I might try and figure out which ones work best for me. But for the time being, I'd much rather know how to navigate my file or project with just the standard set of operations and minimal configuration. That way, I can launch Vim on any machine and start using it, without needing to waste time setting it up just so I can use it properly.
(Disclaimer: I have mapped Caps Lock to Esc, which is indeed a major problem if I use another person's computer. I've gotten used to seeing "E492: Not an editor command: W" practically every time I type on a friend's laptop. But it saves me so much time when working on my own machine that it's worth it!)
In short: stick with Vim long enough, and you'll find that you don't really need many plugins or much configuration for it to be incredibly useful. They help, but not as much as you might think, especially once Vim's standard keybindings become part of your keyboard reflexes.
" Enter command mode with SPACE instead of :
noremap <Space> :
" Exit insert mode with jj (double J) instead of ESC
imap jj <Esc>Now it does.
let mapleader = ","
it remaps <leader> to ',' instead of '\'That's why it makes sense that my strongest fingers are on the up/down motions, whereas to move to the left, a movement I never make, is off to the side.
Also, I wouldn't remap it for practical reasons - hjkl is a standard implemented in many places.
Hence, your question is somewhat misguided ;)
Unless you mean you specifically use search for every motion...?
* I like using "Ctrl+Direction" to move around splits, and mapping Ctrl+; on a Mac doesn't work without some Keyremap4Macbook trickery. It's a pain to get working.
* Tons of other stuff uses Vim bindings, and you can't usually remap keys in most other programs.
https://github.com/tomhsx/dotfiles/blob/master/vimrc
I think the advice to stay away from highly customized environments and hacks is really the way to go. A huge strength of vim is that you're going to find it on any server you end up using.
Disclosure: I didn't disable my arrow keys when I started with vim, but after a few months I did end up doing it to really brand the h/j/k/l movements in my mind.
The newer versions of Vundle are fantastic, and give you features like lists of your current plugins and searching of the plugins repository.
His best recommendation is at the top: don't configure a lot of settings and plugins at first. Start with a minimal setup, and slowly work up from there when needed. In particular, don't copy someone's huge .vimrc.
In fact, that's good advice for any tool or technology: start minimal, and only add what you need, when you know you need it.
To his minimal initial configuration, I would suggest one addition: set a colorscheme that looks good to you in the terminal/gui environment you normally use, and choose from the default schemes rather than downloading a pack of them. I like elflord (it doesn't use a lot of red, which is hard to read on a black background), YMwillcertainlyV.
To see which scheme you're currently using, open an existing file in your favorite language and then:
:colorscheme
To cycle through the available schemes: :colorscheme<space><tab>
Each tab will show you the next scheme's name; hit enter to try one. :let colors_name
Though this doesn't always happen. To those who would say “that’s obvious; of course you learn
vim incrementally”, I would simply say that having spoken to
a number of vim users in the past, I never got that advice.
Instead, I got a lot of advice about turning off my arrow
keys, disallowing the use of the mouse, and learning the
(MORE EFFICIENT!!!) vim ways to do everything, all at once.
People just couldn’t stomach the idea of me continuing to
use an outmoded practice (like apple-f) when vim had much
better tools available just a (huge volume of) memorization
away."
Source: http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convi...I am an inherently lazy person; I cannot just sit down and memorize stuff (one of the reasons I'm in CS). Yet I definitely support giving up the mouse and arrow keys immediately.
When I originally picked up Emacs, I went through the tutorial and promptly forgot exactly which keys did what. However, I decided to follow the tutorial's advice and learn how to navigate properly. To do this, all I did was not use the mouse or arrow keys for editing some text. For the first couple of days, I had to keep looking the keys up each time I did anything; later--relatively abruptly--I started using them without realizing. There is no way I would have learned nearly as much as quickly if I had not got through a couple days of not knowing what I was doing.
Once the standard moving commands became second nature, I started using some of the more specialized ones (like moving around by line or paragraph or expression). Without having given up on the arrow keys and mouse, I would probably never have learned the more advanced movements which are now exceptionally useful.
Basically, to follow your suggestion would be to avoid a couple days of bumbling around in favor of being less effective for a very long time. On the other hand, with my approach, I did spend a couple days being incompetent but then the bindings became natural. Ultimately, to me, being lazy involves not just minimizing work immediately, but increasing efficiency in the long run as well.
As a contrast, I know many classmates who have tried to learn Emacs your way. Most of them can use it, but not much more efficiently than notepad; I regularly see them spending minutes doing menial tasks that would have taken seconds had they known Emacs better. In the context of a 90 minute lab, that is not trivial at all; even in the context of working full time, the amount of time they can save should not be ignored.
Ultimately, all it takes to learn Emacs (and, I imagine, the same can be said of Vim) is a little bit of patience and willingness to embrace change. By jumping into the deep end immediately, you can learn really quickly, and reap the benefits almost immediately.
This puts off a lot of people, especially if they're working full time as a couple of days fumbling with a text editor equates to real dollars lost in productivity. (In my experience though, it'll take at least a few weeks to be even mildly proficient).
If you're a student (I was 13 when I first picked up vi) this is no problem, as I had infinite time on my hands, but when you're working full time, the amount of time you have to experiment drastically reduces.
Also, while my approach will certainly cause a small amount of difficulty at the very beginning, I think you will actually win out in the long run. That is, let's say you normally code at 1 productivity unit (whatever that may be). My way, you may spend a some time at 0.1, then a bit of time at 0.5, but, in a couple weeks at most, you will start working at 1.5 or 2 or more. On the other hand, while still using arrow keys, you may first be at 0.8 for a bit, then back at 1 then maybe at 1.2. But you will not see any drastic improvement for a while, and so will actually be less efficient in the long run.
However the huge shift in mentality has to go from the idea that you are working with a "text editor" (which VIM and EMACS are not IMHO) and a text processor which I would argue these are.
When you start thinking about processing rather than editing text, the productivity goes way up. There is nothing like these tools in the text editor world for editing large, complex codebases. IDE's can't compare.
Time to remap that one too.
As someone said, when programming typing isn't my bottleneck, thinking is.
Full touch-typing speed is a must for court clerks -- not for programmers, and also not even for writers.
Couple this with inoremap jj <Esc> and it eliminates the majority of large movements away from the home row.
Say you are in the middle of a word that you want to change compare: Arrow key right until at end of word, i, backspace until at start of word, type new word, Esc three excursions from home row.
Ciw, type new word, jj. No excursions from home row and less of a mental load.
But I'm glad to learn from your link that it's possible. I'll show it to aspiring vim users as an alternative take to learning vim.
This is probably the most valuable piece of advice in the article. I have over a number of years looked at the tangled mess that my .vimrc had become, but always put off cleaning it up because I really didn't understand what some of the things did.
I thought to myself: Yes some of the keys act a little funny (sophacles/vim-bundle-python had awful, conflicting use of [c when I used Vimdiff on a python file), and yes I get warnings about some things, but hey, I must have put all this stuff in the config file for some reason.
Well, tonight I finally pitched my whole .vimrc (https://gist.github.com/1464673) and I am much happier as a result. I realized that I didn't need all that stuff to be productive, and I never probably used any of it anyway.
I had been using Vim for years, and this is fundamentally one of the most useful settings I came across. I think it's only available it the latest rel.
Funny side note, I was out on the town one night and saw a bunch of guys and girls hacking on their laptops... in a club. I noticed one guy using Vim, came up behind him and told him he has a good taste in editors. It turns out he's Jay Freeman (saurik). I showed him relativenumber and he was stoked. EOS.
if version >= 730
set relativenumber
endif " toggle line numbers from absolute to relative with f2.
map <silent> <F2> :if &number <Bar>
\set relativenumber <Bar>
\else <Bar>
\set number <Bar>
\endif<cr>Also, openvim.com has an excellent online tutorial that's convenient.
"Don’t use the NERD tree plugin. It is clumsy, will hurt your workflow with split windows, and it’s not particulary pretty either. You never needed a file browser pane in the first place."
"It is clumsy"
We're talking about VIM, with dozens of keystrokes to invoke everything but emacs already. The whole thing is a bit clumsy! I use it every day and have for a decade but it's still clumsy.
"will hurt your workflow with split windows"
The author then goes on to state
"You can split the current buffer horizontally or vertically. This is useful, for instance, to view simultaneously the top and the bottom part of the same file. But it’s even more useful to view different files in splits; for instance tests and implementation."
HUH?
" and it (nerdtree) ’s not particulary pretty either"
And the rest of VIM is?
Nerdtree is great, especially when I'm using it on remote systems. A vim session open with nerdtree and some tabs inside of a screen session, and life is good.
I'm not a VIM purist. I use the arrow keys, and I use the mouse a lot. I find NERDTree to be tremendously easy to use and helpful when on a local system.
On remote systems, though, I generally just edit 1 file at a time and don't need NERDTree. For multiple files, :e works just fine in those situations.
I toggle nerdtree on and off often, so it's there when I need it, and gone when I don't, so I don't notice it getting in the way of my split windows all that much.
nnoremap <Leader>n :NERDTreeToggle<CR>
I suggest remapping NERDTree's help function from ? to H so it doesn't interfere with search-up.Some additional tips:
* As your # of plugins grow it helps to isolate plugin-specific config to separate files. Example: https://github.com/cldwalker/vimfiles/tree/master/after/plug... .
* If you want to stop seeing vim as a series of unforeseen tricks, take the time to learn the 300-400 keybindings you find useful. I'd recommend a free flashcard program like anki which also has a vim flashcard set, https://github.com/amikula/vim_flashcards
* One helpful pattern I've noticed in memorizing keybindings: uppercase, left characters i.e. P, ( map to above and reverse; lowercase and reverse characters i.e. p, ) map to below and forward
* If you're looking for a more powerful to search your vim docs, check out my vimdb project, http://github.com/cldwalker/vimdb
Do you mean 30-40?
Janus is what got me to switch full time to Vim a few months ago, after having used Vim off and on for over a decade, mainly on the command line or for edits that were to difficult or repetitive to get done in more "friendly" editors/IDEs like TextMate and Visual Studio.
Janus provided just enough familiarity and convenience to make a full-time swap something I could stick with. After a couple of months of this I did basically dump Janus and start managing plugins myself with Pathogen (adding new ones and removing some of the default Janus ones), and customising my config (which is still based on the old Janus config, but extensively modified)
If I was pinning my productivity on customizations then emacs would be the clear choice.
If I wanted the perfect coding environment for language X, there's a good chance it would be an IDE.
But with vim, I can open any text file on any system and edit the hell out of it amazingly efficiently. It's extensibility is a nice bonus (very nice in some cases! eg: https://github.com/tpope/vim-fugitive), but at its core it's about raw text manipulation.
It's also true that Vim 'suffers' from the open source infinite configurability issue. That is, it is so configurable that you'll spend a significant amount of time configuring it to your tastes rather than getting work done. This tails off over time of course. Slightly more awkward is that it's also easy to shoot yourself in the foot. For example my current config has an issue where on rare occasions undo sporadically fails, and ends up undoing line insertions by deleting the wrong line! Ouch. I still have several such issues, but not enough to deter me as yet.
Another thing to consider is that Vim is not equally suited to all developers. If you're editing a bunch of different file types with mostly consistent libraries I think it's a great fit, which describes a lot of web developers. In that case you just want world class text editing. If you're editing mostly C++ with a bunch of different APIs and libraries, the loss of decent codesense/autocomplete forces you into lots of very slow doxygen searching in a browser. I've tried various solutions to this such as clang complete and eclim, but ultimately Vim is not an IDE and there's no way to make it act as one.
Overall I'm happy to have made the switch though, since the editing itself is so very smooth. It's great to have the same environment in a remote shell as well.
http://alfmikula.blogspot.com/2010/11/using-spaced-repetitio...
It's very easy to do on most OS's today and not having to move your hand from the home row when you switch into command mode is as big as proper use of jump commands imo.
I also agree to avoid all massive .vimrc files. If you don't understand it, don't use it. Simple.
Or, to be more precise, I want Caps Lock to somehow switch modes in vim in a terminal app. If that means configuring something on both sides, the OS and vim, I'm cool with that.
I've tried a number of things but nothing seems to work right.
I learn something new with these posts every time! I've been wanting something like this for a while.
While I do agree using the mouse for cursor positioning isn't always the best use of the mouse, there are situations where it's just better. For instance, using mouse scrolling in vim is very convenient, and mouse selection and paste is also very convenient. It's even better when you can use it across the network!
I loved Sublime Text 1, and I really love Sublime Text 2. With the addition of Vintage, Sublime Text is slowly becoming the ultimate answer to the question of which editor to choose.
But Vintage mode is really buggy, and misses a lot of very important features that vim has. There is work being done on it, and it is getting better, but vintage mode does not come close yet to the power of vim. And there are a few bugs that make it hard to get used to some of vim's more powerful features.
Plus it's much more productive!
Disable arrow keys.
It's extremely painful for the first 5 days but I promise that's all it takes to get use to it. And it makes huge difference in your productivity. All that time does add up.
Add the following to your .vimrc
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
The reason you want arrow keys disabled in insert mode is that arrow keys breaks the modal paradigm. Again, I promise that once you get comfortable, it becomes more efficient to go into editing mode and make the change rather than navigate via the arrow keys in insert mode.If he's saying it's not for beginning Vim users, OK, fine. But "harmful plugin"? Like it's some sort of malware? Very poor form.
Check out Steve Losh's Learn Vimscript the Hard Way[1].
I've been using vim as a supreme novice for a few years, and have only really tried to get to know it better in the past six months after switching to OS X and getting to use MacVim.
And already in one night CommandT has blown me away with how timesaving it is, and how much time I've wasted in the past not using it.
A better alternative: issue the ":set paste" command just before pasting text. That way you keep the original indentation.
Why does everyone feel the need to re-tell the same story?
This story is pretty different from, say, Yehuda Katz's story about switching to Vim.
I find all the different takes interesting, and I think you can casually learn from the differences between them.
i stopped reading here because i knew what was coming next. the omen was fulfilled by the next line:
"in insert mode, now you type text as your normally would. Pressing <Esc> exits back to normal mode."
its command mode vs insert mode. any vi user should know that.. it's the very first thing vi bludgeons you with.
Both have pros and cons; both are in the same everlasting-holy-war and once in a while either will start a new crusade.
1 month - really started to feel a productivity increase over text editing in an IDE
3 months - started to feel like I was flying
6 months - began desperately searching for Vim plugins for Eclipse