vim: key-binding customization -- how far is too far? [closed] - vim

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
What are the pros and cons of changing vim's default keybindings? How far is too far? As a new learner of vim, I already have a glimpse of its power, but I am also much bothered by some key-bindings that don't make sense to me. Already, I have mapped <c-l> and <c-h> to w and b respectively. Now I'm itching to find a new key for $ so that I won't have to press shift just to go to the end of line. To my mind, the basic motion keys should be one-button operations (my mapping above notwithstanding, I still use w and b in conjunction with d and c etc), and spatial logic should trump symbolic logic in deciding their placements. - is currently my candidate for replacing $ because as a shift-free key to the right of 0 (for the beginning of line).
Should I go ahead, and thus opening the floodgate for potentially myriads of other changes? Or should I try to adapt to the default? One thing that's holding me back is my concern about unintended consequences that I, as a newbie, cannot foresee, including loss of functionality (such as what the - currently does, which doesn't seem like much to me). In addition, I'm not sure how I feel about customizing vim so much that I can work only with my vim and no others. Are these concerns valid or overblown? Thanks.

While I agree that some vim key-bindings can be awkward, you should start off following the defaults in the beginning. After some time most of it becomes muscle memory and it shouldn't bother you much. If after a long time you still feel uncomfortable, feel free to rebind some keys. For example I have <CTRL-S> bound to save because it's easier than pressing <ESC>:w<CR> and less confusing when I'm working with other editors.
If you start rebinding too many keys too early, you will find it frustrating to use vanilla vim (for example on a remote machine).
As for your examples, I personally think <c-l> and <c-h> are harder to press than w and b. For example cw is a common vim operation and can be done using one hand compared to c<c-l>.

I say, go for it. Although it appears that you have already learned the vim model essentials somewhat well, there's no reason not to adjust it to your personal needs and preferences. One shouldn't aim to target the lower common denominator, even if "plain vi" is pretty high as such. Although I don't exactly know what's the case with C-l and C-h if you also use w and b comfortably, there's always a case for meaningful helpers.
If you are worried about ssh'ing to foreign machines without your vim configs, worry no more. Vim has a satisfactory remote editing capabilities; edit over SSH/SCP locally.

Related

Should I invest Time Learning Emacs? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I know that this question has been asked many times before. However, I want to take everything that I have read about Emacs/Vim from other posts, give my own understanding of the situation, and request feedback from senior developers.
Here is what I see as the advantages of each type of IDE:
Advantages of Modern IDE
Many features work with little hassle or need to configure like: Text
completion / autogenerating closing tags Useful warnings tailored to
the language
Solving issues like the ones above often require a
significant time investment. I know that you become faster at finding
and installing the packages you need, but it seems like every
extension you need in a traditional editor is much more readily
available or already built-in in modern IDE / Code editor.
For compiled languages like Java, IDEs like IntelliJ seem to have a clear
advantage in the way they are able to analyze code and for the robust
debugging they offer. As far as I can tell, even if you spend a lot
of time configuring Emacs, there is no substitute for IntelliJ even
no matter how much time you invest.
Emacs/Vim Advantages
Though there is a lot more time investment, it seems like there is a strong consensus that the time investment has a significant payout for many developers. I do not necessarily even know these benefits, but I just know that Emacs/Vim is a very powerful and loved tool by many many highly experienced devs.
Extensibility
Availability (you can use either in a terminal very easily)
Great for SSH
Full org mode (versus the much more limited org mode in VSC)
Model-editing / Vim keybindings can make editing much faster once you learn it. Also, key chords in Emacs can make you much faster and keep you on the keyboard.
Related to above, but it seems that the more you commit to Emacs, the more you can get out of it because of the extensibility. Whatever your work flow is, usually there is a way to set up Emacs to take care of the whole nine yards for you.
I am guessing because of the above, it probably helps with your focus. You can keep everything inside emacs.
So my only big question is, "Do I have an accurate understanding of the advantages of each IDE?" A harder to question answer for me is, "Do I want to invest more time in learning Emacs or Vim?" (sidenote: will probably go with Doom Emacs) Right now I have been programming for two years. I am currently learning Javascript to help me get employed and will be focusing on that for months in the future. I keep going back and forth on whether I should just go with VSC and focus on Javascript or if I should learn Emacs concurrently.
I would recommend activate a Vim plugin within your IDE. That way you will learn bit by bit without affecting your productivity. After some time you can judge by yourself if it is worth learning more and go full Vim or just use the IDE. I use Vim for 5 years and I still have to take a look at the Vim documentation everyday. But I do it because it is fun to learn to do complex text manipulation with few strokes. If Vim does not suit you, try Emacs, then. But only trying each one will tell you what fits your style.
Here is a quick intro to Vim

Should a Project Tree plugin like NERDTree be used alongside a fuzzy-searcher plugin like CtrlP? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Before you light all fuses; I know this might come off as quite opinion-based. I am asking for functional differences, not "is X better than Y and why".
I have been using fuzzysearcher-plugins for some years now, as my previous employer quickly made mockery of me for "needing to actually SEE my files". I've been getting along with CtrlP for a while, but more often than not, when I see a Vim-user whip up his environment, there's NERDTree.
Am I missing out on any important functionality?
Depending the the nature of your project the structure could be very important. It maybe helpful to see you project files. However the use of an always open NerdTree instance is probably not worth it. Please see Oil and vinegar - split windows and the project drawer.
As for exact functional advantages of having a file explorer always open, I seriously doubt it. I think you would get much more usage out of something like projectionist and of course using a fuzzy finder like you are currently doing. Personally I use Tim Pope's vinegar so that if I need a file explorer it is a simple - away.
First you have to understand that Vim already comes with a rather powerful file explorer called netrw (:help netrw) so there's actually no real hard need for another file explorer plugin like NERDTree. But netrw is not really designed to be used as a "side-panel" like those found in other editors and IDEs: "desire" for that feature is what prompted the creation of NERDTree which closely mimics those "side-panels".
Both NERDTree and netrw give you a familiar file navigation interface that's quite handy when you don't have a good knowledge of the project you are working on: they give you a comfortable experience and therefore are quite valuable.
When you know your directory structure well or use alternative means of navigation (I'm thinking about tags), a file explorer — especially one that's "always on" — is not that useful and it's quite legitimate to prefer the simple :e and/or :find or the higher level abstraction provided by CtrlP, FuzzyFinder, Command-T and friends.
I usually prefer :e, :find, :tag and related commands to using a file explorer but there's always a time when using one is more efficient and, when that time comes, netrw is only an :Ex away.
Both navigation methods are not mutually exclusive at all.
A core aspect of the issue worth discussing, IMO, is the perceived need for such a "side-panel". Do we really need to have a list of the files in our project visible at all times? What's the benefit of such a feature when you consider that you never look at it and, really, never use it unless you need to open or interact with some files? Since you have to switch your focus from the editor to the file explorer anyway, why not simply, well… "open" the file explorer when you actually need it? Of course, the NERDTree window can be toggled but, most of the times, it's just left open. Simply because that's what most people are used to.
Now, comformity, lazyness and ignorance also come into play: NERDTree is listed as a "must have" in every blog post and, AFAIK, it's also provided by default in every crappy distribution so people often install it right away, without even knowing about netrw. The same could be said about CtrlP, of course.

How to set up this specific vimrc configuration [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I don't have much experience and I hope you guys can help me, because nobody around me can.
I am starting to work with Vim and I am setting my vimrc now, but that's a lot of work, and I want to focus on learning how to use it, and not waste my time for now on configuring simple stuff like text highlighting or indentation, things that everybody has... So I want to use this vimrc https://github.com/spf13/spf13-vim which is generally provided by Steve Francia.
The problem is that he uses gitHub, and I want to have everything locally on my machine, can you tell me how to do that? Including all the plugins, of course.
... that's a lot of work ...
Be prepared to continually spend some time to learn new Vim skills and improve your configuration (or chose a different editor / IDE that offers a more carefree, but also more restricted experience). Bram Moolenaar, the creator of Vim, has made a compelling case for good habits of text editing. Trust me, it's not a waste of time, but you need to overcome your need for instant gratification.
I would suggest just turning on the indent and syntax features you mentioned, and call it it a day. Don't worry right now about extensions you don't need that load themselves.
$ cat > $HOME/.vimrc
syntax on
filetype plugin indent on
^D
$
Yes, I use something like his setup (I use Pathogen) and sure, it is kind of cool to just be able to clone a git module into my .vim/bundle directory, but that's an elaborate configuration that's just a distraction for you right now.
The absolute minimum you need for programming in Vim is in the accepted answer. I'd add set hidden and a few others to the mix but you don't need much more. Especially weird shortcuts that hide native features or useless Git integration plugins.
Don't install any plugin from the start, actually, especially piles of crap like that kind of "distribution". Follow $ vimtutor, multiple times if needed. Learn how to use :help. Don't copy anyone else's vimrc verbatim and, if you take something from a random vimrc on the net, read the relevant part of the documentation to be sure that you understand what it does, how it does it and why. Your ~/.vimrc and ~/.vim/ will grow and shrink with you, as you go. That's how it's done.
If you are looking for beginner-level info, LearnVim is a rather nice introduction to Vim that you install as part of Vim's documentation. I'd suggest you install it and read it carefully: it's opinionated but full of low-level information that will doubtlessly help you in the future. I sure would have loved reading it when I started.
Like Ingo said, if all that seems overwhelming nobody will mock you for deciding to use another editor/IDE. Of all my team, I'm the only one who uses Vim (hell, I don't even use it for everything) and the code we write is equally good and/or bad.
Anyway, if you really want to go the "distribution" route, you'll have to learn Git and Github's basics and follow the instructions provided by the distribution's maintainer.

What are the benefits of learning Vim? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
As a programmer I spend a lot of hours at the keyboard and I've been doing it for the last 12 years, more or less. If there's something I've never gotten used to during all this time, it's these annoying and almost unconscious constant micro-interruptions I experience while coding, due to some of the most common code editing tasks. Things like a simple copy & paste from a different line (or even the same line), or moving 1 or 2 lines up or down from the current position require too much typing or involve the use of the arrow keys ...and it gets worse when I want to move further - I end up using the mouse. Now imagine this same scenario but on a laptop.
I've always considered learning VIM but the amount of time needed to master it has always made me want to step back.
I'd like to hear from people who have learnt it and if it ends up being one of those things you cannot live without.
At work, I use VS2008, C# and R#, which together make editing code a lot faster and easier than ever, but even so I think I could enjoy not having to use the mouse at all.
And not even the arrow keys.
I've been using vi and vim also for some 20 years, and I'm still learning new things.
David Rayner's Best of Vim Tips site is an excellent list, though it's probably more useful once you have some familiarity with vim.
I also want to mention the ViEmu site which has some great info on vi/vim tips and especially the article Why, oh WHY, do those nutheads use vi? (archived version)
Could I live without it? Easily.
Is it useful? Yes.
Reasons for Learning
vi is guaranteed to exist on all Unix systems and exists on most Linux ones as well. That kind of broad coverage makes learning it worth it.
It's much quicker to use vi for a sudo edit:
$ sudo vi
Also, GMail uses vi-ish commands for selecting & moving emails around!
You don't have to be a master.
Just learn
The basics:
How to switch from command mode to insert mode i
How to switch from insert mode to command mode Esc
How to navigate up a line in command mode k
How to navigate down a line in command mode j
How to navigate left a character in command mode h
How to navigate right a character l
How to save a file :wEnter (write)
How to exit without saving (in command mode) :q!Enter
How to Undo u
How to Redo Ctrl+r
You can combine writing and quitting (in command mode): :wqEnter
From there the rest will just make you faster.
Running through vimtutor only took me 30 minutes, which was enough to get familiar with vim. It was worth every second of it.
If you're a programmer who edits a lot of text, then it's important to learn an A Serious Text Editor. Which Serious Text Editor you learn is not terribly important and is largely dependent on the types of environments you expect to be editing in.
The reason is that these editors are highly optimized to perform the kinds of tasks that you will be doing a lot. For example, consider adding the same bit of text to the end of every line. This is trivial in A Serious Text Editor, but ridiculously cumbersome otherwise.
Usually vim's killer features are considered: A) that it's available on pretty much every Unix you'll ever encounter and B) your fingers very rarely have to leave the home row, which means you'll be able to edit text very, very quickly. It's also usually very fast and lightweight even when editing huge files.
There are plenty of alternatives, however. Emacs is the most common example, of course, and it's much more than just an advanced text editor if you really dig into it. I'm personally a very happy TextMate user now after years of using vim/gvim.
The trick to switching to any of these is to force yourself to use them the way they were intended. For example, in vim, if you're manually performing every step in a multi-step process or if you're using the arrow keys or the mouse then there's probably a better way to do it. Stop what you're doing and look it up.
If you do nothing else, learn the basic navigation controls for both vim and Emacs since they pop up all over the place. For example, you can use Emacs-style controls in any text input field in Mac OS, in most Unix shells, in Eclipse, etc. You can use vim-style controls in the less(1) command, on Slashdot, on gmail, etc.
Have fun!
It's definitely worth the effort.
There's one obvious reason that anyone who uses Vi(m) will tell you, and two others that people never seem to mention.
Here's the obvious one:
vi is at once ubiquitous and incredibly powerful, and by learning it once, you gain the ability to exercise that power on pretty much any computer that has a keyboard.
And these are the lesser known reasons to learn Vim:
It's not half as much effort as you think it's going to be. Run through the Vim tutor once (vimtutor at a shell, or in Windows run it from the Vim folder in the Start Menu), and you'll already be well on your way to competence, and it's all downhill from there. I was up to the level where I could use Vim at work without taking any noticeable productivity hit within less than a week's worth of lunchtimes.
It's fun! Editing text is like a game to me now. I actively enjoy it--which is pretty ridiculous, when you think about it.
There's also two good reasons not to learn Vim:
It's addictive, and you'll find yourself wishing you could use Vim commands in all your computing, and cursing whenever you can't. Fortunately, at least for some situations, there's ways to get around this.
Again, it's addictive, and although you won't lose any productivity from actually using Vim, you will waste hours searching for good tips to make your Vim experience even better, and reading the Vim tag on Stack Overflow.
It's definitely worth learning either vim or emacs. It's also worth learning to touch-type. In both cases the reasons are the same: your thinking is no longer interrupted by the mechanical process of getting your code onto the screen.
As to how to start, just dive in and start using vim for everything.
P.S. The emacs-vs-vi debate is endless. I've been using emacs for 26 years. If I started again today I'd learn vim because (a) it's gotten better and (b) there are many fewer modifier keys (Ctl-Alt-V, anyone) and vim users seem to get much less typing injury.
You can get good functionality out of vim by learning the meanings of only 16 keys: ijkdbw9:q!%s/nNEsc. You can do the bare bones with just i:wqEsc.
The first two keys you need to know are: Esc takes you to command mode (the mode you start in), and i takes you to insert mode (normal typing).
To save you need to
get out of typing mode (Esc)
type a colon :
type lowercase w then Enter
To save-and-quit you need to
get out of typing mode (Esc)
type a colon :
type lowercase wq then Enter
To not-save-and-force-quit you need to
get out of typing mode (Esc)
type a colon :
type lowercase q! then Enter
To learn more you can run vimtutor at the command line. It's a medium-length, well-structured lesson.
Beyond i and Esc: you can replicate or surpass some MS Word functionality with only jkwbd3:%s/nN.
b takes you back a word (Ctrl+←)
w takes you forward a word (Ctrl+→)
9w takes you forward nine words
db deletes the preceding word (Ctrl+Backspace)
d3b deletes three preceding words
9j moves down 9 lines
/ ornithopter Enter takes you to the next instance of the word "ornithopter", then n and N to the next and previous occurrence of "ornithopter" respectively.
:%s/confounded/dangfangled/ Enter substitutes every "confounded" with "dangfangled" (like find and replace all in MS Word)
Any of those should be run in "command" mode (Esc), not insert mode (i).
I recently switched to VIM, and I think it's worth it. If you need to "just get something done", you can always stay in insert mode, where vim is (mostly) like a normal text editor.
I've noticed that things that didn't use to bother me, like reaching for the arrow keys, now feel wrong and too much effort. It's definitely decreased my hand motion and usage of the mouse, which is good for both ergonomics and productivity
It depends what you want to do with VIM. It doesn't make sense to learn it only because many people cannot live without it.
When I was working a lot on UNIX environments, I couldn't live without it. Even when VIM was not installed on a UNIX machine, I could at least use vi. You could always count on it -- even if the machine is not yours (that from the customer).
Now I program in C# and mostly work on windows environment. I have installed VIM on my PC ... and I don't need it.
Evaluate if you really need VIM and if it supports you in your "flow of work". Try it out. Play with it. If you think you need it, stick to it ... the learning curve is very steep.
I learnt vi because I had to.
My crazy teacher forced us to learn to program in C using a terminal to an AIX system.
It was a real pain, but worth it.
Today, I only use vi for quick edits or small programs.
When I have to go for a project, I rather use and IDE. In my case IntelliJ idea is very good at the task, because I can code for hours without grabbing the mouse.
I don't know how much shortcuts does VS2008 has, but if they are as discoverable as Eclipse, I think you are in trouble go for vi.
If you DON'T edit code outside the IDE and your IDE has good shortcuts, you better learn those, and then, go and learn vi anyway.
:)
I've used vi/vim for 25+ years. If you already know some command-line editor, then maybe you don't need to learn vi/vim. But if you don't know any other command-line editors very well, it's worth learning it. It's pretty easy to be productive in vi/vim with little effort.
I use VIM pretty much exclusively now.
I used to use Vim for editing and VS Editor for debugging. This probably seems a bit crazy, but I found the Vi paradigm (macros, home key based editing etc) such a boost to my productivity, that editing in VS was paintful.
Thanks to Viemu, I don't even have to do the switching any more. It is not the perfect solution yet (code completion is sometimes not as elegant as in native vim and the macro recording isn't perfect), but it is much better than switching back and forth constantly.
The learning curve for Vim is probably exaggerated. I think once you get into it, it is pretty intuitive.
My job forced me to pick up vim and it has quickly become second nature. Now my complaints are about IDE's that do not have vim emulation or plugins. I do notice that the esc key has become my enemy outside of vim.
I did find several emulators for vi within Visual Studio:
http://code.google.com/p/vim-visual-studio/
Firstly good vi(m) knowledge will save you the time you have to hustle to do emergency editing of config files on a server under seige. It can hold up on a laggy ssh connection.
Admin stuff aside vim's input method will be your best defence against carpal tunnel if you use it effectively with an ergonomic keyboard.
The best way to see the point of vim is to start a casual project at home, unplug your mouse and tape over your arrow keys.
And read the help
Two advantages of vi/vim:
it is very light-weight
it is installed on almost every *NIX system
I am maintaining a very big linux project on the remote computer. There is no choise to use Eclipse or similar GTK based IDE. I've been working there for 3 years.
And I set my vim just for this project. And still tweaking.
Now I can do any thing from the Vim: source control, sql, debug, compile, browsing - really fast browsing over 1Gb source code.
Visual Studio or Eclipse couldn't handle all of this. And If I had a choice I would'n change Vim to other editor or IDE.
I learned Vim. It wasn't too much effort. Now I absolutely love ci" ci( cw V:s/from/to/g
I'd say vim is definitely worth learning. I picked it up last summer, and it is now my editor of choice for just about everything (java is a stretch, but doable when I don't need extensive analysis support). As everyone has already affirmed, it is a wonderfully efficient tool.
For what it's worth, I only learned a fairly small subset of vim's features (which took a day or two) from a graphical tutorial, and a few odds and ends from here (long read), and the search and replace functionality, and I was hooked. I've learned things since then, but at my leisure. I'd say the learning curve flattens out at this point, but then, I was using it pretty heavily and was surrounded by others who were, too.
I'm in the same situation as you, and as a beginner to Vim I originally found it a little daunting - the learning curve seems steep.
From what I've learned in just a few hours I'm already feeling like I won't be able to live without it.
Here are a few links that I've found for useful Vim screencasts to show you what it's capable of.
A good bit of advice that Bram Moolenaar (benevolent dictator of Vim) gave in that last link is that it would be inefficient to try to learn every single command and function, just figure out what it is that you're doing that isn't working very well, look for a way to make it more efficient and then make it a habit.
Yes, definately take the time to learn at least a bit of 'vi' and 'vim'. It travels very well.
You'll never be stuck when you are faced with a customer Unix/Linux/Mac system that you don't have install capabilities for. Even on Windows (if you do have install capabilities) 'Vim' is free and easy to install. (As opposed to investing your learning curve purely in something like UltraEdit, which although an excellent editor might not be available for you all the time...).
Learning vi can set you up for learning other tools like 'sed', and regex in general: stuff that is generally transferable.
Plus if you want to be a proper geek, you just simply need to know 'vi/m' or you'll look like a faker ;-)
I think it's definitely worth the time and effort to learn vim. To me, it makes typing and navigating around text so efficient, it's hard to imagine going back to emacs or ctrl/shift/alt/meta key combos.
Don't get intimidated by all the fancy features of vim. Once you've used it enough, you'll figure out which commands you use the most, and you'll figure out which things you can forget about.
The amazing ubiquity of Vim, and the even more amazing ubiquity of Vi-clones in general, on Unix systems alone is enough to make it worth learning.
Besides that, the whole Vi-style thinking is something that I really think has made me a bit more productive. For a person not used to modes such as the command mode and insert mode, it seems a bit excessive to have to enter a mode just to insert text. But, when one has been using Vim for a few months, and has learned quite a few tips and tricks, Vim seems to be an asset that seems to be worth it.
Of course, the Emacs crowd says the same thing regarding Emacs-style thinking, but I gave up on learning Emacs because Vim was simpler and did the job for me.
I learned to like vi after watching someone who was very skilled with it navigate around to make edits at an insanely fast clip. You really can code quickly with it. Another reason I like it is that sometimes I find that mousing around in an IDE really hurts my hands after a while and vi provides a nice change. As others have mentioned it's also almost always available on unix systems and works well even over lousy connections.
One thing that I haven't seen mentioned is that knowing vi has the added benefit of "geek cred" in some circles. I can think of at least a few people who chuckle when they see a new programmer fire up nedit to make some changes to a file.
Don't be scared off by the number of commands, I've not met anyone who used more than a couple dozen at most. I find it indispensable, because when I'm thinking about code I'm thinking about text, moving to thinking about mice just messes me up. The big tricks, I think, are to learn it a little at a time, and don't be hesitant to play around - the undo features is great for exploring its behaviors.
Also, if you get deeply into it, vim is scriptable. The possibilities are literally endless.
(Yes, all of this applies to emacs too...)
I was happy at my textpad and ecplise world until i had to start working with servers running under linux. Remote scripting and set up of config files was needed!
It was hard at the begining but now i can easily set up and tune up my servers.
You might want to learn vim because you might not be happy with the editors you're already using.
You might want to learn vim because many people say it is cool. Just look how many answers you've got to this question.
I will provide an additional reason for learning vim. It has a reputation for the quality and the completeness of its docs. So you will find most answers to your questions in its help system as soon as you will manage to stick the proper keywords in your help queries.
To learn vi(m) fast one must first understand the whole design.
Vim has a great set of cursor-movement commands, check a few (X is a character, # a digit):
j k enter arrows
0 $
w W b B
ctrolD crtolU
ctrolE ctrolY
H M L
fX FX tX TX , ;
%
gg G
n N
mX 'X ''
and many more it would be boring to enumerate. Many of these support a count before the command, like 4j to move 4 lines up.
Now, back to the design, you type a command like d for delete followed by a cursor movement and the command applies to the piece of text from the cursor position till the movement end. For example H moves to the top of the screen, dH deletes to the top of the screen and cH changes (replaces) to the top of the screen.
This design is quite powerful. It also reduces, or organizes, what you need to learn.
Definitively the first step is to learn a few cursor movement commands. Say,8 or 10 at first. Then you are almost done.
Learning something new is always worth the effort, IMHO. I suggest you print out a cheat sheet and force yourself to use it day-in and day-out.
Vim is definitely worth learning to partly summarize what has been stated previously here are the main reasons:
Vi/Vim can be found on most unix systems.
Vim allows you to easily code without taking your hands off the keyboard.
If you plan you configure anything in a unix based system likelihood is you going to be editing a fair few config files, therefore you'll want to learn a terminal based editor, of which vim is one of the best (sorry emacs).
Vim compiles/has precompiled binaries for almost every OS out there. No need to post "I need a textmate alternative for [insert OS]", you'll have Vim instead!
There are a lot of good plugins out there to add alot of functionality, such as in-editor cvs diffs, although some of these require a fair amount of tinkering.
Also on a side note if you find you like the Vim key bindings, there are also IDEs which include vim bindings in their editors for simple commands, for example Komodo Edit.
For help on learning Vim, try typing 'vimtutor' into your terminal and follow the instructions. There is also a book which is particularly good Hacking Vim
No. Learning vim is worth more than the effort.

What is the best way to force yourself to master vi? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
A good while ago, I read an article by the creator of viemu, clearing up a lot of the misconceptions about vi, as well as explaining why it's a good idea (and why it's been very popular for the last 30 years+). The same guy also has a great set of graphical cheat sheets that teach the basics a few bits at a time.
I'm convinced.
I've been convinced for the past 2 years in fact. But I still really haven't gotten around to force myself to learn vi as my primary editor, the learning curve is just too high. When I get down to work, acceptable but immediate productivity (using my current editor) has so far won over tremendous productivity farther down the line (using vi).
Does anybody have any good tips to help get past the learning curve? It can be straight out tips, some other tutorial or article, whatever.
Edit: Note that I'm aware of the vim/gVim, Cream and MacVim (etc.) variants of vi. I kept my question about vi to refer to the vi family as a whole. Thanks for all the great answers.
Update (April 2009)
I've been using Vim (more precisely, MacVim) in my day to day professional life since last December. I'm not going back :-)
Good luck to everyone in their Vim mastery.
First of all, you may want to pick up Vim; it has a vastly superior feature set along with everything vi has.
That said, it takes discipline to learn. If you have a job and can't afford the productivity hit (without getting fired), I'd suggest taking on a weekend project for the sole purpose of learning the editor. Keep its documentation open as you work, and be disciplined enough not to chicken out. As you learn more, become efficient and start relying on muscle memory, it won't be as hard to stick with it.
I've been using Vim for so long that I don't even think about what keys to press to search or navigate or save. And my hands never leave the keyboard. To use Vim is one of the best choices I've made in my programming career.
The first thing I'd do is lay a piece of paper or a book over your arrow keys and your ins/home/end/pgup/down keys. Those aren't needed in Vi.
Next I'd get used to hitting ctrl+[ whenever you're told to hit escape. It's much faster and you won't need to take your hands off the keyboard.
Then I'd watch my screencasts:
http://www.youtube.com/watch?v=FcpQ7koECgk
http://www.youtube.com/watch?v=c6WCm6z5msk
http://www.youtube.com/watch?v=BPDoI7gflxM
http://www.youtube.com/watch?v=J1_CfIb-3X4
Then, just practice practice practice.
edit
The reason for avoiding the arrow keys is that they slow you down. One of the largest benefits of Vim is the speed it allows you. The arrow keys also prevent you from really embracing the modal nature, which is very powerful when mastered.
Step 0: learn to touch type. Seriously - if your fingers don't know where the keys are then vim is going to be a pain. And even if you reject vim, touch typing will improve your programming (ask Steve Yegge ) by making the mind to monitor link friction free. There is a lot of software that can help you improve your typing.
Step 1: use vimtutor to get you started. It is in gvim (under
the help menu I think) or you can just type 'vimtutor' at the command
line. It will take 30-45 minutes of your time and then your fingers will
know the basics of vi/vim and you should be able to edit files without
wanting to hurl your keyboard out of the window.
Step 2: use vim everywhere. See this
question
for tips and links for using vim and vi key bindings at the command
line, from your web browser, for composing emails, in your IDE ... You
need to use vim to embed the key bindings in your muscle memory.
Step 3: learn more about vim. You will only have scratched the
surface with vimtutor. You can watch this
video or
read this article (both about
the "Seven habits of effective text editing". You can
read
about
tips
and
tricks
on
StackOverflow.
You can browse vimtips. Learn a
litle often would be my advice - there is so much out there that
sticking to bite-size chunks will be the best way to make the knowledge
stick.
Step 4: Profit :)
I've been a on-again, off-again user of vim throughout the years (doing the occasional sys admin job). I just recently started spending more time doing my programming work in it. I'd suggest starting with gvim too. It integrates well with most OS environments, and (even better), you can fall back to the mouse when you need to :).
To get going with vim, run through the vimtutor (bundled with gVim) once or twice (takes an hour or so). I can't overstate how helpful it was for me! Especially the first parts about the different ways to move through a document, and how edit actions are recorded with motion commands, etc, etc. After that, things will be MUCH clearer.
Then, start doing quick, minor edits with it (notepad-replacement stuff) 'till you are comfortable enough to do useful editing at a rapid clip. Then try doing your day-to-day work in it. You'll find yourself pining for the "repeat last action" command in other editors in no time!
You asked for good tips to help get past the learning curve on the vi text editor. Many of the previous answers suggest you use no other editors. I think that is good advice. Switching to vi from a more graphical editor requires a change in mindset. It requires thinking in terms of commands, rather than visual changes.
I used nothing but vi for many years and believe the only way you can be productive is to memorize the commands you regularly use. The way I did this was to make a short list of the most common keyboard commands. I grouped and color-coded these commands by function, i.e. Moving the Cursor, Editing, Searching, etc. I was careful to only include the most commonly used commands I did not know. The idea is to create a quick reference that is also an aid in memorization – not to replace the available help screens. Then I printed this list and taped it to the wall behind my monitor so I could see it easily. (The graphical cheat sheets you mentioned might work better for some, but are probably a better reference source than a memorization tool.)
Here's the key. As I became comfortable with one of the commands, I drew a line through it with a pencil. I could still see it if I needed it, but it was symbolic to me that I had mastered that command. That gave me confidence and motivation as I could see regular progress. Once I had most of them crossed off, I removed them and added some of the more rarely used commands. I continued this process until I was satisfied with my command of vi. I knew I had reached that point when I realized I had not crossed off any commands or even looked at the list in a long time.
A couple years ago I had need to work on a UNIX platform where vi was the only editor available. I bought a little pocket reference book on vi, but hardly used it. I ended up making lists and posting them on the wall as I did the first time I used vi. By the end of the first week, I was very comfortable even though it had been five years since I had used vi.
force yourself not. the path to mastery love is.
For me VI is a good emergency editor, but not something I want to use if there is any other alternative available. I realize this is not for everyone though, I'm not saying it's horrid or anything, I just personally prefer a discoverable UI.
But you really have to know VI if you do anything significant in Linux!
So just learn the basics:
i=insert mode
esc=leave insert mode
:wq=save and quit
:q!=don't save and quit
x=when not in insert mode, delete the character.
/=search
That will get you through any editing emergency. There is nothing you can't do with those few commands (and navigation of course). The rest you can "Tack on" as you need them.
Keep a reference or book available though--when you NEED to use VI, you probably won't be able to browse the web--but the man page may be somewhat useful.
You should start with vim (Vi IMproved) and especially its GUI - gVim. The GUI has menus and on Windows you can use the copy, cut and paste shortcuts, so you can replace Notepad immediately. And since the menus display the shortcuts (vim commands) you could learn a lot.
Another thing that you should do from the beginning is to configure vi for your needs. For example, you can transform vim into a Python IDE. By doing this, you'll have no excuse for using another editor, because vi will offer you everything you need.
Every time you're doing a complex editing task, keep wondering if there is a more efficient way to do it. Most times, when it's something that you can describe in simple terms (like "swap paragraphs of text" or "delete everything after the X character in commented lines"), it's something you can do in just a couple of keystrokes in vim.
There are some key features that are extremely useful, and you'll end using all the time. The ones I love the most are:
Block selection (Ctrl-V)
Macro recording (q)
Virtual editing (:set ve=all)
Regular expressions
Piping to external Unix programs
Key mappings
Autocompletion (C-p, C-x C-p, C-x C-f)
The operation+movement combination (this is amazingly powerful)
Ask other programmers what features they find most useful and adopt the ones that fit better your brain. Steal ideas from other people's .vimrcs (here's mine)
delete all other text editor apps.
Then you will have to learn it.
The simplest way to force yourself might be just to remove all the other editors from your machine. Get rid of temptation :)
I wrote a guide to efficient editing with Vim a while back. You may find it helpful.
I'd step back for a minute and ask yourself "why do I want to learn this editor? What makes me think it'll be faster or better than my current text editor?" Then learn those features that will make Vi(m) indispensable to you.
For instance, Vim's CTags integration is completely indispensable for me. I work with a very, very large codebase, and the ability to jump to a function or class definition in one keystroke (regardless of which file it's in) is an absolutely killer feature, one I have trouble working without.
Use your .vimrc file to make macros that automate common tasks.
Your autopilot editor-chooser will pick the editor that will get the job done quickest and with the least amount of mental effort. A little prep-work will ensure that editor is Vim. :-)
EDIT: I've created a flashcard set over at the online spaced repetition site flashcarddb.com, in case you're interested ...
Use a spaced repetition flash card program such as mnemosyne, supermemo, or anki to incorporate learning and retaining new commands into your daily routine. It's not enough to be using vim as your daily editor. To master it, you have to be storing those codes in your head, laying in wait for the time when they're the ideal solution to the task at hand.
Maintain a .vimrc with customizations
Write or edit a vim plugin
Two things that will greatly improve your vi skills:
Practice, practice, practice
Nethack
My suggestion: start small. Just start by memorizing a small set of most useful commands. When I started vi, these were my top 10:
(Esc) to return to command mode (most important!)
a to add text after cursor
A to add text at end of current line
x to delete 1 character
dd to delete 1 line
R to replace text (overwrite)
u to undo
:q! (Enter) to quit without saving
:w (Enter) to save
ZZ to save and quit
A lot of basic editing can be done using only these commands. Once you get comfortable, the rest don't look too difficult.
BTW, I'd like to add that I used to rely on vi for my primary text editor, but now only if I have to. In my case, productivity is better when I use tools like Emacs or Visual Studio (please note: "in my case"). Try more than one tool and choose the one that helps your productivity the most. Good luck!
It sounds silly, but playing roguelike games (such as Nethack or Angband) is a fun way to get comfortable with using the h/j/k/l keys for cursor navigation.
Write down all the short-cuts and features that you use in your current editor while you're using it at work. Then sit down on Saturday morning and using Google and stack overflow find out how to do each one of those in vi. Probably best if you use a sheet (or sheets) of paper for this.
Now disable/delete the other editors at work so that it'll take you longer to find and re-install them than look at your comparison sheet and do it in vi - i.e. you have no choice.
Lastly, publish your list of crossover shortcuts from your old editor to your new one on your blog.
Good luck!
Don't use X11?
$ sudu rm /usr/local/bin/emacs
Change your login shell to vi?
First, force yourself to use ed, then vi will seem like a luxury?
Use the vi key bindings in bash?
Just start using vi all the time?
It seems to me that learning an editor isn't terribly different from learning a language. Immersion works best.
I use vi for really quick edits or when I can't use X11 for some reason, but I live in emacs. Really powerful editors are worth taking the time to learn.
My recommendation is to come up with some simple programs and write them, start to finish, using VI.
Odds are, you will be too frustrated at first by the learning curve to force yourself to use them at work or in any time-sensitive environment.
I've done this before to get familiar with environments/editors, and it works pretty well.
If you are having problems coming up with things to write, I recommend redoing projects you did in school (or anything else that you've done previously). This method has the added bonus of letting you see how much of a better developer you have become. :)
Edit: forgot to mention that you should do this entirely from the console to avoid any temptation to use the mouse!
I remember when I first started learning emacs, it was after I was already very comfortable with Vim, and I was in the same or similar boat that you were, where I knew how to get a lot done in another editor, so as I started using emacs, it was always painfully slow.
However, I think what you'll have to do is just absorb a little bit of the pain, and always, always, ALWAYS make sure that you look up the documentation for doing something that you know you can do in your previous editor, such as moving to the end of a line, or selecting a region of text.
It also helps if you have a local vi-expert on hand that you can ask questions, or if you're like our company, you promote pair programming. That way when you're trying to do something that should be easy, you can simply ask someone, they'll show you how, and if you're using the editor regularly for a few weeks, you shouldn't have to ask more then a couple of times before it becomes second nature.
If you don't have any local resources, there are plenty of books/tutorials/reference sheets online that should be able to answer most of your questions.
Ultimately, learning Vi is like learning other skills, there's no silver bullet, and you'll have to accept that, for a while, you're going to be less productive in it then your current editor. Just keep telling yourself, "Other people have been able to learn Vi, and I'm at least as smart as them" (That's what I tell myself anyway :) )
The main reason for me to use vi is ssh (or Putty on Windows): When you're logged into a Unix server remotely, then vi is always available. And it works with VT100 when neither the cursor keys nor backspace/delete are mapped.
Also having a book like VI Editor Pocket Reference helps greatly.
gVIM has a really good tutorial (link in the Start menu group).
I found working through that helped to get over the initial learning hump; and then switching my Visual Studio to ViEMU helped me hone my VI skills.
Also, the screencasts at http://vimcasts.org/ are great!
You could get your hands on one of the original Happy Hacker keyboards (no arrow keys) and place your (wireless) mouse out of reach each time you start editing.
It's easy to write out a big list of commands/shortcuts, but it's difficult to remember them all without practice.
Focus on one new command at a time. When it becomes automatic, say after using it for a week or two, add another to your repertoire.
You'll be taking the long way around to accomplish certain things in the short term - these are obvious opportunities for new shortcuts to learn.
In my experience it was easier when I tried not to take on too much at once.
My number one suggestion: learn to type fast, without needing to look at the keyboard.
If you can't touch type and are always hunting-and-pecking for the colon or the hjkl or :%s/foo/bar, forget about it. Typing can be faster than using the mouse, but if that's not the case for you, vi's not going to work.
But combine good typing skills, ssh and screen and vi will be natural.
Face the fact that it will create an immediate performance hit. When learning a new tool you need to be able to do something that you know how to do with other tools so the problem isn't your problem. After using the new tool a while it will disappear and you will be only focusing on the underlying problem.
With something like vim (as others have said, vim is vastly superior to vi) it is important to reread and browse the documentation periodically. The interface is completely undiscoverable without it. With each new reading you will see a feature and say, "ah ha, that would have solved this issue I was trying to figure out last week", and will file it away in your brain. Solutions connected to real-world problems that you've had are much easier for you to remember than random shortcuts.
In the end you can use vim with a fairly small subset of it's features, so don't be overwhelmed with all the bells and whistles. Think of all the features in Word, do 99% of the people use them?
ESC gg=G to reindent code and :retab to convert tabs to spaces or spaces to tabs was what hooked me to vim. So actually you don't need to be forced to use it, you just have to learn when it can help you increase your speed.
Go through vimtutor.
Start using vim for simple editing, like config files or html. Learn the commands as you need them.
Search google for a good .vimrc used by someone who uses a toolchain that resembles yours. Turn on syntax highlighting. Find a nice color scheme.
Learn macros because Vim is the best for automated tasks and snippet insertion, like formatting a few words into a complex XML tag or converting a CSV to an HTML table.
You might want to start out with Cream. Cream describes itself as "a modern configuration" of vim. Basically, it is a special version of vim which looks and feels like any other text editor for all practical purposes. But enable the "expert mode" and you have all the power and behavior of vim.
So you can start using Cream as a regular text editor and then experiment with the "expert mode" until you are comfortable enough to fully switch to vim.
Install gVim on all platforms you use.
Then run through the the vimtutor (:help vimtutor or vimtutor at the command line).
Watch the following lecture and follow its advice: 7 Habits For Effective Text Editing 2.0
I say you definitely want to start using it for all your editing. If you fear a loss of productivity then take a weekend to practice it solid (I once did this to switch to dvorak from qwerty and had my productivity high enough by Monday and managed to stick with it after).
It's worth the effort and you won't look back!
Personally, what I had to do was make sure that I could use the Vim key-bindings (or at least, close enough) in several applications. Having to completely switch how I edited text whenever I changed editors made it too hard to get the Vim editing style committed to muscle memory.
In my case, Viemu + vimperator did the trick.

Resources