4

I know that in insert mode I could navigate through the document by using the arrow keys or by using Ctrl-o to escape insert mode temporarily. My question is: Is there any other way to navigate through documents instead of using those keys or temporarily escaping?

Thank you.

OK guys, just found a solution for my own question in which I use imap to map keys in Vim in insert mode.

 imap <C-n> <Down>
 imap <C-p> <Up>
 imap <C-@> <C-Space>
2
  • 8
    Vim is designed for navigation to be done in normal mode and text insertion to be done in insert mode. You will be much happier and more productive in the long term if you learn to use Vim the way it was designed to be used instead of fighting it. If you try it for a while and find you really don't like a moded editor, you may want to try Emacs. It is another very powerful editor, but lets you navigate and edit without changing modes.
    – garyjohn
    Jan 7, 2013 at 7:05
  • 1
    if you dont care for modes, you could give... emacs... a whirl. shudders
    – ash
    Jan 8, 2013 at 4:33

4 Answers 4

5

Another upvote for @garyjohn's comment, here.

By following that path, you are certainly shooting yourself in the foot. I see at least two big mistakes in your approach.

  • As @garyjohn wrote, you are "fighting" against Vim's most crucial aspect. Modality is at the core of everything that makes it the awesome text editor it is. If you consider its proverbially steep learning curve, actively going against its design won't get you far up.

  • Like many others, you focus your "dumbing down Vim" effort on movements like <up>, <down> and friends. Vim has much better ways to move around in and between buffers: wWeEbB/?tTfF{}[] and so on. All these motions give you super powers. All these motions depend on modality in one way or another.

    Rejecting these incredibly useful tools is a very bad mistake in and of itself. Remapping them would be both very tough and utterly worthless.

    FYI, when I started Vim, I spent months trying to turn it into a TextMate clone. Trying to create insert mode mappings for everything was probably one the most frustrating endeavour of my whole career. I learned two things in the process, though:

    1. my beloved TextMate was seriously underpowered compared to Vim so it made absolutely no sense to dumb down Vim, and…

    2. modes freaking rule.

Accept Vim's philosophy instead of rejecting it. Or reject it and use Sublime Text 2 instead, for what we care.

3

I agree with @garyjohn - besides, Ctrl-n and Ctrl-p are things I use for autocompletion or automatic spelling completion - I wouldn't map those to something else. All the same, Ctrl-w will delete one word before the cursor, and Ctrl-u will delete everything before the cursor, so at least you could use these shortcuts (which also work in a shell).

1
  • 1
    Another reason to avoid abusing insert mode (i.e., by using it all the time) is that the user would be sidestepping Vim's standard undo/redo functionality. For example, if you make a series of changes in insert mode, then escape to normal and undo with u, you will undo all changes made. Additionally, Ctrl-u in insert mode is not easily redoable (unlike normal mode deletion commands). The user can still rely on :earlier and :later but loses granularity in the undo tree unless using Ctrl-G u See vim.wikia.com/wiki/Using_undo_branches
    – Andy Mo
    Jan 9, 2013 at 14:02
3

Just to hammer this home: If you stay in insert mode for long, you're doing something wrong. The pattern in Vi(m) is: Move around in normal mode. Make short inserts (a word here, a sentence there). Or manipulate the text with Ex commands like :substitute. Repeat.

Try to teach yourself to leave insert mode (via <Esc>, hopefully conveniently accessible on your keyboard) as soon as the stream of characters coming from your brain starts to trickle off. The next insertion is just an i / a away.

0

If you want to move more than ONE or TWO positions...

...the best choice is to hit ESC, move around, and get back to insert mode again.

There's no point on create mappings like <C-h> to move left and then start hitting it too many times... as a vim user you're not supposed to hit the same key multiple times to achieve a smart movement.

(If the ESC key isn't close to your fingers, it would be a good option to create a mapping for it.)

If you want to move ONE or TWO posistions on insert mode...

...a good choice would be to define some movements using your <Leader> key:

(I use , as <Leader> key since it's feels close and confortable to my fingers)

noremap! <Leader>h <left>   "move cursor left
noremap! <Leader>j <down>   "move cursor down
noremap! <Leader>k <up>     "move cursor up   
noremap! <Leader>l <right>  "move cursor right
noremap! <Leader>w <esc>wi  "move one word forward
noremap! <Leader>e <esc>ei  "move forward to the end of word
noremap! <Leader>b <esc>bi  "move one word backward

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .