148 points · by fredoliveira · 15y ago · 123 comments
edit: links...
http://en.wikipedia.org/wiki/Nvi
As a relative latecomer to vim, I think your distinction is worthy remembering. If you didn't start with vi, it's easy to assume that all the power and cool stuff is the result of improvements and not realize how much just plain old vi could/can do.
I'm really happy there are enough people who apparently appreciate (if not fully agree with) my comment to upvote it, though. I don't care about the karma, but happy to see signs of kindred spirits :)
There are more than just two of us nvi users, and we're in good company :)
edit: This suggests DragonFlyBSD is nvi too, which isn't really surprising: http://leaf.dragonflybsd.org/cgi/web-man?command=vi
or
:NERDTree
NERDTree is great for browsing your project and managing your files, but for opening files (when you know their names) you really can't beat the speed of Command-T/PeepOpen. They're in another league.
I don't know how people work without it.
I also stick to buffers rather than tabs (for terminal/gui consistency) and use buftabs, which I quite like.
You can also try using tabs to represent views of several buffers at once -- for example, I use one tab per app when working on Django code. I have the views, models, templates etc. in split buffers inside one tab.
For example, to this day I haven't figured out an easy, built-in way to copy from one vim window to another. I'd love to have some features of other editors have but the key bindings always hold me back.
Normally y is used to yank. However, you can prefix it with "x to yank in to register x. Then you can "xp to paste from register x. You have registers 0-9 and a-z for regular use. They work within a single window.
If you use register *, the register corresponds to your OS clipboard.
Read :help registers to learn more.
For editing multiple docs with vim, I find it's easier to use multiple buffers in the same window. Use :b <start of file name> to jump back and forth.
" Use ctrl + movement keys to move around windows
map <C-H> <C-W>h<C-W>_
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
map <C-L> <C-W>l<C-W>_2 ctrl-^ go to buffer 2
3 ctrl-^ go to buffer 3
ctrl-^ toggle this buffer with the last one, quickly switching back and forth.
[Of course, ctrl-^ is actually just ctrl-6, you don't need to use the shift key.]
If you have used a tiling window manager before, this is very natural.
I actually use tabs for multiple files and these keybindings for navigation:
nmap T :tabedit nmap H :tabprevious<CR> nmap L :tabnext<CR>
So I can go into a project dir and do vim -p .c* which opens the file in tabs and just navigate with Shift-H and Shift-L
nmap T :tabedit
nmap H :tabprevious<CR>
nmap L :tabnext<CR>huh? I run in 3+ windows (terminal shells) all the time and have done so for 5+ years. To cut and paste between windows I use filesystems copy and paste (select and middle click in X)
Vim is flexible and you are suppose to run it however works for you.
Also, the + register has similar intended uses.
com -range YY :<line1>,<line2>w! ~/tmp/cnp.txt
com PP :r ~/tmp/cnp.txt
Then :YY, :PP as appropriateGetting to the point, it is easy to copy and paste between windows using the system buffer. Just map copy and paste to something easy and familiar, say Ctrl-C/V/X, and go on with your life. I'm sure there is a "correct" way to accomplish what you are asking using registers, but quite frankly I don't know it and have never felt the need to learn.
(I know this assumes you are using a graphical Vim.)
q <macrokey> <do some stuff>; then q to stop recording. Then @<macrokey> to kick off the macro. Splendid.
The only problem is that they take a lot of practice before you get them right first time. After a while though, you learn to record them fairly quickly and they streamline your workflow. They also melt the faces of anyone pairing with you.
The best part is they get better with age. The more vim commands you know, the more opportunities you find for using them.
What do you find yourself macroing, generally?
$address = array(
'name' => '',
'line1' => '',
'line2' => '',
'state' => '',
'country' => '',
'postcode' => '',
);
That's a lot of commas and quotes etc. Nowadays I usually punch this into vim: name
line1
line2
state
country
postcode
Then I start on the first line and record a macro that wraps that word in quotes, then appends hashrocket, quotes, comma, and then moves to the next line. Run the macro 5 times with 5@<register> and the you get your array. (length (remove-if (lambda (b) (not (buffer-file-name b))) (buffer-list)))
42Interesting post so 1+.
As a side note the font used for the article does not render well on my Chrome browser. What are you using ? :)
Me, I compiled vim over ports and use it via rxvt-unicode or as gvim in an XQuartz session. That, and I run XMonad in that same session.
This way, my iMac at work almost feels like a Linux machine, and I can at least get work done here (if I'm not browsing HN.)
something like...
set shellcmdflag=-O\ expand_aliases\ -cNot sure why it wouldn't for you.
And maybe he's running gvim or from a login shell that hasn't sourced his bashrc.
I'll just come out and say it: my favorite editor is Visual Studio. Sure, it's slow to load and rather fat now, but I'm talking solely about the editing functionality.
With vim, I have to climb an amazing learning curve, regularly practicing all sorts of commands to achieve basic productivity. With VS, any command I don't recall is readily available through the menus. As I access it in the menus, I'm reminded of the keyboard shortcut, so it seems like a much more natural leaning experience to me.
If you only code every now and then, so you've got a lot of time between sessions to forget things, and not a whole lot of time in total, then something like Visual Studio which has good 'discoverability' is going to be better for you - as you say, if you get lost just go to the menu and it does a pretty good job of showing you around.
If, however, you are coding full time for a living, spending at least 8 hours a day 5 days a week coding (and let's face it, for most people on HN it's probably more like 12 hours a day 6 days a week), then spending even 2 whole weeks getting to grips with an esoteric but POWERFUL editor like Vim will very quickly pay off in terms of time saved and productivity gained.
Not my experience at all. It's a sea of confusion and pain.
However, over and over, on each of my projects that used Eclipse, inevitably multiple team members would have Eclipse crash and throw their entire workspace into disarray. Sure Eclipse might give you a 20% boost of productivity day to day, but that once every six months catastrophic disaster it would cause negated a lot of it.
Sometimes Eclipse would have trouble talking to the database, sometimes it would screw up its project file, other times it would outright corrupt files, cache things wrong, etc. This wasn't just for me, it was the experience many of our programmers had at various companies.
Now I'm working on my own project, and it's not near as large so I haven't felt the pain of not having magic-refactor. I've been forced to hack on a script to provide step-through debugging capability, and probably once a day I'll google to find the right keystrokes to do something, but I feel in the end, the effort is more than worth it.
I would disagree with the gp's assertion that there is an extreme amount to learn to obtain basic editing efficiency. A dozen commands or so and gvim so you can use the mouse should take you 20 minutes and a bit of practice to feel comfortable with.
Not to be overly pedantic, but your favorite IDE is Visual Studio, and you just happen to use whatever crappy editor component comes bundled with it.
If we could have full-blown Vim embedded inside IDEs instead of good-but-incomplete plugins which merely give you some of the key mappings, I'd be elated and couldn't see why anyone would stick with the Notepad-style editor which is the default.
While I really hated Visual Studio (and still do), this combination of tools really makes it worthwhile. It is an awesome marriage of a mediocre IDE, some substantial refinements to make it usable, and a phenomenal text editor. The nice thing about ViEmu is that is extremely full-featured. It even reads my entire .vimrc with all my customizations and personal magic!
So, I guess what I want to say is that instead of deciding between using an IDE and a text editor, you should actually use both! Real progress lies in synthesis, not analysis!
Personally, I love vim, and have been using it for years and years, and feel hobbled without it, but if you're satisfied with your tool, and don't long for something better, stick with it.
Not at all. If VS suits your needs, then rock on!
Personally, I enjoy the occasional vi/vim story here, as in reading the comments I almost always come away with several new ways of doing things in vim.
I think there's a better question to be asked, however. Given that programming involves a seemingly endless stream of tools/techniques that seem good enough and alternatives that are promised to be much better, do you have an efficient strategy for determining which alternatives to explore? (This is a question I've been wrestling with myself recently.) How much time should be budgeting for exploring an alternative before writing it off as a time sink instead of productivity multiplier?
In your case, since you already use vi/vim daily for some editing tasks, I'd suggest a low time-investment strategy of lowering the slope of your learning curve: review how you normally use it, isolate one or two procedures that seem awkward or irritating, and then focus a small amount of time on researching/practicing the recommended alternative practices of experienced users. I've found that by focusing on the occasional experiment, learning is much more enjoyable. If I think about how much I don't know about vim, on the other hand, I'm inclined to feel overwhelmed and put off learning anything.
Admittedly, this approach isn't going to help if your resistance point is learning to dump the arrow keys and mouse. On that one, I don't know that there really is any good alternative to a couple of weeks of devoted effort.
Incidentally, in relation to your last paragraph, I don't see any advantage to vim's keyboard usage because I use a Kinesis Classic with a Dvorak layout. My arrow keys, home, end, page up, and page down are all within reach from home row. And of course, the Dvorak layout makes some vim shortcuts less intuitive. As for the mouse, I hardly touch it while coding.
I know it is hard to justify plonking down 2 weeks when your current methods work. For me it is the ability to type what I am thinking without having to reach for the mouse (I know in VS you could customize keyboard shortcuts exactly the way you want but somehow it seemed a lot more obvious in vim for me).
I've found Vim's text editing to be better than VS. For example, it's extremely to change a string - ci" - where in VS it's ctrl-leftarrow a few times then ctrl-shift-rightarrow a few times. In Vim it's much harder to compile things, no Intellisense, no refactoring, no decent equivalent to the Solution Explorer, and tons of other missing things. There's no doubt about it. A lot of these things are less useful when working in PHP, so Vim makes sense there.
Not believing the Vim hype is like wondering how anybody could be a Dallas Cowboys fan, which makes a lot of sense to people who grew up or live in Dallas. To people writing code where VS isn't available, there's more focus on editing letters which Vim lets you do more efficiently.
I'm curious, does anyone use Visual Studio for non-code editing? For example, I'm typing this in Vim right now. I use Vim for lots of meant-for-human-readers text.
In the past, I've used VS for editing PHP, which I then deployed to the server using a keyboard shortcut.
I understand what you're saying, but I want to point out that VS can be used as an editor even when the target platform isn't MS.
What I'm curious about, is it so good an editor that people commonly use it for general text editing for non-code text? I know Vim and Emacs gets used like that a lot, maybe Notepad too.
Any full featured editor has so many commands, menus are not practical to display them. VS included. So you're either using just using a subset of VS' functionality, or use hotkeys in VS too.
I'm definitely using hotkeys very heavily in Visual Studio.
http://www.yr.no/place/Norway/Nord-Tr%C3%B8ndelag/Stj%C3%B8r...
As to copy/paste, does that depend on the platform? I use vim in a terminal on Linux and Ctl+Shft+C/Ctl+Shft+V on selected text works fine for clipboard transfers. I don't use vim on Windows often enough to remember how things work there, however, and the article that prompted this discussion was focused on Mac usage.