ViEmu
ViEmu

ViEmu Blog

A blog about all things ViEmu
Emulating
the one true editor
since 2005!

Archive for June, 2009

A Vim and ViEmu mapping you *really* can’t miss – never type :noh again!

Tuesday, June 16th, 2009

Today, I noticed a mapping Tomas Lundell had posted on the ViEmu forums two months ago. Here it is in all its glory:

:nnoremap <esc> :noh<return><esc>

It’s the kind of mapping that, when you read and understand, it makes you think: “how can I not have thought of this before?”, and even, “how come this is not all over the net?”. I have added to both my _vimrc and my _viemurc, and I’m sure it will be with me for many years to come. The kind of mapping I’ll never forget. And this is from someone who <em>doesn’t</em> like to customize his editor(s) too much – my _viemurc is only5 lines, and my _vimrc is a meager 24.

What does it do? I will explain it in detail for those of you who don’t have all the background. If you don’t know what it does, then this post contains more than one valuable lesson for you.

Its function is related to vim’s “hlsearch” feature. When you search for a string in vim, either with / or ? (forward or backwards), or even with :g or :s, if hlsearch is set (“:set hlsearch”), vim will highlight all instances of the string. If the pattern was a regex, all sequences that match will be highlighted. This, as you can imagine, is very useful. It’s actually the “inspiration” (ahem) for one of the features of Codekana, which adds this functionality to Visual Studio’s native search. Bringing vim features to poor souls who depend on regular editors is a surefire way to improve their editing experience… But now on to the mapping.

Once you’ve seen all matches of the string, and you have done what you wanted to do, those highlights become an annoyance. And this is where the problem comes — the vim-standard way of removing the highlights is typing the “:nohlsearch” ex command. You can abbreviate it to “:noh”, but that’s about it. There is an alternate way: just search for a string that doesn’t appear – say, “/asdfgh”, which will remove the highlights. But this is ugly.

So the hlsearch feature is great, but it becomes an annoyance after using, and the annoyance is cumbersome to get rid of. Ouch.

Different people solve this in different ways. You can assign a keybinding to the :noh command. I tried to map it to “\”, which is unused by vi/vim’s keymappings, but couldn’t train myself to use it. Someone suggested “<alt-n>”, which is kind of nice because ‘n’ and ‘N’ are the vi motions for “find next” and “find previous”, but I just forgot to use it. I have always just kept using :noh every time. Until today.

The new mapping does magic. It maps the <Esc> key in normal mode to remove the highlighting (:noh<return>), and also to keep doing the typical function of <Esc> (by default, in normal mode, it will just beep). This is amazing. It’s reminding me of what Python programmers say about things being “pythonic” or not. This mapping is totally “vimmic” — it fits with the rest of vi/vim editing, it doesn’t remove any other functionality of vi/vim, it doesn’t even gobble up other keys which could be used as map-leaders (this is another advanced topic), and it is memorable and discoverable (I won’t forget it, because I will be reminded every time I pressEsc).

I tweeted about it (I’m very active inTwitter lately, and liking it a lot — I’m at http://twitter.com/jonbho). Several people are already retweeting it, even if I didn’t add any explanation (I will now tweet a link to this). I hope this will become popular and reach every vim user, because it’s really good and useful.

It’s shameful that I didn’t really pay the original post the proper attention then, until another person commented on it yesterday. My apologies, Tomas! And one thousand thanks!

Although this forum thread hasn’t been very active, just this has made it worthwhile that I added the sticky topic for tricks at the forum:

http://www.viemu.com/forums/viewtopic.php?pid=2456#p2456

And I hope this forum thread and the creativity of Vim and ViEmu users will generate more gold like this!

[[Update from Tomas Lundell: he wrote in with this comment:

Thanks for the kudos. However, much like everything else in the world, I didn’t come up with it. Any glory should go to Shai of Colemak (www.colemak.com), whose Vim mode for Colemak includes that mapping.

/ Tom]]

Work underway in ViEmu for Visual Studio 2010

Sunday, June 14th, 2009

I’m already working in ViEmu for VS2010. It’s a lot of work, because they’ve totally replaced the editor, but I’m confident I will be early for the VS2010 release. Also, I’m excited the new editor and extensibility model will allow me to offer an even better experience and cool new features.

I’m also working in Codekana for VS2010, but ViEmu comes first.

I’m posting more details at the NGEDIT blog:

http://blog.ngedit.com/2009/06/02/started-working-on-viemu-and-codekana-for-vs2010/

http://blog.ngedit.com/2009/06/15/first-baby-steps-of-viemu-in-visual-studio-2010/

And I’m tweeting regularly every step of the progress, asking for questions, etc… you can follow all the gory details at http://twitter.com/jonbho.

By the way, I will of course keep supporting and improving ViEmu for the “older” Visual Studios indefinitely, and I do plan to implement improvements that will apply to both versions. The vi/vim emulation core is a shared codebase, so any emulation improvements go to all the ViEmus. Anyway, there will indeed be improvements that will be VS2010-only, given the possibilities the new architecture provides. I do think VS2010 will be a hit, much more so than previous VS versions, so most people will end up moving, but of course there’s always a lot of code that won’t be migrated, and we’ll be using older VS’s for years to come!


Highlights

ViEmu: vi/vim emulation for Visual Studio, Word, Outlook and SQL Server:
ViEmu
See where ViEmu customers are around the world:
Map of ViEmu customers around the world
Hear what others are saying about ViEmu:
ViEmu testimonials
Learn vi/vim easily with this cheat-sheet and tutorial:
Vi/vim Cheat Sheet and Tutorial
Read why vi/vim editing is the killerest:
Why vi/vim editing?
Discover ViEmu's sister product, Codekana:
Codekana outliner and syntax highlighter