One with Vim
invisibletheory.com
invisibletheory.com
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
It can, in fact, search pretty much anywhere in vim (from the docs):
- buffers
- files
- directories
- most recently used files
- files around most recently used files
- most recently used command-lines
- bookmarked files
- bookmarked directories
- tags
- files which are included in current tagfiles
- jump list
- change list
- buffer lines
- quickfix
- helpNERDTree 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.
I just glanced over the Command-T docs and it seems to be a one-trick-pony ("search in path") whereas FuzzyFinder supports a wide range of scopes (path, buffers, tags, etc.).
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.
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 appropriateFor 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>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.
Getting 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.
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.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.
(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.
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.
http://www.yr.no/place/Norway/Nord-Tr%C3%B8ndelag/Stj%C3%B8r...
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.
I prefer Vim as the frontend, but was hoping to add Eclipse's code correction and refactoring to it. But that's also the most complicated of the three options, and least well supported right now.
Refactorings: I can rename a method in one location and it will change all the calling code. This would be dangerous to do by hand: Best case scenario, there would be a compiler error for all the broken code. Worst case, that method name was already overloaded and you just introduced a bug.
ctrl+n: Open any file that's in your project. It can find the file by camel case or pattern matching and it only includes files in your project.
ctrl+alt+h: See a tree of all the callers of a method. Extremely useful when you're considering a refactoring. You can instantly answer the questions, "Is anyone calling this method?", "Is anyone calling the methods that are calling this method?...", "What will be affected by this change?", and so on.
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.
Not my experience at all. It's a sea of confusion and pain.
Personally, the god-awful slow file switching, frequently-incorrect highlighting, almost totally worthless JavaScript, ASP, and ASP server-side code support, XML comments with no built-in documentation builder nor viewer, text-column editing that's a total joke, and the always-helpful "too many warnings" error are my most recent peeves.
I hate VS. With a passion. I cannot believe that such a painful-to-use program is held up as the pinnacle of programming experiences.
So why do I use it? Because .NET defies logic; framework-wide intellisense is the only way to do anything in it. Give me almost any other language/framework and in a few days I can get by almost entirely with a programming text editor and occasional official-documentation browsing. Several months into .NET code, I still Google more than I MSDN, StackOverflow more than .NET-developer-blog, and the massive style inconsistencies between different sections of the library mean I cannot go into any new area without Visual Studio to hold my hand and kick me in the nuts.
For what it's worth, I've always found Microsoft APIs to vary profoundly in terms of usability and (especially) documentation. And MSDN hasn't been directly useful to me since the VS 6.0 days.
Can you give me an example of an editor with better text column editing? I'm not entirely sure what you mean.
Only about half-so. The first paragraph was all about VS exclusively, minus "too many warnings". But due to the issues in .NET, you essentially must use Visual Studio, which makes it at least bearable due to intellisense. But I crash VS fairly often, it eats up a half-gig or more of memory fairly often, it thrashes my hard drive to bits all the time so everything else crawls, and at one job the visual designer started executing code. Those database-filled combo boxes started querying the database right in the designer. This happened 3 or 4 times over a couple months, and could have been catastrophic if any of the times it happened occurred on deleting fields. I will never hook a database directly up to VS, I'll guarantee you that; this was executing our bound events. Imagine if we actually had direct connections to the DB.
So, one that's more specific to VS: the idiotic Web Site "projects" that have zero capabilities, and not even before / after build events to hot-wire your own in. And I dare you to try compiling documentation on a Web Site project. People have been asking for it and attempting to hot-wire their own for years, and they use gigabytes of memory to parse small projects and choke after an hour and give up without anything more helpful than "MSBuild.exe encountered an unexpected error". I suspect very much that the slowness of the only decent help builders is due to the horrendous reflection side of .NET, but that's not VS's fault. Except that VS wants VS-style documentation and won't accept anything else, but nobody can use it.
And, because it's particularly bad, I'll point to the JavaScript support again (2008. I hear 2010 is a bit better). It throws fits and doesn't always even index global functions you just declared (it's entirely broken on the site I'm working on, it simply refuses to parse anything not in assemblies), Intellisense tries to change "$()" to "$addEventHandler()" as you type, and it has the absolute worst indentation of any code editor in existence. None would be better, but it occasionally decides you're not neat enough and imposes "order" on your nicely readable function.
edit: Ooh! Another one! It's such fun to use VS in a multiple-monitor setup. Either you use the annoying "Multiple Document" layout (inner-windows that waste tons of space and fall behind things when the docked windows change), or you use tabs and can't spread to a second screen effectively. Or you launch two versions, and have them throw fits when you build in one, and the other sees things changing. And there is no higher joy than editing web.config while two instances of the same project are running, and watching the Visual Studio hit the fan.
--- </rant> I feel better. Thanks :)
Nearly any other programming editor, really. Notepad++ is a good example though, and doesn't require install, so I'd suggest experimenting with that.
In VS: hold alt and select a box of text. Note that you can't select less than a single space wide. You can copy, paste, and delete it. Now try hitting space, or typing something: the whole set is erased, and you start entering text at the top-left corner of what you had selected.
In nearly any other editor: hold alt and select a box. Note that you can select a column "0" wide. Copy, paste, and delete work as expected. But start typing; the vast majority I've used will fill the entire column as you type with what you're typing. Backspace removes line by line after the initial replacement. You edit the column, and everything you do is duplicated to the other lines you had the selection in.
It'd be especially useful for .NET as damn near every useful method returns void: want to populate a list with a few items? Select a few columns, type "list.Add(" and you're most of the way there. Plenty of times the refactoring tools (as good as they are in non-VB languages) don't work if you're not changing everything, and having a column editor would make things a lot faster. Besides, they have half a solution working; why did they stop at the nearly-useless step?
Another handy thing many programming text editors will do, but VS does not: soft-tabs go away with a back-space to the next tab-stop (if you start at one). In VS: keep hitting until you reach what might be another tab stop, there are no indicators for such things. Happy counting!
Zeus also does a limited amount of intellisensing, but naturally the intellisensing is nowhere near good as that found in VS. But the code navigation is not too back.
Zeus also has full MSDN integration and it can actually do context sensitive queries of the MSDN much faster than VS:
http://www.zeusedit.com/zforum/viewtopic.php?t=2833
So if you are prepared to forgo a bit on intellisensing, it is in fact possible to develop outside of the VS IDE at least some of the time.
To be honest I'm not really sure. The big test would be to see if Zeus manages to import the solution file (i.e. from the Workpsace, Import menu).
This import has only been tested for 2005, 2008 and 2010 C# and C++ projects.
If it doesn't feel free to send me a bug report.
> I'll certainly give it a try for more "normal" .NET coding, there's a lot of utility code to be written :)
These are the three 'one off' steps needed to get the Visual Studio compiler to run inside Zeus
One of the first things I noticed: apparently a couple of your regexes are off in C#, for VS2008 at least. Typed interfaces come up as "T" instead of the interface, and it would be immensely more useful to have the class browser have information about the parameters of functions. I've got a ton of overloads, and they're note even in any useful order, as far as I can tell.
That is what I had feared. It looks like Zeus will need to be tweaked to understand this type of solution file.
> I can poke at it a bit more and see if I can get more into it.
One thing you could try is opening an explorer window and then just drag and drop one of your source code folders onto the Zeus workspace panel.
Zeus will parse the structure of the folder that was dropped and add all files that if finds to the project/workspace.
> One of the first things I noticed: apparently a couple of your regexes are off in C#, for VS2008 at least.
The use of a regexp to identify functions is a Zeus feature that dates back to one of the very early versions and is no longer the primary method of identifying functions.
What should have happened is for Zeus to create a tags database for all the files in the project/workspace and it then uses that tags information to display the function list.
But in this case since the solution was not imported correctly, the workspace is empty of files. As such Zeus reverted back to the older regep approach to identify the functions.
And as you suggest, the regexp that it used is almost certain to be out of date since, it was probably written even before the time of C#.
> it would be immensely more useful to have the class browser have information about the parameters of functions.
Adding the current file (or all the project files) to the workspace should result in a lot more information being seen in the class browser.
The class browser shows the contents of the tags database and if it is not full then it means the tagger is not understanding the code, but for C# that should not be the case.
I recommend giving 2010 a go. If I recall correctly, 2010 was the version where they drastically reworked Intellisense. In previous versions, even my moderately-sized projects would break Intellisense upon reaching x lines of code. I don't think the multi-monitor support is any better, though. You can drag documents to their own window on any screen, but I can't seem to group them into sets of tabs.
Oddly, Intellisense is generally keeping up with me, despite the site being at least a few hundred thousand lines of code (light on the abstraction, though, so it's mostly flat .NET code. Probably not too taxing on intellisense). There are times I just break out Notepad++ and finish up stuff VS was breaking, but it generally catches up any time I build the relevant projects.
And I should be clearer, because it's so weird: the designer-view was actually instantiating the entire window control, as it's init contained the database connecting code, and firing events on the combo box controls that queried the database. At no point was the database actually connected to VS, which you can do; and I'll never even consider trying it, after seeing that happen.
Also, VS10's WPF-based UI is a nightmare, but that's another discussion...
Of course Visual Studio still does its own parsing in the background, for example for the class browser. VA provides something similar, maybe I should use that one and see if there's a way to turn off the Visual Studio Intellisense. It is my subjective impression that this one does sometimes slow down the IDE itself.
My only complaints are the recent price hikes: 249$ -_- ? Those are getting above discretionary purchasing power and although I guess there is some effective productivity gain, it's very hard to quantify and therefore justify... Especially when other people don't want it, because then if you do want it, you look like a wuss who can't hold his own without having his hand held by pretty colors (simplifying of course but let's face it, this is what it looks like from the outside).
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.
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.
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!
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.
I wouldn't start up a VS instance just to edit text, but if I have one running, it's my editor of choice.
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.
The startup time is too long for off-hand editing (I suppose this is hardware dependent). In that case, I'll open Notepad for quick to-do lists, or vi for non-line-ending-mangling tasks. It's pretty unusual for me not to have VS running, though.
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 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).
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.
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.