Saturday, December 5. 2009You and Your Editor: Vim normal mode commands g, : and d (3 of N)In my last post, I showed off some normal-mode data from vim-logging. In this (and the next few) posts, I'll go though my most-used commands and describe how I use them. (Don't use Vim? This post won't be too interesting… Although you may pick up something useful) gMy logs contain more than 60,000 references to the 'g' command (eight times more than ':', the next most frequently used command). This may seem surprising at first, but stick with me and let me explain: the 'g' command is something of a 'gateway' command - a prefix for a number of common actions which don't have their own single-character command (for example, gd, goto definition and g?, rot13 encode). Here is a breakdown of the 'g' suffixes I often use:
That's all the 'g' commands I can think of for now... The next version of vim-logging will log the sub-command used, so I will be able to provide better data in the future. :The colon command is fairly obvious: enter command-line mode to run commands like I'll write more about this later, when I analyze my most-used ex commands. dAh, As with
You and Your Editor: Data from vim-logging (2 of N)Remember when I blogged about vim-logging? Well, I've finally gotten around to interpreting the results. First, I will cover what I believe to be the most important thing to know about vim: the normal mode commands. Below is a chart of my 39 (why 39? I can't remember - when I created the graph, that's the number I chose) most-frequently-used normal-mode commands: Continue reading "You and Your Editor: Data from vim-logging (2 of N)" Thursday, October 15. 2009You and Your Editor: The Bare Minimum You Should Be Doing (1 of N)It's come up a few times, so I'll just go and post it here: the things, in no particular order, I believe to be the bare minimum you should be able to do while you're editing source code (and how to do them in Vim): Easily move between filesAll but the simplest scripts require more than one file, so you'll often need to switch between them. Eclipse has two very useful features here: Quick Access (command+3) and Open Resource (command+shift+r):
And in Vim, I make heavy use of multiple windows (
Jump-to-definitionWhen you're working with a large project, especially one for which you aren't the only author, it can become nontrivial to figure out where things (classes, functions, etc) are defined. I've found that it's very hard to read source code without a jump-to-definition function because it forces a mental context switch from "figuring out what this code does" to "figuring out where this method is defined", then once I've found where it's defined, "ok, now what was I looking for again?", and once I've finished reading the definition "why am I looking here again?" and finally to "what was the point of this sentence?" With Vim, I use exuberant ctags to do this. First, I run
(note, for this to work properly, make sure Search for/highlight the current wordOften, when I'm reading code, I'll want to quickly look through all the references to some word in the current file (for example, to see where a variable is referenced or how a function is called). This sounds trivial, but I find myself doing it often. Very often. So give it a try before immediately disregarding it. I do this in Vim using For example, if my cursor is over
That's all… For nowThat's all for now, but stay tuned – I do love editing text, so I'll probably come back and write some more on this later. PS: Just to make very sure it's clear, the only editors I mean to bash here are the ones which make it very hard to do the things I've talked about (nano, notepad, etc)… Every decent editor can do these things, you've just got to learn how. PPS: If you don't already use it, Vim has a great built-in help system. Access it with :help {subject}. For example, PPPS: Todd has posted a followup, Worthwhile vim tips – they are a bit more basic, but even more important than the things I've talked about here. Thursday, August 16. 2007DrProject/Trac Wiki Syntax Highlighting for VimAfter being frustrated with boring white-on-almost-black (spectro) while working with DrProject wiki files, I broke down and wrote a Vim plugin to make the syntax pretty. It will also parse most of the Trac syntax (and more should be easy to add). Get it: http://wolever.net/~wolever/drpwiki.vim Using it:
Friday, June 15. 2007Fixing Files with Vim MacrosI got an email a couple days ago asking me to add a small header to all the pages of a website I work on from time to time. The site was built with static HTML a couple of years ago and this was the first site-wide modification I've had to make since then. So I fired up Vim, loaded the session I use to work on the page and got to work. It didn't take too long to make the changes to one page -- add a couple of JavaScript functions, add a call to the the body's But then came the problem. How do I apply this change to all the pages? Normally, to do multi-file search-and-replace, I use So how did I do it? By writing a Vim script! I used As I made the changes, I used general steps so that they could be repeated on each file. For instance, I used Finally, after saving the file, I used Now, this makes me curious... Faced with a similar situation, how would you solve a problem like this? 1: Now, in retrospect, I realize I could have used:
for FILE in `find . -name '*.html'`; do
read -p "Edit $FILE? " R
if [[ $R == "y" ]]; then
perl -pi -e 's/old/new' $FILE
fi
done
But that would assume that I was putting some serious level of thought in to this. Also, unless I also had the presence of mind to add
(Page 1 of 1, totaling 5 entries)
|
QuicksearchArchivesLinks
CategoriesSyndicate This Blog |
