Tuesday, January 12, 2010

Some recent nontrivial searches

Doing a lot of CSV file analysis the last couple weeks. Some things I've needed to do:

  • [^X]: Find out if there are any fields that don't match the typical pattern. Here's one. In this file I noticed that most files 2nd field had the pattern of four numbers followed by the letter A. I wanted to see if there were any that had some other character at the end. When I used s/\d\{4}[^A], lo and behold there was indeed a nonstandard entry:
102,0949,0277A,1,0.00,"
102,0282,0282A,1,0.00,"
102,0284,0284B,1,0.00,"
102,0287,0287A,1,0.00,"
102,0288,0287A,1,0.00,"
102,0289,0289A,1,0.00,"

  • \1: Then I noticed that in a lot of entries there were field 2 and field 3 pretty much matched in most cases. I wanted to see which ones didn't match. At first it was easier to look for the matching entries with the following s/\v(\d{4}),\1\u,:
102,0949,0277A,1,0.00,"
102,0282,0282A,1,0.00,"
102,0284,0284B,1,0.00,"
102,0287,0287A,1,0.00,"
102,0288,0287A,1,0.00,"
102,0289,0289A,1,0.00,"

  • \@!: Its actually a little confusing, but it can be done. By using the zero width matcher \@! you can specify that it NOT match the previous but then you have to fill in some for the part that it will match. Strangely the \@! matcher doesn't respect the \v 'verymagic' setting, so you end up with a lot of slashes in the end result. And this is what it looks like \(\d\{4}\),\(\1\)\@!\d\{4}\u,:
102,0949,0277A,1,0.00,"
102,0282,0282A,1,0.00,"
102,0284,0284B,1,0.00,"
102,0287,0287A,1,0.00,"
102,0288,0287A,1,0.00,"
102,0289,0289A,1,0.00,"

Thursday, January 07, 2010

quick * and # search hack

A friend of mine introduced me to a quick way to use the * and # commands (which let you quickly jump to the next or previous instance of the 'word' under your cursor). Generally a word is ([A-z][0-9])+. When you use the :set lisp option though, it then includes the '-' character as well. An old school option that makes for a nice quick hack.

There is however a general solution: it turns out there is yet another thing I didn't know. You can change what a 'word' is in vim by modifying the 'iskeyword' setting.

To see what characters are considered to be part of a word you can type:

:set isk
iskeyword=@,48-57,_,192-255

I've found that its pretty easy to change things up when you need a slightly different usage from */#. For instance, if you are searching some keywords of the form:

final int TRANSIENT-RAT-SCH-CODE = -1;

Suppose your cursor is on the 'T'. If you hit * or # you would be brought to the next or previous instance of 'TRANSIENT' because '-' isn't in the 'iskeyword' setting. Quick fix? Do:

:set isk+=-

Then it'll match the whole big bad thing.

Sunday, December 20, 2009

entire file view of matching searches.

So I've been using IntelliJ a lot for my Java and groovy development lately and noticed a cool feature of its editor recently. When you do a search, a little tick mark is made along the area of the scroll bar for each match to your search. This is kinda cool as it gives you a general idea of how many matches there are in the file, and a general sense of where they are.


So I was thinking. I wanna do this in Vim. How? Well, if you have +signs support built in...you could do as I did. This is what I got toward:


This works in the same general way: the green hilighted area essentially corresponds to the scrollbar...it shows you what part of the whole file you are looking at right now. The little ticks show you where the other matches are in your file.

Anyway, I think its generally a cool idea. I've made a plugin that shows this stuff on the side whenever you have the 'hls' setting on. Whenever you move around the file it automatically updates so its generally correct. Still some bugs, but I'm working on it. You can try it out yourself from github.

General conclusions/thoughts:
  • vim-unit continues to rock. I'm almost to the point of considering going all ruby or all python for serious vim scripting though.
  • It sure would be nice if there were events you could subscribe to when your location changed in Vim. There is something for window sizes changing...but w/o this you're pretty much stuck using the CursorHold type cludges - which just feel like cludges unless you get your handler code really efficient (quit early, do as little as possible, set udpatetime high).
  • I wish MacVim supported images for +signs! I've checked out the MacVim project from git. If I get some free holiday time I'll definitely look into making images to get a more IntelliJ like result -- although I suppose the solution I have now is good in that it'd work on the console. Still.
  • Wouldn't it be sweet if you could have a left gutter +signs support as well as right gutter? IntelliJ really can tell you a lot by making use of them.
  • I'm thinking this +signs thing for code coverage tools would be kinda nice...have to look into that at some point...





Thursday, November 19, 2009

NetRW and MacVim

So since I upgraded to snow leopard I could have sworn that the netrw just stopped working. Every time I tried:

:e scp://somhost/somepath/file.txt

I would get some gobbly gook about not knowing how to handle a BufEnter event or some such thing with regard to "scp://".

I'm using Snapshot 50 since that works better than the last stable build (I recall some repainting issues). Well, it looks like maybe the snapshot doesn't include the netrw plugin. So I just downloaded it and installed it manually and all is good with the world, yeah!

:e ~/Downloads/netrw.vba.gz
:so %

Friday, September 04, 2009

YouTRACK: a bug tracker for the vim-ish?

I got an email yesterday from jetbrains, notifying me that their internal bugtracker YouTRACK has gone beta. "Try it out!", they tell me. Okay, I like jetbrains stuff, so I bit. I'm posting here about it because it kind of reminds me of my learning process with VIM. Back when I first started using VIM I remember that I suffered through the initial arcana: I couldn't do anything at first (it was hard), then I began to cotton on to the general concept (but I couldn't really do it), at last I could do things fast, and finally I wondered why it didn't have all those kitchen sink features other products have. Doesn't this sound sooo reminicent of using VIM?

If you have ever used VIM you probably remember struggling just to frickin...TYPE. Type anything at all. And then once you could actually do that, well - what about saving and exiting? Escape? :wq? Ahh...those first few baby steps. YouTrack totally hit me like that. Of course they provide GUI menus for everything but me being a VIMish user, I wasn't interested in the easy/slow way. I had to figure out how to do everything by hot-key only. After all, the speed what supposedly sets this bugtracker apart. The installation part was easy. Download the WAR, stick it in tomcat, and fire it up. Bam. Its up and running. Copy and paste the demo license from their website and I'm good to go until December 2nd (after which point I'll have to buy a commercial license if I actually like the thing? How much?? Who knows...we'll see).

I setup a couple small projects I'm currently working on (too small for a bug tracker - or rather, too small to be worth the trouble). First impression: interesting. There is a search window with type-ahead keywords that appear as you go. How do I make a new bug? Ah. A hotkey (and by mouse of course, but I'm ignoring that as I said).

I easily entered a couple bugs and a couple projects in the system. I'm working on a project and I want to pull up all the bugs, how do I do that? It takes me a couple minutes stumbling around with the search window to figure out what the syntax is "project: AA" - ahh...tab completion. Nice. So there were are - a couple bugs. How do I get from searching to modifying bugs? Durn durn durn I stumble on this for 20 minutes.

Ahah! ESCAPE! Of course. Wouldn't you know it would be the same key that is such a stumbling block in VIM too. Go figure. Once I figure that out, oh my god. Its the frickin easiest thing to add comments and tag bugs. A breeze. Very snappy. I'm loving that. I can now see myself setting up projects and adding bugs for trivial little projects in no time. Nice. Perhaps even todo lists in general. Quick modification of tab names, batch updates, etc. Power.

Of course, now that I'm enlightened, I have questions. Lots of questions. Kitchen sink type questions. Can I use external java/javascript to make mashups (say burn down charts, remotely add bugs say via my own applications, etc). Whats the best practice for agile delevelopment say? Integrate with other back end bug trackers like bugzilla or trac? As I keep playing with it over the next few weeks I'm sure I'll have more questions and comments. But so far I like it a lot. Just wish I knew what I'm gonna have to pay for the thing once they go commercial with it a few months down the road (ie, once I'm totally addicted).

Wednesday, March 04, 2009

Daniel in Nowhere: Put Searched results into a split window under VIM

Hey this looks pretty cool - every now and then I've wanted to see search results in a nice searchable list. Gonna have to try this plugin out:

Daniel in Nowhere: Put Searched results into a split window under VIM

Tuesday, December 09, 2008

Registers

There is always something new to discover out there, particularly with Vim. I thought I knew how registers worked: you got your window manager registers (+ and *); the 'last thing I deleted' register ("); the confusing 'last 10 deletes' registers (0-9); some read only registers that I don't consider to be registers because, hey, you can't write to them (% and #); and then the multipurpose named registers (a-z).

I've programmed myself over the years to use specific letters for specific purposes. The 'n' and 'm' registers are reserved for recorded macros (yes, macros are saved in registers - handy to know if you want to save a macro in your .vimrc for later use, say), the 'iou' I tend to use for registers that are used in a macro, and 'fvc' for yanking and storing.

For instance, if the lines below existed, and I wanted to copy the first one for later use:

every good boy
does good

I'd do: "fyy

Now, if you type ":registers" you can see all of your registers, and thats overwhelming. I tend to just look at the register I'm especially intersted in ":echo @f" or ":registers f" does the trick nicely. Also, since I know I use the 'fvc' registers for yanking - I tend to just look in those registers if I forget what I've done with ":reg fvc".

Did you know that you can append to the named registers? I had NO IDEA. By using the capital letter 'F' instead of the lowercase letter 'f', for instance, you append rather than replace. Take the example above. Say that I was going along editing and I saw another line I might want to use later:

...
...
blown up beneath my glass.
Colors dazzle insect wings.
...
...

I could, if I wanted, just add it to register 'f' with the other line by doing: "Fyy

Type ":reg f" and you see:

--- Registers ---
"f Every good boy^JColors dazzle insect wings.^J


Not too pretty, but thats where this comes in handy: ":echo @f"

Every good boy
Colors dazzle insect wings

Press ENTER or type command to continue

There you are - a case for using 'echo' over 'register' and an interesting note about the named registers.