
Enhancements to Shell and Vim Productivity - danielrm26
http://danielmiessler.com/blog/enhancements-to-shell-and-vim-productivity
======
mtts
"7. Use vi-mode in Your Shell"

Tried this and gave it up. Your shell may be (somewhat) vi compatible but the
applications you use mostly are not so you'll have to break out of the vi
mindset at all sorts of inopportune moments. That, and modal editing, while
perfectly alright for text editing, maps rather lousily to command line
operations. You're much better off getting used to some basic Emacs-style key
bindings that work consistently across a wide number of applications
(including OS X text fields, IIRC).

~~~
kittxkat
What I did, for example, was that I enabled vi-mode in my shell but also re-
enabled __some __emacs-keybindings like CTRL-E and CTRL-A for ending and
beginning of a command because I learned them like a lifetime ago when I first
got used to the shell without even knowing they were emacs-keybindings.

But that way I am also able to hit ESC and do a / for a search, like within
vim, which I am much more used to than a search in emacs. I found that way
combines the best of both worlds.

~~~
jlgreco
I use vi-mode in my shell but the end/beginning Vi commands (A,I,0,$,etc) are
the only ones I find myself using regularly. I also use c[motion] and
d[motion] on occasion, but that is pretty much it.

I'm not convinced that powerful editing is necessary for the command line, but
familiar shortcuts for beginning/end seem very useful.

~~~
dllthomas
There are absolutely times that powerful editing is mandatory at the command
line; I am skeptical that there are times when powerful editing at the command
line is necessary but pulling the line into your $EDITOR (v in vi-mode, ctrl-x
ctrl-e in emacs-mode) is not the best way to deal with it.

~~~
ibotty
but it's not about powerful editing alone. it's about nice things that are
just in your fingertips, say using 'df ' to delete a --long-
argument=/a/very/long/path from a command...

~~~
dllthomas
fair enough

------
Aardwolf
Why is this article so Mac oriented?

So here's tip 9:

Use a nice Linux or similar machine with a pleasant to use clicky keyboard and
a mouse which allows text highlight and middle click paste.

~~~
Watabou
You know I don't really get this sentiment. And I just think people hate on
the Mac because they want to.

I never saw the appeal of Linux. Yes, it's free, and I can buy a cheap PC to
run it on but why would I do that? My Macbook Pro has the best keyboard I've
ever used (the 2008 "pro keyboard", not the chicklet keys Apple uses these
days) and the trackpad is better than ALL trackpads out there. Seriously,
Apple knows how to make trackpads. And on top of that, OS X is as much Unix as
Ubuntu or any other distribution of Linux and I can do whatever work I would
have done on Linux on my mac. If I don't have a command line tool, I just use
homebrew to install it or build it from source if homebrew doesn't have that
formula. And you know what I get including those nice things? The wealth of
awesome OS X apps, like Textmate, Keynote, iTerm, Kaleidoscope,
QuickSilver/Alfred, XCode, Pixelmator, Time Machine etc that are available. So
I ask you, why would I use a Linux machine when OS X is supremely better in
almost every way?

~~~
Aardwolf
1) The article has a title making it seem like it's unix shell tips straight
from the unix master, then instead is advising to use certain Mac programs.

2) A trackpad can NEVER replace a regular mouse with scrollwheel and many
buttons. Maybe the apple.com website triggers _your_ emotions. But the
following website triggers _mine_ : <http://www.razerzone.com/gaming-mice>

3) OS X may be supremely better for you, but not every person is the same, you
may be their target audience, other people are not and, _gasp_ , may actually
prefer a different design philosophy.

4) Being free or cheap is not usually a reason why one runs Linux on a PC. Can
you imagine someone can actually prefer something, independent of cost?

5) Mac OS X has apps. Other OSes also have apps. They all have their selection
of awesome apps. Usually one prefers the ones they're used to I guess.

~~~
Watabou
1\. There's only ONE tip out of 9 that tells the user to use iTerm over the
default Terminal. I don't agree with many of the tips here and I wouldn't use
them to "enhance" my workflow but you have to critique the article on what it
actually says, not what it's geared towards. You can't just say "why is this
geared towards OS X?" because that's not a valid criticism.

2\. Sure, I never said it could replace a mouse. Only, I rarely ever use a
mouse because I don't want to carry around a mouse just for middle click when
I can use a Modifier key + single click to achieve the same thing. I also use
my keyboard more, even to switch between applications and rearranging my
windows using a Window Manager app like Slate. I also never said Apple's
website triggers any of my emotions so I don't know where you got that from. I
just said Apple has the best trackpads around and you can actually not use a
mouse if you don't want to since Apple's trackpad is so good. Also, a Mac app
called "BetterTouchTool" further enhances the track pad so you can do almost
anything with trackpad gestures, something you really can't do easily on
Linux.

3\. Yeah, that was just my opinion. I wasn't speaking on behalf of other
people.

4\. Okay, got it. Many of my friends use that as a reason when I ask them why
they run Linux though. They say it's cheap and they don't want to pay $2000
for a Mac which is fair enough. They just want a Unix machine and they can run
Ubuntu on a VirtualBox without paying a cent.

This may be heavily opinionated, I know, but like I said, the reason Linux
never appealed to me is because I can run Linux apps on the Mac since open
source usually means I can run it on different platforms. Take any linux app,
and I can bet 99% of the time, it's also available on the mac and I can
further bet 80% of the time, there's an alternative on the Mac which is better
(in my opinion). The truth of the matter is, there are many Mac exclusive apps
that are far better than anything available on other platforms. This is just
my opinion, that's all. You may view it differently than me, that's okay!

------
nicholassmith
"A commenter mentioned using Dropbox for synchronization as well, which seems
attractive, but I’m not sure how clean that would be on headless Linux
servers." Dropbox does work pretty nicely on headless Linux servers, you just
have a daemon running constantly with none of the GUI extensions. I use it for
keeping some code in check.

Nice list of things to try, I don't use vim but I've been putting off doing 3
of them (caps remap, iTerm and zsh).

~~~
robmil
For some (entirely irrational, I'm sure) reason, the idea of constant and
automatic deployment of my dotfiles across all my boxes gives me the shivers.
I like that extra bit of control I get from doing it with a git repo.

~~~
nicholassmith
Same, which is why I git repo them as well. It's mostly a nice way to keep a
few bits of code in check, plus handy for quick private repos without needing
all the nice stuff from GitHub/BitBucket.

------
erikcw
As a Vim user, I've always been drawn toward using vi keybindings in bash.

However, as a Mac user, all of the Cocoa text widgets more or less support
emacs keybindings, so having a working knowledge of basic emacs movement
commands has been very useful.

The emacs bash/readline keybindings also have a really neat trick that the vi
bindings don't -- keyboard macros!

Ctrl-( to start recording, Ctrl-) to stop, and Ctrl-x to execute.

~~~
nickkthequick
How is Ctrl- different from using "q" in vi?

~~~
babarock
It's a matter of muscle memory. I used Vim exclusively for several years, and
used vi-mode on my shells. Now that I've switched to emacs, my fingers are
more comfortable using Ctrl-<key> for commands.

~~~
erikcw
At least for me, macros don't work in Bash vi-mode. Perhaps it is only
implemented in emacs-mode? Or maybe it is the readline version I have in OSX.

------
edanm
One small suggestion (I make this every time vim comes up):

Don't remap "jj" to escape. Remap "jk" instead. All of the same benefits, plus
one more - if you get into the habit of nervously hitting "jk" all the time,
as most people do in vim, using "jk" means your cursos stays in place. On the
other hand, "jj" means your cursor will move.

~~~
cmatteri
I was going to suggest mapping both jf and fj to escape so you could mash the
two keys at the same time without worrying about order, but jk and kj would
work as well

------
blux
When you have already remapped Caps-Lock as an additional control, why not
just use Ctrl-[ instead of the 'jj' remapping for Escape. It saves a bit of
Vim configuration, and also works in Bash vi mode.

~~~
emidln
I just remapped Caps Lock as Escape. I use Escape a lot between tmux with vim
modes, bash, and vim itself. I do this in OSX and for the linux console and
X11.

~~~
wahnfrieden
I've also seen setups that somehow let Caps Lock work as Ctrl when used as a
modifier key, and Esc when used regularly.

------
dbbolton
I'm a full-time Vim user who has never taken to `bindkey -v`. The reason is
simple: I'm using insert mode 99% of the time, so using vi keybindings just
makes me have to hit an extra key.

However, it is useful some of the time. Since viins is pretty useless by
default, you can spice it up by setting custom bindings (e.g. copy emacs') and
get the best of both worlds. Furthermore, this may be helpful:
<http://www.bewatermyfriend.org/media/vi-mode.zsh>

~~~
JulianWasTaken
`bindkey -v` puts you in insert mode by default (there's a way to make it not
do that, but the default is insert first).

So there's not really an extra key, you get both benefits :).

~~~
dbbolton
I meant that you have to hit an extra key to actually make use of the mode's
default bindings.

------
pfedor
Do people really not use caps lock? I use it every day, when I need to type
more than one upper case character in a row. Like, every time I type NSString,
not to mention CLOCKS_PER_SEC.

~~~
ernesth
Caps Lock is also the most simple way to input Ç, À or É with a french
keyboard. Not everyone needs it though.

------
moonboots
On linux caps lock can be mapped to both control and escape, depending on
context.

<https://github.com/alols/xcape>

------
bdunbar
1\. Remap Your CAPSLOCK Key

Another upside to this is that people will gradually stop asking to use your
laptop 'for just a minute'.

~~~
jlgreco
Remapping the arrow keys to switch between Vim windows instead of moving the
cursor is a _great_ way to achieve that goal. ;)

------
pfraze
Caps remap is my favorite. My pinky is much happier.

~~~
pfedor
As any book about RSI will tell you, you should not use your pinky finger for
pressing Ctrl regardless of whether it's mapped on Caps Lock or on the default
key.

~~~
timothya
Which finger should you be using (with Ctrl in the usual place)?

------
dllthomas
I wonder if it makes sense to map capslock to, effectively, ConnectBot's use
of the "okay" button on Android - where a single tap is ctrl and a double tap
is alt/esc (or vice-versa - it's muscle memory at this point...)

------
jlgreco
One of the issues I have with tmux is that like xterm, but unlike screen, it
doesn't reflow text when you resize. I understand doing that probably is not
an ideal default, but it would be nice to have the option.

------
derwiki
> inoremap jj <ESC>

A mapping I've been using for years. I'm pretty sure between this and Ctrl-c,
I never hit escape in Vim anymore.

~~~
jrajav
I've always used Ctrl-[. It's there in all Vim installs, doesn't conflict with
anything else that I know of, and is a quick, no-glance pinky shift for both
hands (assuming you remap your Capslock to Control). Edit: Ninja'd by top-
level comment!

~~~
wahnfrieden
In OSX at least, there's a way you can make Caps Lock behave as Ctrl when used
as a modifier key, or Esc when pressed alone. Way better than adding an extra
keystroke to every time you want to hit Esc.

~~~
ryane
Do you happen to know a resource that explains how you do this?

~~~
bti
The way I do it is: map caps lock to Ctrl in System Preferences, then download
this tool[1]. The setting you are looking for is 'Control_L to Control_L'.
When you hold Control it acts as a modifier but if you tap it, it acts as
escape.

[1] <http://pqrs.org/macosx/keyremap4macbook/>

~~~
0ren
More details can be found in the ctrl/escape section in:

<http://stevelosh.com/blog/2012/10/a-modern-space-cadet/>

------
pajju
echo "set editing-mode vi" >> ~/.inputrc

This will turn on vi mode for anything that uses the readline library (there's
a good chance your favorite database command line uses it and any other apps
that also use the readline library)

------
void-star
I tried iTerm for about a year. After getting fed up watching it lag or crash
all the time. I definitely went back to stock Terminal and haven't looked
back.

~~~
Watabou
It's definitely gotten better. I've been running the iTerm 2 beta release and
it never crashes. I've literally never had a crash after I began using it.

