
Vim - Putting arrows to use - mmozuras
http://codingfearlessly.com/2012/08/21/vim-putting-arrows-to-use/
======
RegEx
I believe many VIM users overestimate the importance of using h,j,k,l in
comparison to numeric modifiers. Holding down j to scroll down the page is no
more "right" than holding down the down arrow, in my opinion.

The following made me considerably faster:

* Relative Line numbering (For Vim 7.3). G/gg stop being convenient for frequent line movement once your file goes beyond 100 lines. Doing math in your head to figure out if line 589 is 16 lines from 605 takes way too much effort. Append this[0] to your ~/.vimrc, and then CTRL-l will toggle relative/absolute line numbering. So in relative mode, you see a line is 20 up from your cursor, and 20k takes you there with no guessing or holding down keys.

[0]: <https://gist.github.com/3418841>

* Learn the following: f,F,t,T. Combine them with c and d.

* zz => make current line appear in middle of the screen.

* H,L,M

* w,W,b,B. Combine with numeric modifiers (5dW)

* CTRL-u, CTRL-d, CTRL-f, CTRL-b

* % for block highlighting. Works well with curly braces by default, you may need to pick up extra plugins for ruby/python.

* g; will cycle back to the last places you were in insert mode. g, will cycle forward.

~~~
amadeus
Even better, just learn to use EasyMotion, it's one of the most efficient ways
of navigating around a file:

<https://github.com/Lokaltog/vim-easymotion>

~~~
johncoltrane
I've tried it and didn't like it at all.

The main problem is how it replaces the letter I'm searching with another
unrelated one, making all the matches practically unreadable. To me, at least.

    
    
        set incsearch
    

and

    
    
        /foo
        ?bar
    

are more than enough for my needs.

~~~
amadeus
Basically what dedward said before me.

EasyMotion is not for searching, it's for moving the cursor deliberately to a
place onscreen where you need to make an edit.

~~~
johncoltrane
Yes, I know.

Searching is how I move to where I want.

It's a lot less confusing to me than EasyMotion's logic, it's consistent
whether the word I want to jump to is visible or not and it's a native
feature.

Well, I was curious when it was released so I've used it for a couple of weeks
and found it horrible and confusing. Obviously many people like it so let's
say it's a matter of taste.

------
samdk
I use my up/down keys to move between visible lines (rather than real lines,
which is what they and j/k do by default). This can be helpful occasionally
when you have lines wrapped for something that's text rather than code.

    
    
        " up/down move between visual lines
        " instead of actual lines when wrapped
        imap <silent> <Down> <C-o>gj
        imap <silent> <Up> <C-o>gk
        nmap <silent> <Down> gj
        nmap <silent> <Up> gk
    

(You could also map j/k to just do this if it's something you use often, but I
prefer not to.)

------
marcrosoft
I don't remember where I found it but the best remapping I ever did was to map
the sequence 'kj' to esc.

kj is rarely used in a word, and when it is it isn't a big deal.

inoremap kj <Esc>

~~~
mmozuras
That's useful indeed - I have both kj and jk mapped to Esc in my vimrc.

<https://github.com/mmozuras/vimfiles/blob/master/vimrc#L75>

~~~
pilgrim689
Interesting, I always did jj, but kj or jk feels speedier. Thanks for the tip!

------
lucian1900
I use arrow keys for movement all the time. Not always, but I found no value
in forcing myself otherwise.

~~~
mmozuras
Interesting. How long have you been using Vim?

~~~
ibotty
you did not ask me, but: when i'm busy thinking about the code, when i'm not
typing for a long time, i lay back and browse the sourcecode with arrows and
(up and down or pg-up and pg-down). not that fast, sure. but can be done with
one hand, the other is scratching my head or what helps me think.

~~~
latortuga
Page up and page down are part of my must-learn-asap shortcuts when learning a
new editor - once you have hjkl and ctrl+f/ctrl+b ingrained, browsing code
while keeping your hands mostly over the home row becomes a lot easier and you
don't have to move your hands back and forth. I've found that if I want to
browse my code with one hand, the scrollwheel on my mouse does the trick :)

~~~
ibotty
ah yes. mouses. i knew there was another input controller...

(not to be misunderstood, i use mostly hjkl and ctrl-d and ctrl-u (half-screen
up and down). and i find the mouse uncomfortable.)

------
kondro
My issue has always been one of muscle memory.

The hjkl keys are fine to use when in Vim, but the majority of other products
(browsers, word processors, spreadsheets, etc) don't support them for
movement. So I have a constant context-switch in my muscle memory when moving
between these different applications.

On a Mac keyboard, I find arrow-key navigation with my pinky finger very
efficient… only requiring the rest of my fingers to move from the home row
when pressing right.

I'm not sure this would work for everyone… but for me, one set of muscle
memory is superior to convincing my nervous system to context-switch.

------
nathan_long
Not to be too cranky, but the rationale for avoiding the arrow keys is to keep
your hands on the home row. So anything useful you find to do with them, if
you do it often, will be inefficient.

~~~
mmozuras
Good point and something I should've written in the post. Text moving is not
something needed very often, but I find using arrows in this case more
pleasant than <gv or [egv. In normal mode, I'll usually use <<, because I'm
already used to it.

------
rednum
It's a nice idea, but I don't buy it. What I like most about vim is how few
unnecesary moves I make with my hands - in particular my wrists stay in the
same place all the time; reaching for arrows would require moving the whole
forearm, which I don't like and which breaks my flow.

Also I'm curious about this quote from OP:

    
    
      I just might remap hjkl to split navigation, 
      because I use hjkl less and less, favoring 
      navigating in other ways. Sounds crazy, I know ;)
    

Can you elaborate on your habits that cause it?

~~~
mmozuras
I got used to better ways to navigate in Vim - RegEx pointed out quite a few
of them - <http://news.ycombinator.com/item?id=4414502>. I would especially
emphasize f,F,t,T and w,W,b,B,e,E.

------
aartur
I'm a rather advanced Vim user (10 years, vimrc with custom vimscript, use
many shortcuts for movement), but I find it unproductive to NOT use arrows in
insert mode. Example: inserting 'x' two characters before current position.

With arrows: <LEFT><LEFT>x<RIGHT>

Without arrows: <ESC>hix<ESC>lli

It also much depends on a keyboard design, the laptop-like often have arrows
under ENTER and using them doesn't require hand movement.

~~~
qu4z-2
In that situation I'd likely as not just backspace to the offending location
and continue typing. Although I have been known to map caps+hjkl to the arrow
keys.

(I'm assuming your situation is a typo while you're inserting a short string,
rather than just defaulting to insert mode)

------
fiona
Cool idea. I read an article here a couple months ago about vim autocomplete
and I mapped my tab key to autocomplete, but that was super annoying for, you
know, adding indentation.

Now I've got my arrow keys mapped to Nop in all modes except I mapped my right
key to autocomplete in insert mode, which has worked pretty well for the last
10 minutes. I'd really like to start using autocomplete more, so for me it's
handier than text moving.

~~~
RegEx
Check this[0] out. Autocomplete when typing words, indentation otherwise.

[0]: <https://gist.github.com/3418565>

~~~
fiona
thanks, that's a way better solution.

------
trtg
A very small corner case here, but on certain keyboard layouts, hjkl is
actually harder to use than the arrow keys. To be more specific, I use an
alphagrip keyboard most of the time where left,right,up,down are all under the
left thumb and a trackball is under the right thumb. The way I interact with
vim is thus very different from most folks, I imagine.

------
asb
I prefer to map left and right arrow to navigate :bprev and :bnext. Paired
with buftabs, I find it rather handy
<http://www.vim.org/scripts/script.php?script_id=1664>

------
artursapek
From my funny looking vimrc: navigating between splits with Alt+HJKL

    
    
        nnoremap ¬ <C-w>l
        nnoremap ˙ <C-w>h
        nnoremap ˚ <C-w>k
        nnoremap ∆ <C-w>j
    

(Mac :P)

------
jwpeddle
I map left/right to next/previous tab, and up/down to next/previous buffer,
since if I switch files my hand is often coming from the mouse and the arrows
are along the way.

