Vimtutor Arrow Keys V/S Hjkl

VimTutor arrow keys v/s hjkl

You don't have to move your hand from the touch type position to use hjkl, whereas you do if you use the arrow keys.

Why hjkl is highly recommended?

It is a bit like using the mouse. Every time you reach the mouse, or the arrow keys, you have to move your hand back to the main part of the keyboard to access other very common commands like i, y and you will lose some time.

Rather than the time, I think that the main issue is you are losing some focus on what you are doing, because you have to look at (or think about) your hand rather than the screen.

Why hjkl is highly recommended?

It is a bit like using the mouse. Every time you reach the mouse, or the arrow keys, you have to move your hand back to the main part of the keyboard to access other very common commands like i, y and you will lose some time.

Rather than the time, I think that the main issue is you are losing some focus on what you are doing, because you have to look at (or think about) your hand rather than the screen.

Speed up cursor in macvim with janus

The simplest solution would be to drop Janus which is full of settings and plugins (30) that you probably don't use/need. Or, at the very least, review all of the decisions made for you by complete strangers and remove/reset anything you don't need.

A better solution (in the long term) would be to learn about motions and text-objects: for anything other than very short movements hjkl and the arrows are equally useless when you get used to bBeEwW^$fFtT{}()[]<C-f><C-b>/? and so on.

As I like to say, :help motion.txt will blow your mind.

Or $ vimtutor, actually. Did you do it?

Vim: transitioning from mouse to movement

I think that my speed (and posture at
the computer) will be improved by not
having to escape from insert mode

No, you must escape from insert mode right after you typed what you want. It quickly becomes a reflex, so you don't really lose time (I sometimes even press escape after completing a web form...). Normal mode isn't just for moving around, it's used to perform most operations (save from typing): for instance deleting or moving sections of text. You also benefit from entering insert mode with the appropriate key: o to start a line, S to replace a line (while keeping indentation), A to move to the end of the line, c+motion to replace a few words or until a given character... All of these save keystrokes.

The mouse seems fast, but in reality it isn't precise, so you lose time (in addition to the constant back and forth with the keyboard). ViM has a long list of moving commands (see :help usr_03) which, when mastered, are faster than the mouse in most situations.

Use search the most you can (/, ?, *, #, f, t...). I personally use Ctrl+(d,u,f,b) a lot. Also, Ctrl+(o, i) and `` are really useful to go back where you were before a search or something else.

h, j, k, l are there to place your right hand near to useful commands (i, u, o...): I always have my fingers on them. The arrows force you to move your hand a lot.

Try to look at a few commands in :help, then use them a lot, and you'll get habits about what you should use to move according to the situation. Nobody uses ViM the same way.

Moving the point between in charactors by quick search

If you are before the point you want to go:

/version then <Enter>

If you are after you want to go:

?version then <Enter>



For more info type:

:help search-commands

Becoming better at Vim

"Why, oh WHY, do those #?@! nutheads use vi?" is a nice introduction to "the Vim way", especially about text objects which are one of the most defining features of Vim.

What are the most-used vim commands/keypresses?

Here's a tip sheet I wrote up once, with the commands I actually use regularly:

References

  • vim documentation online
  • advanced vim tips
  • more useful tips and graphical cheat sheet

General

  • Nearly all commands can be preceded by a number for a repeat count. eg. 5dd delete 5 lines
  • <Esc> gets you out of any mode and back to command mode
  • Commands preceded by : are executed on the command line at the bottom of the screen
  • :help help with any command

Navigation

  • Cursor movement: ←hjk l→
  • By words:

    • w next word (by punctuation); W next word (by spaces)
    • b back word (by punctuation); B back word (by spaces)
    • e end word (by punctuation); E end word (by spaces)
  • By line:

    • 0 start of line; ^ first non-whitespace
    • $ end of line
  • By paragraph:

    • { previous blank line; } next blank line
  • By file:

    • gg start of file; G end of file
    • 123G go to specific line number
  • By marker:

    • mx set mark x; 'x go to mark x
    • '. go to position of last edit
    • ' ' go back to last point before jump
  • Scrolling:

    • ^F forward full screen; ^B backward full screen
    • ^D down half screen; ^U up half screen
    • ^E scroll one line up; ^Y scroll one line down
    • zz centre cursor line

Editing

  • u undo; ^R redo
  • . repeat last editing command

Inserting

All insertion commands are terminated with <Esc> to return to command mode.

  • i insert text at cursor; I insert text at start of line
  • a append text after cursor; A append text after end of line
  • o open new line below; O open new line above

Changing

  • r replace single character; R replace multiple characters
  • s change single character
  • cw change word; C change to end of line; cc change whole line
  • c<motion> changes text in the direction of the motion
  • ci( change inside parentheses (see text object selection for more examples)

Deleting

  • x delete char
  • dw delete word; D delete to end of line; dd delete whole line
  • d<motion> deletes in the direction of the motion

Cut and paste

  • yy copy line into paste buffer; dd cut line into paste buffer
  • p paste buffer below cursor line; P paste buffer above cursor line
  • xp swap two characters (x to delete one character, then p to put it back after the cursor position)

Blocks

  • v visual block stream; V visual block line; ^V visual block column

    • most motion commands extend the block to the new cursor position
    • o moves the cursor to the other end of the block
  • d or x cut block into paste buffer
  • y copy block into paste buffer
  • > indent block; < unindent block
  • gv reselect last visual block

Global

  • :%s/foo/bar/g substitute all occurrences of "foo" to "bar"

    • % is a range that indicates every line in the file
    • /g is a flag that changes all occurrences on a line instead of just the first one

Searching

  • / search forward; ? search backward
  • * search forward for word under cursor; # search backward for word under cursor
  • n next match in same direction; N next match in opposite direction
  • fx forward to next character x; Fx backward to previous character x
  • ; move again to same character in same direction; , move again to same character in opposite direction

Files

  • :w write file to disk
  • :w name write file to disk as name
  • ZZ write file to disk and quit
  • :n edit a new file; :n! edit a new file without saving current changes
  • :q quit editing a file; :q! quit editing without saving changes
  • :e edit same file again (if changed outside vim)
  • :e . directory explorer

Windows

  • ^Wn new window
  • ^Wj down to next window; ^Wk up to previous window
  • ^W_ maximise current window; ^W= make all windows equal size
  • ^W+ increase window size; ^W- decrease window size

Source Navigation

  • % jump to matching parenthesis/bracket/brace, or language block if language module loaded
  • gd go to definition of local symbol under cursor; ^O return to previous position
  • ^] jump to definition of global symbol (requires tags file); ^T return to previous position (arbitrary stack of positions maintained)
  • ^N (in insert mode) automatic word completion

Show local changes

Vim has some features that make it easy to highlight lines that have been changed from a base version in source control. I have created a small vim script that makes this easy: http://github.com/ghewgill/vim-scmdiff

Preferred way to move around in vim (normal mode)

I like the cheatsheet of Ted Naleid. It's like a reticle so you can easily find the horizontal and vertical movements. Put it on a wall next to your monitor and you will soon pick up new movements on the fly.

The movements that I liked recently are:

  • () and {} which let you hop function wise in source code
  • / and ? + n/N just search, you normally know where you want to go
  • fx and tx - to jump to or before the next character x
    of course you can do a 2fx to jump to the second occurrence of x, like you can do with all movements
  • % to move between starting and ending parenthesis


Related Topics



Leave a reply



Submit