
Vim Anti-Patterns - microsage
https://sanctum.geek.nz/arabesque/vim-anti-patterns/
======
pjungwir
I never got into the habit of using { and }. I just use H M L
(high/medium/low) to get approximately in the right part of the screen, then
go line-by-line. You can also do 5H or 10L to get "5 lines from the top" or
"10 lines from the bottom". I make pretty good use of vim features, but I like
to mix some sloppiness with the precision. I don't often count things before
typing commands, because that breaks the second-nature quality of navigation.
If something is more than 2 or 3 objects away, I approximate. I do use
counting with t, T, f, and F a lot to hop around, including things like c2f).
Very frequently that combines well with spamming j.j.j.j.j. I use . with
trivial movement (like j or n) at least 10x more than @a. Another way to move
fast sloppily is W and B. I guess I'm saying: learn all the cool stuff you can
do, but don't feel like you have to find the most precise way to do every
little thing. If you're just starting out, relax and don't try too hard. You
can always just pick one new thing every couple weeks and try to add it to
your habits.

Oh also: he mentions O to insert above the current line. I use that a lot, but
on my systems (going back 15 years or so I think) it has always required a
pause, like vim is waiting to see if I'm typing O or some longer command. If I
type O and immediately start entering text, strange things happen. This
doesn't happen with o. Does anyone else experience this? Maybe it's just
something weird in my own setup.

EDIT: Some more "moving fast sloppily": 1G goes to the top of the file. G goes
to the bottom. Also you can not-move, but scroll the visible area so that your
cursor is on the top line (zENTER), middle line (z.), or bottom line (z-). I
use that a lot when I am Ctrl-Fing through a file, so I can see more context.

~~~
savanaly
I have two tricks for better movement, add the following to your .vimrc:

    
    
        " for scrolling up and down quickly
        nnoremap J 7j
        nnoremap K 7k
        vnoremap J 7j
        vnoremap K 7k
    

and the second (which requires a third party plugin):

    
    
        " easymotion allows us to jump to all places that could have been reached by
        " (w in this case), and the bd- indicates we want to search backwards too.
        nmap f <Plug>(easymotion-bd-w)
        vmap f <Plug>(easymotion-bd-w)
    

The first one originates from recognizing the problem from the antipatterns
article: that spamming j j j j to get down to the line you want is dumb. But I
choose not to follow the advice of most vim articles I read which is to learn
built-in tricks such as typing 10j or :<line number>. The milliseconds it
takes for me to count the number of lines I want to go down or assess the line
number of the line I'm interested in aren't worth it, I'll just tap j if the
line is close enough or J if it is five or more lines down. I think it is a
good solution.

The even better solution (and I use them both in tandem) is to install
easymotion [1] and use it like I show in the second example.

I also use gg and G to get to leap to the top and bottom of the file quite a
lot.

\---

As to your question about using O to insert above the current line, that
should not work that way. Your specific issue sounds very much like a binding
has been defined for O<other character>. Type :nmap in vim to display a list
of bindings and check for lines starting with O. It might be in your .vimrc or
some plugin defined something. I would definitely say remove the binding or
the plugin rather than put up with that, O is very useful.

[1] [https://github.com/easymotion/vim-
easymotion](https://github.com/easymotion/vim-easymotion)

~~~
Tyr42
Ahg, no I couldn't do that, I need to keep J as Join lines. That's pretty
useful to me. Kinda the inverse of gq.

~~~
savanaly
Ah, I bound join lines to :join since I don't use it that often. I still
encourage you to try binding something to 7j (or whatever number of j's feels
right). One of the best shortcuts of my life.

~~~
yamaneko
I tried to use J, but it's somewhat tied to my muscle memory already (and I'm
surprised I use it quite often joining comments and stuff). If you're like me,
remember that you can abbreviate :join to just :j.

The advantage of using J and K is that they're very vim movements, but if
can't because of :join, another workaround would be to use <PageUp> and
<PageDown> since they're redundantly bounded to <Ctrl-B> and <Ctrl-F>:

    
    
        nnoremap <PageDown> 7j
        nnoremap <PageUp> 7k
        vnoremap <PageDown> 7j
        vnoremap <PageUp> 7k

------
foob
These are all good tips but most of the anti-patterns seem to skew towards
beginners ( _e.g._ don't use the arrow keys, don't navigate in insert mode).
One that I think is more common among intermediate, and even advanced, users
is the misuse of tabs, windows, and buffers.

A lot of people have a tendency to think of each tab as corresponding to a
single open file. This is very understandable because it closely matches the
paradigm of most IDEs but it's actually an anti-pattern in VIM. Tabs are
really meant to be more like workspaces where you arrange multiple windows
into a desired layouts. You then have one buffer for each file that you're
dealing with and view them in your windows. It's perfectly fine for multiple
windows to share a single buffer or to switch out the buffer that is being
viewed in any given window. This StackOverflow answer [1] and this blogpost
[2] both go into a fair bit more detail.

If you're trying out this approach for the first time then you probably want
to add `set hidden` to your configuration in order to avoid automatically
closing buffers that aren't currently being viewed in a window. Coupling this
approach with fzf.vim [3] makes managing very large numbers of files a breeze
compared to using one tab per file.

[1] -
[http://stackoverflow.com/a/26710166](http://stackoverflow.com/a/26710166)

[2] - [http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-
vs-...](http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/)

[3] -
[https://github.com/junegunn/fzf.vim](https://github.com/junegunn/fzf.vim)

~~~
cyberpunk
Well, I've been using vi and it's brethren since about 2002 and I've pretty
much always used the arrow keys; after some point it becomes muscle memory...

I never really understood what the problem with this was; I rarely actually
use them (esc|capslock /str,ctrl+f|b etc) is usually how I move around and if
I'm wanting to move a few chars my little finger is not moving very far (at
least, on apple keyboards)...

Is this heathen territory? ;)

Do you see any big advantage of using a lot of buffers/tabs/splits over
running multiple vims inside tmux? My workflow seems to be more multiple vim's
and shells inside tmux (I have ` as my "control key" in tmux, which is right
beside z on my keyboard) which always feels quicker to me than ctrl+ww or
ctrl+w<arrow>; and I really like the "zoom" functionality there...

hitting `` to switch between windows in tmux is really nice, too.. :}

~~~
gizmo385
> Do you see any big advantage of using a lot of buffers/tabs/splits over
> running multiple vims inside tmux?

I think my personal benefit is that I don't have to make a bunch of new SSH
connections every time I want to split files in vim, I can just open up a new
buffer.

------
lunchboxsushi
I was originally a die hard Emacs user, but I started to feel a bit of strain
on the whole holding Ctrl+p, Ctrl+n etc. I was trying to find an editor/plugin
that can reduce keystrokes or at least the strain. I ran across EVIL for Emacs
which is just a Vim emulation and keybindings for Emacs users. Unfortunately I
did not like it at first the entire hjkl felt awkward and all those modes -
OMG. But after toying around with it a bit and playing the online interactive
vim learning game I started to see the benefits of Modal editing.

I can easily without leaving home row move a few letter to the right or back
with hl or f and F. but things started to get a lot more fun when you realize
that Vim is a programming editing language and it's beauty is in the commands.
This leads to amazing things that I hated before, such as deleting 2 words
back from my current position would simple be d3b. instead of shift+ctrl+left
arrow x 2 + delete.

Overall it's been about 2 months since I've started using EVIL mode for Emacs
and I love it. I'll stand by the saying that Emacs is a great OS and vim is a
great for editing text in it's modal editing.

lastly modal mode really felt powerful only after I had re-mapped my CAPS key
to ESC. I mean throughout the past decade I don't think I've even used Caps
for anything. so I've remapped the machines I work on the have caps as esc.

\- for those that think it's not reasonable to do so and the whole point of
using vim is so that you can edit machines via ssh then use vim on that
machine, my suggestion is to use tramp in Emacs with ssh or plink to get to
the server and edit (you will still have the local caps to esc key mapped)

TL;DR - Vim modal editing is amazing and feels has straining than other
editing layouts - IMO.

~~~
tgb
I love vim but admittedly ctrl-backspace-backspace is just as fast as d2b and
works in nearly any editor. The stuff i really like is stuff as dt. which will
delete until the end of the sentence, ie until the period. Or di( which
deletes everything inside the parenthesis.

~~~
clifanatic
I decided one year that I would force myself (a vi die-hard) to use emacs for
everything for an entire year, to see if I ever got used to it. One thing that
never stopped driving me crazy was that there's no efficient way to duplicate
a line like yyp in vim. The closest I could ever get in emacs was ctrl+k k
ctrl+y ctrl+y (that is, delete the line and then paste it back twice). Looking
online for a solution leads me to believe that the only way to really
effectively use emacs is to learn lisp and reprogram it yourself.

~~~
qwertyuiop924
...Which is actually quite simple. Here's my function for doing that that I
wrote just now:

    
    
      (defun duplicate-line 
        (interactive)
        (kill-whole-line)
        (yank)
        (yank))
    

Five lines, and it took me all of ten minutes to write, including looking up
the names of all the functions. Of course, there's probably a better way to do
this, but I don't know what it is. Now all you have to do is bind it to a key.

Or, of course, you could just record a keyboard macro to do it instead.

~~~
_asummers
I have mine set up like this:

[https://gist.github.com/asummers/7784d40b1bc53ee309777274e9d...](https://gist.github.com/asummers/7784d40b1bc53ee309777274e9d10997)

That way I can hit M-w when I don't have a region and get the copy behavior
for the whole line.

~~~
qwertyuiop924
That's cool. I have no idea how that works, but it's cool.

------
bpierre
Shameless plug: I wrote a small guide about how I switched to Vim, after
having “tried” for years. It’s not a universal approach, but maybe it can be
useful for people here: [https://github.com/bpierre/switch-to-vim-for-
good/blob/maste...](https://github.com/bpierre/switch-to-vim-for-
good/blob/master/README.md#switch-to-vim-for-good)

------
yes_or_gnome
This is a great resource, but the article is pretty strict on the arrow keys.
I would recommend `nnoremap`, over `noremap`, because it only disabled the
arrow keys in Normal Mode.

The author's explains his rationale in the next section, it's to prevent users
from living in Insert Mode. Fair enough. But, when making several relatively
close edits, the ability to tap a few arrow keys in Insert Mode is far easier
and less mentally demanding than any key combination that requires the user to
bounce around different modes.

~~~
DSMan195276
I don't really disagree with your overall point, the arrows keys are not
horrible, but I think for beginners removing all arrow keys is the best
approach. I used vim for a while just relying on the arrow keys, and it wasn't
until I disabled them completely that I really started to use vim. If I left
them on in insert mode, I would have just ended up using them that way, just
due to muscle memory.

I'd also add that if you remap Esc to something more manageable, leaving
insert mode for a second to move around starts feeling a lot more natural. I
still do get where you're coming from, the arrow keys do have a time and
place. But since I do all of my moving around in normal mode, leaving insert
mode to do it just 'makes sense' now and I really don't even have to think
about it.

~~~
rectang
I tried and failed to make myself use `hjkl` instead of the arrow keys. It was
a perpetual hindrance to my brain that up (`k`) and down (`j`) did not
spatially reinforce their functions.

What ultimately worked was to map the triangle `ijkl` like you normally see
`wasd` in games.

    
    
         i
        jkl
    
        i -- up
        k -- down
        j -- left
        l -- right
    

I then added two more keys beyond left and right to skip forward and back by
words.

    
    
          i
        hjkl;
        
        h -- skip backward to the beginning of a word (ordinarily `b`)
        ; -- skip forward to the end of a word (ordinarily `e`)
    

There were some echo effects since I had to replace `i`, but they were
manageable. On machines where I don't have my vimrc available I'm still
functional, just clumsy. It was definitely worth it.

My vimrc:
[https://github.com/rectang/dotfiles/blob/master/vimextra](https://github.com/rectang/dotfiles/blob/master/vimextra)

~~~
Lxr
Oh god... doesn't this mess with plugins or something?

~~~
vadskye
Speaking as someone with a similar setup, I've never had many issues with
plugins assuming the use of hjkl. The only one I can think of offhand that has
issues is indent-object.

The thing that really causes issues is my attempt to swap the roles of [ and
{, using [] to jump between paragraphs and {} to do fancy function jumping.
Vim plugins really don't like that...

------
taneq
While it's unarguably fun, I can't believe the effort required to become
actually good at vim (as opposed to just using a few of the easier features)
will ever pay itself off. (These days, at least - if you spend your days
editing code in a terminal over a dialup connection, then it's absolutely
worth it!)

Maybe there are scenarios where the busywork of text editing really is on your
critical path, but even as a fluent coder who uses some verbose languages at
times (my current project is C++ and IEC Structured Text, does it get any more
blabby?) I still spend far more of my time looking at, and thinking about,
code than I do actually typing. Any extraneous cognitive load just takes focus
away from what I'm actually meant to be doing.

~~~
mablap
Did you take the time to learn vim? Just start using it. With only a small
subset of commands you can be pretty damn efficient. The fact that you can
compose actions means that you don't need to remember every command - you can
just create them yourself. After a very short while you will "get" it. You can
say to yourself "I want to change the next three words" and immediately do it
by pressing "c3w". Or you can move around with your mouse. The former is much
faster.

BTW, I rarely use escape. I am using Spacemacs with evil-mode, and the default
"fd" is perfect for me. It's much faster than using ESC.

~~~
taneq
Oh, I've been using it for years and I'd consider myself an adequate vim user.
I'm quite comfortable in it, just using the basics - but given the small
amount of time I spend using it these days, the added investment to learn the
more seems redundant.

------
sdegutis
> _" If you have to move more than a couple of lines, moving one line at a
> time by holding down j or k is inefficient."_

This very point is actually why I moved from Vim to Emacs years ago. After
mastering Vim, I realized that Vim strongly encourages you to think a little
too much about exactly how to get there or do that thing in the fewest
keystrokes, and that it's incompatible with muscle memory. Even years later, I
still had to think too much about it. Whereas in Emacs I can just use basic
character/word/line-based movements and let my muscle memory do its thing
while I let my brain focus on the code itself instead of how to use the text
editor.

~~~
plgs
Honest question: How does Emacs help with this particular problem ?

I feel like with every editor, it involves repeatedly hitting J, Ctrl+N or
down arrow, which is inefficient. Do you have a way to get to a particular
line that does not force you to think too much about how to get there ?

~~~
sdegutis
> _How does Emacs help with this particular problem?_

What, inefficiency? Inefficiency wasn't the problem. The problem was having to
focus too much of my mind on how to use the editor. Muscle memory is
invaluable, and Vim just doesn't let my muscle memory take over if I keep
having to think about what's the most "efficient" way to move around or change
text. Emacs lets my muscle memory take over easily. I just hit C-n or M-S-] a
lot. It's inefficient, sure. But who cares? I never realize I'm doing it, and
I never feel blocked having to wait until I get to the line I want to.

~~~
aidenn0
Normal vim users aren't thinking about the most efficient way to perform an
edit, but rather just go with muscle memory. Said vim users also don't write
blog articles on how to be more efficient with vim.

~~~
sdegutis
Well after 5 years of using Vim, the muscle memory for more efficient
operations never kicked in. I was either holding "h" and "l" to move around,
or I was consciously thinking of the more efficient combined operations like
"f.ce.com^[". And that conscious thinking was _very_ distracting from the
actual code I was editing.

~~~
disease
I used vim for everyday use for almost ten years before I realized that
navigating around with the keyboard would never be as good as clicking a
mouse. All the mental overhead of trying to be efficient with vim, for me at
least, ended up being a bit of a false oasis.

I happily switched to Sublime for two years and then VS Code. I still use
emacs with Clojure though.

~~~
sdegutis
Similar story here. I use IntelliJ for Java and Emacs for Clojure. We're
porting our codebase from Clojure to Java at work, so soon it'll all be
IntelliJ, which will be pretty sweet. I do kinda miss Paredit, but IntelliJ
makes up for it with lots of other pretty sweet features.

~~~
slgeorge
Out of interest did you try using the Vim plugins for Clojure?

I'm only playing, but found a good set-up with vim-fireplace; vim-clojure-
highlight; vim-sexp; Vim-sexp-mappings-for-regular-people; vim-surround and
luochen1990/rainbow

------
Philipp__
Not trying to start a flame war here, but I in recent few years I am seeing
Vim being more popular, and I feel it adoption in terms of younger developers
(those who weren't programming when original Vi was around) grows. (Ok, please
forget about GUI editors, they have their audience, and I am not comparing any
of those facts to them) I used Vim for 3 years, and found philosophy and
implementation of modal editing amazing. Writing and manipulating code in it
went like bread and butter.

But then I told myself, hey, why not try Emacs? So I've been using Emacs for
~6months now and cannot but notice that community is much more niche and
humble compared to Vim. Just look at the sheer number of color schemes
available for both editors. And I had to agree, Vim was far superior text
editor, but that wasn't enough to keep me away from Emacs, since I gave the
advantage to other things (everything else) that Emacs does better.

I tried EVIL mode, and it is amazing, but something just felt wrong using it
inside Emacs. I wasn't using either Emacs or Vim. I would often shuffle and
mix commands, sometimes I would do :w, sometimes C-x C-s. So I decided to
ditch Evil until I get more comfortable with Emacs key bindings. I came to
Emacs because of Lisp (and general FP audience is much, much, more based
around Emacs, makes sense), amazing tools and plugins which I found more
stable, better designed, and it is weird to say this but things just worked
with Emacs, things like auto-completion and code navigation (ivy, ace-jump-
mode) were really fast, hustle free experiences. Disclaimer, I have never
touched older versions of Emacs, spent my time in 24, and now in 25, so many
of _myths_ and problems that Emacs got known for over the time, I think,
aren't there anymore.

And to sum things up, what is really weird to me is that functional
programming is on the rise and every year I see it more and more being
adopted, but that doesn't help Emacs audience grow. (Maybe because I am young,
and I am nerd often found in nerd communities where things like FP are often
praised, but in the real world considered a bit awkward or esoteric.) I showed
up at the FP workshop few weeks before in local dev/hacker community place,
everybody rocking Sublime Text/Vim, but nobody used Emacs, people were looking
at me like I was an Alien. Spacemacs is doing good job at attracting people,
but maybe Emacs will stay that programmers/nerd phenomenon, the all-mighty
lisp OS, that in the end people often reject or overlook. And why is it like
so? I do not know. If somebody can sink into and learn Vim, I don't see a
reason why it is different story with Emacs.

~~~
qwertyuiop924
Emacs was far easier for me than Vim was. To this day, I have no idea how
people learn Vim. And the scripting is awful, especially compared to Emacs,
which is really a script interpreter that has a built in text-editor script
and some useful primitives for text editing.

~~~
the_duke
Best of both worlds: [http://spacemacs.org/](http://spacemacs.org/)

Modal editing is far superior, once you learn it.

Emacs runtime and configurability thanks to Elisp is far superior to VimL.

So just use Spacemacs. ^^

~~~
sham1
It works until one wants to create their own configuration stuff and functions
and stuff. Much rather just stick with normal emacs configs and stuff and put
in EVIL-mode once my pinky finger can no longer reach Ctrl (Not a worry seeing
as I need Ctrl for gaming as well).

Also, installing plugins requires one to create one's own layer? Eww.

~~~
the_duke
It's complicated, true.

But it does a lot of work for you.

I started to create my own setup from scratch with Evil etc.

But recreating all that Spacemacs has, especially with customizing all the
plugins for Vim keybindings, is countless hours of work.

You can skip the layers and side-install custom plugins quite easily though.

------
glormph
Useful stuff. I'd add typing J to move the next line to the end of the current
line. A move I normally do by being on the next line and then type
0dwiBackspace.

Only just figured that one out by mistakingly having the capslock on when
moving around.

~~~
sevensor
That's how I discovered "K". Which is usually not what I want, and tends to
provoke a moment of "where did this garbage come from and where did my code
go?" panic. I'm close to masking it out, but I remap very reluctantly.

------
dopeboy
> It’s always useful to jump back to where you were, as well, which is easily
> enough done with two backticks, or gi to go to the last place you inserted
> text. I

And here I was undoing and redoing the entire time.

~~~
protomikron
Ha, I do the same - you always learn something new in vim.

For me the biggest boost in Vim was configuring the shell (i.e. readline via
.inputrc) to use my vim key bindings, so I can use it without arrow keys. Not
because of efficiency, but more for wrists comfort.

Furthermore I am in the camp of mapping ESC to 'jj'. My index finger has more
power and using the pinky (e.g. via CAPS or ESC) is too exhausting for me.

------
JackMorgan
For anyone who wants to build muscle memory in Vim I'm writing 10 Minute Vim,
a book of pre-made exercises for practising advanced macros, RegEx, and
navigation. It's already helped me learn a number of new commands in just a
short time.

[https://leanpub.com/deliberatevim](https://leanpub.com/deliberatevim)

------
sevensor
This is good solid advice -- I have a problem with vim advice that golfs more
unusual circumstances to save a keystroke or extensively remaps the keys.
(Generally the only thing I remap is F1 to ESC, because I use laptops that
place them inconveniently close together.) Devoting too many cognitive
resources to text entry is also an anti-pattern!

~~~
Lxr
I highly recommend not using the Esc key, remap to jk or caps lock that you
can reach without moving your hands. It makes a pretty big difference.

~~~
servlate
Even easier to use the default Ctrl + [ instead of ESC.

~~~
coldpie
I've somehow gotten in the habit of using ^C for Escape. Guess it feels
natural from using it in Bash to restart typing my command or to kill a
program.

~~~
servlate
Related: [http://stackoverflow.com/questions/5030164/whats-the-
differe...](http://stackoverflow.com/questions/5030164/whats-the-difference-
between-ctrlc-and-ctrl)

------
tremon
Note that d2wi and c2w are not exactly equivalent: d2w will consume trailing
whitespace after the second word, while c2w will not. FAFAIK, there is no
exact equivalent of d2wi using c. I usually end up using c2aw, but that will
also consume any word characters preceding the cursor (not a problem for me
since I usually navigate using b and w).

~~~
no_protocol
> d2wi and c2w

There is a nice chart on this page with a few more inferior/superior motion
commands:

[http://vimcasts.org/episodes/modal-editing-undo-redo-and-
rep...](http://vimcasts.org/episodes/modal-editing-undo-redo-and-repeat/)

One problem I commonly see with most vim advice articles is they just have too
many tips for the reader to consume at once. But if you just make sure to pick
up at least one of the tips, you'll at least gain something.

~~~
skykooler
Indeed. I try to come back to pages like this every few weeks, and to start
training myself to use one more of the tips from it. Today it's * and # to go
to the next/previous instance of the word under the cursor.

------
nocman
"Hitting Escape is usually unnecessary; Ctrl+[ is a lot closer, and more
comfortable."

I agree with a lot of the things in this article, but wow, I could not
possibly disagree with this quote more. Ctrl+[ is _WAY_ more uncomfortable
than using the Escape key.

Granted, I have _many_ years of vim usage that have made hitting Escape a
habit, and that probably plays a big part in it, but Ctrl+[ is downright
painful for me (and yes, I sat and tried it for a while in vim to see what it
would be like).

I can get from the home row to Escape and back with very little effort, though
I understand that is not the case for many people. Perhaps it is due to the
fact that I use my ring finger to hit Escape rather than my pinky (which would
be a lot more work, I think).

~~~
btym
I suggest remapping Caps Lock to CTRL if you haven't remapped it already.

~~~
karmajunkie
Plug for Karabiner on OS X, which lets you use capslock as a control if you
press it with another key, and escape if its released on its own. It has
ruined me for other computers that don't have this set up. There's also a way
to do it under Linux, but I can't remember what the package is that lets you
do that.

~~~
steeef
You're thinking about xcape:
[https://github.com/alols/xcape](https://github.com/alols/xcape).

FYI, Karabiner is incompatible with MacOS Sierra. There's a project
(Karabiner-Elements) to replace its (and Seil's) functionality, but I don't
believe it has feature parity yet: [https://github.com/tekezo/Karabiner-
Elements](https://github.com/tekezo/Karabiner-Elements)

~~~
karmajunkie
Wow thanks for the heads up... that would have been a shitty thing to discover
the hard way!

------
yumaikas
I'll just drop my 2 cents here as a vim user. I've tried emacs a number of
times, but I've gotten too familiar with what vim has on offer.

I think where vim often wins over emacs is the 110 vi modes that every IDE
eventually gets. Vi is an idea that can prosper in many environments.

Emacs is kinda like smalltalk. To get much benefit from it, you have to buy
into it whole hog, or not at all. I can write C# in VS with vim keybindings,
go in sublime text, and then just hack on a Lua snippet in vim itself. Emacs
has ways to work with all those, but that requires a new skill set that I
don't need at the moment. Maybe after I graduate from college, but right now
isn't the time for me.

------
stewbrew
While these tips are good per se, in retrospect I don't think it's that a good
idea to tie your muscle memory that much to a single piece of software. I'd
say enjoy the cursor keys. Moving around in insert mode is ok too.

~~~
rocky1138
This is normally true, except that in order to be good at your job as a
developer, you have to be good with your tools.

It helps that vim is installed by default in every modern OS.

~~~
oblio
But in reality you'd constrain yourself to using Vim just because it is the
lowest common denominator (i.e. it is available - vi - in Sun OS 5.2 & co).

Otherwise, if it's a really modern OS, there's a plethora of modern, fast,
cross-platform editors that follow CUA conventions.

~~~
Spivak
Right, but a common characteristic of modern editors and IDEs is that they
attempt to be uncontroversial and follow the 'intuitive' keybindings because
they're what people are used to from word processors.

These editors have sparked a holy war and a cult following not just because
they're powerful, but because they're opinionated. They prefer efficiency and
customization over familiarity.

I will freely admit that there's only only so many of those programs that I
can handle in my life, but my text editor is one so frequently used that it's
worth the investment.

------
oolongCat
Instead of

    
    
      c2w

I prefer

    
    
      v2ec
    

selecting with v helps me avoid making mistakes.

~~~
grault
ct" or even ci" (or ci) ci] etc) is really useful to reset the inner contents
of text delimited by ")] etc.. I use these a lot -
[http://fuckyeahvim.tumblr.com/image/122372862496](http://fuckyeahvim.tumblr.com/image/122372862496)

~~~
vacri
ci", ci), ci]... I love these, and use them all the time.

------
deathgrindfreak
I find that marking my place with "ma" and returning to it with "'a" is a huge
productivity boost. Of course the "a" is just a label, you can use any
character (this allows multiple marks as well).

~~~
lunchboxsushi
if you only browse code use gi, that saves me a ton of time. gi brings you
back to last inserted text.

------
SCdF
So I have used ST3 for years now, and I realise that I'm slowly moving toward
Vim. I started using Vim shortcuts in Chrome, and now I use Vintageous in ST3.
Vintageous is good, but it is incomplete. It can't even do the first examples
on this article (ctrl+f / ctrl+b) correctly.

Thinking I should just bite the bullet. Would mean I could work on a server
using Mosh + Tmux as well, which should be rather nice.

What would the current canonical guide be for getting up and running with Vim,
with plugins, auto-complete[1], inline linting, multiple carets etc?

[1] Just the ST3-style of parsing out tokens in the same file

~~~
Lxr
Note sure about a guide but I would start without any plugins at first.
Otherwise you never learn what's vim and what's a plugin, and working on
remote servers will be a pain. Also for a lot of plugins, there's a better way
of doing things in native vim if you learn it properly.

What worked for me to bite the bullet at uni was making myself do an entire
programming assignment in vim and not opening in any other editor. If you
commit it doesn't take that long to learn. Keep a list of commands handy and
learn a few new ones each day.

------
dvcrn
I can recommend vim-hardtime [0] for anyone wanting to force themselves to
learn the "vim-way" of navigating. It disables n subsequent presses of hjkl
where n is any number you want.

For me I set it up to not allow more than 2 steps in any given direction to
remind me to use jumps instead.

[0]: [https://github.com/takac/vim-hardtime](https://github.com/takac/vim-
hardtime)

------
bcheung
<C-c> works likes escape almost all the time. Mapping the caps lock key to
Ctrl makes hitting <C-c> super easy. I usually use that instead of escape.

In general I would agree 1 character at a time is an anti-pattern but it needs
to be balanced with the cognitive load of counting how many words or deciding
what is or is not a boundary when there are symbol characters.

~~~
icen
This is why `f` is really my workhorse key in vim.

------
godelski
Movement is an important part of vim, but so is auto-competing. Probably the
biggest thing that helped me greatly improve speed in vim was learning the C-x
keys and that they are context aware. Having to repeat an entire or similar
line/s becomes quick without having to go back to that place. Why move in the
file when vim can find the text for you?

~~~
nocman
Pretty funny. I found myself asking "What does C-x do when autocompleting?" I
took the 'x' literally, instead of realizing you meant C-n, C-p.

xD

~~~
Tyr42
In insert mode, C-x actually lists the different completion methods, so it's
actually accurate.

^X mode (^]^D^E^F^I^K^L^N^O^Ps^U^V^Y)

I really like having C-x C-f, which autocompletes file names.

~~~
nocman
yeah, see my reply to the parent below. :D

------
mastazi
> If you happen to know precisely where you want to go, navigating by
> searching is the way to go, searching forward with / and backward with ?.

It's worth noting that, after searching with ?, you can still move back and
forth through occurrences using N and n, in the same way you would after using
/ for a search.

------
tomc1985
While I prefer vim for text-mode editing, it is so frustrating that it just
has to use its own damn keyboard shortcuts and that the ones burned into
muscle memory from 20+ years of using pretty much every text editor under the
Windows/DOS sun don't work without significant hacking.

------
bagol
My favorite is mapping '()' to 'vi)', '[]' to 'vi]', '{}' to 'vi}'. So I can
read is as "grab parentheses" instead of "visual inside parentheses"

------
vlunkr
> don’t forget you can yank, delete or change forward or backward to a search
> result.

Did not know this! (although I've been on vim for ~a month) That's a great
trick. Much easier than trying to count words.

~~~
pjungwir
I agree it is very nice, although you should know one caveat:

deleting/yanking with / and ? will do whole lines, so it may go past the
match.

deleting/yanking with t, T, f, and F will go up to just the char you want, but
it won't search onto the next line.

I wish there was a way to get a char-by-char multiline search, so I could e.g.
cut/yank a whole sentence (something like d/.). But I haven't found it. I
wonder if anyone else knows of a way?

~~~
tomku
You might find vim-sneak useful: [https://github.com/justinmk/vim-
sneak](https://github.com/justinmk/vim-sneak).

[https://github.com/easymotion/vim-
easymotion](https://github.com/easymotion/vim-easymotion) is another plugin
that does something slightly different, but also useful.

------
lucb1e
Page loads very slow and uses Wordpress. In case it goes down:
[http://archive.is/JaOXd](http://archive.is/JaOXd)

------
choicewords
My eyes. Good content, but very hard to read.

------
rhinoceraptor
I have a programmable keyboard, so I just map escape to be right above tab,
where tilde usually is.

~~~
sotojuan
I use Karabiner + Seil to make my Macbook Pro's Caps Lock be Escape when hit
by itself and Control when hit with another key. Unfortunately this doesn't
work on Sierra yet so still on El Cap.

~~~
lathiat
the lack of tilde doesn't drive you mad?

This is built-into my Lenovo Carbon X1 (gen2) keyboard, drives me bananas as I
use tilde quite a bit (being home on linux):
[http://www.lenovo.com/images/gallery/1060x596/lenovo-
laptop-...](http://www.lenovo.com/images/gallery/1060x596/lenovo-laptop-
thinkpad-x1-carbon-2-keyboard-3.jpg)

What kills me more though is that "Shift" is now caps-lock if you double hit
it (because home/end are where capslock normally is). The standard way I wake
up a machine when it's locked/asleep/blanked? Tapping the left shift key a few
times. ergh.

Should get a gen3, they reverted to a more sane keyboard layout.

------
lathiat
This is a really good guide.

------
jnordwick
I started off using Emacs a lot (like tons and tons of Emacs with tons and
tons of custom modes, functions, and craziness - network pong anybody?). For
almost a summer, my xinitrc at the school labs literally opeed up a full
screen Emacs; it was my window manager too.

The simplicity of vim (and pretty colors) drew me in. Plus as I learned more
sed/ed, I understood vi more. That, and a slow connection from off campus
really sucks. I learned that too pretty well. Well enough to hack together
some vim scripts, but nothing near my Emacs level. I feel like vim mode
hacking is a beast you need to be specially equipped to handle (and I can
write APL in any language so it isn't the syntax).

Then Eclipse and IntelliJ came around and I only really used vim for quick one
off stuff (if I didn't use printf, echo, or cat). The only time I used vim was
for C/C++ or something esoteric, like KDB+/Q/K, that didn't have their own dev
environment (unlike say VHDL or Matlab where I could sit in their ugly
cocoons).

Now I'm growing tired of the very buggy, slow Java environments that seem to
require a gaming rig to compile HelloWorld.java (or sorry, HelloWorld.xml with
SpringBoot). And I see all these poor Emacs clones playing catchup with 2000.
You have editors written in JavaScript inside a web browser with modules
transpiled to JavaScript (for some reason JavaScript is too low-level to write
text editing packages in now -- God help us all). That, and they don't support
a tenth (I'm being generous) of the functionality that Emacs does and they
probably never will.

What is so hard about an extensible text editor? Just getting the basic hooks
down for self-insert and movement without having to go to swap?

I remember when Emacs was called "Eight Megabytes and Constantly Swapping". I
now see Atom routinely take up over 800 MB. And it still can't play Pong.

Now with Rust and other languages, I'm back home in Emacs, but the keystrokes
do tend to bother me a little. I liked the HJKL movement keys in vim - I just
hated the modality and think I spent more time trying to figure out "my cursor
is here, but I need move it over there - so first I need to jump on that log,
shoot the rocket to knock down flowerpot then run quickly while the line is
falling to catch it and K it to the next line" \-- like some sort of weird
text editing puzzle (I wonder if you could make a vim code golf puzzle set).

Emacs has these bindings that feel like finger yoga, even when I've remapped
Caps, control, half my F-keys, etc. What I really need to do is remap my toes
to my hands, I think.

It would have been really nice to see C-[hjkl] style movement (with maybe
CS-[HJKL] be the distance mods or something). It's too late now. You of course
you can remap those keys, but too much of that behavior is baked in to
people).

Maybe one day when I'm old and gray I'll do the Knuth thing and start a new
text editor, but before that I'll probably need to redo the monitor, mouse,
and keyboard and that is just too much right now.

~~~
aidenn0
evil-mode

vim keys in emacs.

~~~
jnordwick
I don't want vi modality. I find it more annoying than emacs yoga-esque
bindings. I want more sane emacs bindings.

~~~
qwertyuiop924
You can make them yourself, and I think there are some packages for that as
well.

~~~
aidenn0
Coming from evil-mode, I often have to make them myself, and it is a pain.
Every mode needs new keybindings to fit in with whichever scheme you use. I
imagine it would be worse with custom keymappings that aren't evil-mode,
because I can at least use the default keybindings in input mode as-is with
evil.

------
foo101
Moving to the far left-corner of the keyboard to reach Escape has been a major
annoyance for me. On the other hand, the Caps Lock key on my keyboard is
almost useless. I never use that key. Is there a way to map Caps Lock to
Escape in Vim?

~~~
minitech
Run setxkbmap in your .xinitrc if applicable:

    
    
      setxkbmap -option caps:escape
    

Linux desktop environments’ keyboard configuration tools should also let you
do this.

~~~
foo101
I am using Windows. Is there a lightweight solution to map Caps Lock to Escape
on Windows?

~~~
jackrh
Copy and paste the below into a .reg file and run it. I used Sharp Keys (
[https://sharpkeys.codeplex.com/](https://sharpkeys.codeplex.com/) ) to create
it, but since every major Windows 10 update resets your key mappings I just
extracted it from the registry and double click the reg file after each
update.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,01,00,3a,00,00,00,00,00

------
clifanatic
> Vim isn’t the best tool for every task

Begone with your heresy!

