

Staying the hell out of insert mode (vi) - cloudhead
http://cloudhead.io/2010/04/24/staying-the-hell-out-of-insert-mode/

======
oliverkofoed
The author recommends remapping "kj" to ESC.

I've remapped caps lock to ESC, which I think is a far better use of that
useless button, and a hack i recommend to everybody i know who uses VIM.

I could never understand that VIM choose to put such an important button so
far away from the homerow.

~~~
xutopia
In the same vein it seems totally ridiculous that we use the pinky finger to
hit ctrl. Surely there are better ways.

~~~
spudlyo
There are. The Kinesis keyboard has four thumb buttons on each side of the
keyboard. The biggest, closest one on the left side I map to CONTROL. The
other big left thumb button I map to ESCAPE.

~~~
RevRal
You can also look into importing a Japanese keyboard for more thumb options.

~~~
Calamitous
Why? Do the Japanese have more thumbs?

Sorry. Had to get it out my system.

~~~
RevRal
I don't get it. . . .

They have two thumbs, but within reach of their thumbs are extra keys. They
need these extra keys because there are a lot of characters in their writing.
They don't need more thumbs, because they only need to push one of these extra
keys at a time.

Do I need more pointer fingers if I need to use one of the Y, H, N, B, T, G,
and V keys?

~~~
Calamitous
Um, it was a joke...

------
klochner
The only problem I've found with remapping keys (and getting used to it that
way), is that you look like an idiot when using someone else's machine.

This was particularly unfortunate in a coding interview:

"I'm used to a different keyboard layout, seriously."

~~~
jerf
My plan to combat this in any future interviews (and a couple of previous
ones) is to bring my laptop with me. If there's any development questions,
I'll do it on my laptop. If they become offended that I want to develop in my
preferred environment, on my preferred keyboard layout (Dvorak +
capslock->backspace), with my preferred editor... _they_ have failed _my_
interview. It ought to be a _plus_ that I came that well prepared.

Incidentally, having been on the interviewing side, I do not see this often
enough. Bringing your own laptop ought to be something you always do. I can
provide "a" coding environment but it won't be "yours". Unless you always
develop in a completely uncustomized standard Visual Studio environment, maybe
(in which case frankly I'm still wondering a bit...).

------
pge
For vim users, particularly newer ones, I think the cheat sheet at
[http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial...](http://www.viemu.com/a_vi_vim_graphical_cheat_sheet_tutorial.html)
is great. Happy Hacking Lite keyboards are also great - they have the old
layout with Ctrl where Caps Lock usually is and Esc not too far away.

~~~
jraines
Thanks, I'm in the early stages of learning vim and this is great. If anyone
else is in the same position, also check out vimcasts.org.

------
lanstein
I map caps to esc instead of ctrl, and that plus H -> ^ and L -> $ means I
hardly move my hands when out of insert mode.

------
Avshalom
Vi(m) out of the box is a fantastic editor.

As a code composing environment it leaves a lot to be desired until you've
tacked on enough plugins that it looses a lot of it's vimmy goodness (imo
obviously), as a result I tend to do my first draft in various places
(FlashDevelop, the Factor Listener, Dr. Scheme etc...) and then use vim for
all the follow up work.

I don't know that it's a failure of vim but I think it's part of the reason
articles like this keep getting written. The people not already deeply
invested in an editor/IDE (me for instance) are the ones who spend more time
writing new code than maintaining or adding to a significant existing code
base.

Just my thoughts, not really a comment on the article.

~~~
DannoHung
screen + vim is all the IDE I need (and want, for the most part).

~~~
Avshalom
If you mean just vim and not vim + omnicompletion + whatever, then more power
to you I guess.

I try to keep my vim pretty vanilla outside of font and color preferences
because I spent most of college jumping from one computer to the next and I
didn't want to get used to relying on anything that wouldn't be there next
week.

That said vim + screen kinda translates to vim + 'my entire computer' which
doesn't prove my point really but also doesn't say much about the completeness
of vim as an environment.

~~~
pyre
You can send commands to other 'windows' inside of a screen session. So you
can whip up vim plugins to spawn a new screen window (for example) with your
test suite running in it. This allows for some of the things that you can do
with 'buffers' in Emacs that you can't really do with them in Vim (i.e. you
can't launch a test suite in Vim with the output sent to a Vim buffer and
still be able to edit with Vim while the suite is running).

That said, I much prefer hex-editing with Emacs to using a combination of xxd
and vim.

~~~
bittersweet
Could you point me/us in the direction as to how to set this up? I've been
trying to emulate this function from Emacs ever since I've seen it in action.
I'd love to be able to launch my test suite and have the output available in a
buffer.

I've tinkered around with hacks that put shells in Vim windows but it wasn't
really satisfactory.

~~~
pyre
The manpage for screen should tell you how to send commands to the screen
session (the -X option, I believe). You just need to create a function/binding
in Vim that tells screen to create a new 'window' and run that test suite in
that 'window.'

Screen is basically a terminal multiplexer. This would work a little
differently if you were using gVim instead of Vim (from within the same screen
session that you're sending the test suite command to). If you were using gVim
you'd need to use a named screen session (the -S option) and send the screen
command to the named session (and possible have logic in the Vim/gVim function
to start a named session if one doesn't already exist). Then you'd need a
separate terminal window attached to that screen session to view the test
suite output.

Do a search for vim and REPL or SLIME for articles like this:
[http://technotales.wordpress.com/2007/10/03/like-slime-
for-v...](http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/)

These articles use the vim+screen combo to send commands to an interpreter,
but you can use the same concepts to send your test suite to a screen session.

------
willwagner
The "kj" remapping seems like a nifty trick; I've spent a while getting
accustomed to ctrl-[ instead of the <ESC> key (I can't reach the <ESC> key
without moving my left hand), but it's still hard for me to do quickly and
reliably.

~~~
latortuga
The author of the article suggests using Caps lock as control but I've found
it's a stellar place to have an escape key. After a few days it felt
completely natural for my left pinkie to hit escape. For those on windows,
there are a number of batch files that will help edit your registry to remap
the keys although I found it to be a problem on Windows 7 until I tried Sharp
Keys which worked great.

Another trick that is useful for people who compulsively hit the Ctrl+s
keybind from other editors; the following is from my vimrc:

    
    
      " Map Control+s to save a file
      nmap <C-s> :w<CR>
      imap <C-s> <ESC>:w<CR>
    

This leaves you in normal mode which is usually what I want when I hit ctrl+s.

~~~
pyre
Don't hit C-s when you're using vim in a terminal though. (But if you do, hit
C-q)

~~~
latortuga
I actually almost put this in my original post but I didn't know if this was
just our server's vim install or if it applied generally. Thanks for the heads
up!

------
xutopia
I guess I have to give it a shot again. I keep on getting frustrated with VIM.
Perhaps this is the proper way to learn it.

~~~
nailer
[code folding section deleted, I stand corrected]

Vim's indentation changes still require a mode change three obscure keys and
an enter, and vim's discoverability still sucks.

~~~
sophacles
Have you ever tried reading the manual? Seriously, the level of the
documentation is pretty good for a free piece of software.

Edit: actually, its pretty good for _any_ piece of software.

~~~
pyre
The problem comes when you don't know what the topic you're looking for is
called in vim. I've only had that problem once or twice over the years, but it
can be frustrating (esp. w/ no Internet connection).

~~~
sophacles
I agree. Fortunately however, :he has tab completion, which certainly reduces
such. Also :he index is nice. And for those times with internet, #vim on
freenode usually knows the correct :he keyword in seconds.

------
jrockway
I like how people think vim is vi, and talk about vim-specific features as
though they are in all vis.

Incidentally, I sometimes use vim as $EDITOR when dealing with perforce,
because if the editor dies (or fails to start) for any reason, all changes are
committed by default with no commit message... and sometimes I don't have an
emacs for emacsclient to connect to. (The result is 30 minutes of work trying
to get perforce to uncommit my changes. Usually I fail and just comment out
the tests, commit that, and fix the code later. Ah, perforce...)

Anyway, I recently discovered that C-p, C-n, C-b, and C-f work as they do in
Emacs. They just need to add C-a, C-e, M-m, C-k, and C-y, and normal mode will
become unnecessary. (And I won't need to install mg on so many machines.)

And then vim will almost have as many editing features as my bash prompt ;)

~~~
Locke1689
Hint: set -o vi

That said, if you really believe that vim can't do everything that emacs can
do in editing, I have nothing else to say...

~~~
jrockway
Editing is but a small part of programming.

~~~
Locke1689
Editing is a large but incomplete part of programming, which is why vim is a
large but incomplete part of my programming environment.

Look, if you're arguing this just to take potshots at "that thing you don't
like" then we should end this conversation now. If you're open to the
possibility that we can both be productive with different toolsets then I'd
like to learn more about your setup and maybe share some of the benefits of
mine.

~~~
jrockway
You're the one getting defensive. I am merely amused that vim added the Emacs-
style keybindings to insert mode.

~~~
Locke1689
Sorry -- you're right, I guess I've been trolled a bit too often as of late.

------
blahedo
Ah, too bad---I was hoping for an article on _why_ to stay the hell out of
insert mode, not _how_ to. I know how to; I sometimes have a hard time
convincing my students that it's good for them to become power users of their
editor, and thought this might be a link I could pass along.

------
RevRal
I have tab remapped to esc, and s-tab as tab.

------
city41
I use ViEmu in Visual Studio as my primary "vi editor", and the clashing of
Visual Studio and vi really adds up after a while. As I'm sure you can guess
CTRL+O and CTRL+C don't work in ViEmu.

I think the real solution is to make vim my main editor for working in C#.
That's a pretty tall task unfortunately.

~~~
frou_dh
Given how well it marries with VS intellisense, it seems almost unfathomable
to write C# in a more general text editor.

Of course for C++, VS intellisense is a lot weaker and probably not that much
of a draw.

~~~
city41
Yeah, part of me is not convinced ViEmu is the way to go. So many things in VS
still require either the mouse or the arrow keys. A simple example is
intellisense, once it pops up, j/k are not going to scroll through it.

------
hotmind
The title makes this article full of win.

