34

I am new to vim,

Usually, I find myself wanting to save and stay in insert mode, rather than hit escape, :w and back into insert mode.

  • 2
    I think it should stay here. Most vim questions are asked on SO, and by starting to divide them amongst sites accomplishes nothing except giving a user more work in terms of searching for them in all three sites. Vim is also an editor more often found at programmer's then average(or super:) users's machines. – Rook Dec 26 '09 at 23:26
  • I agree. SO has 1,199 questions tagged vim. SU has 106. – zen Dec 28 '09 at 22:11
38

Ctrl+O, then :w and Enter.

  • Yup, that's how I'd do it too. – David Wolever Dec 26 '09 at 20:40
  • 2
    Which is actually more complicated than the usual way, IMHO. – Rook Dec 26 '09 at 20:41
  • @Idigas: why is that? – akira Jun 1 '10 at 19:47
  • 2
    It is the same number of key strokes, but seems not very vimish. – Seamus Connor Aug 16 '10 at 18:32
32

You could add an alias like inoremap <F3> <c-o>:w<cr> in you .vimrc.

4

Without getting into a debate about the right or the wrong way, if you use a graphical Vim like MacVim or GVim, you should be able to use Cmd-s or Ctrl-s for saving. I can say that it works on OS X with MacVim and Cmd-s and so you can save your stuff in the insert mode.

2

Apart from that suggestion which Juliano mentioned (which should be taken out and shot <- the suggestion, not Juliano), it really is THE WRONG WAY TO DO IT. It would be actually more "normal" to try and do everything from command mode, instead of insert. But using them interchangeably is the usual vim's way and if one doesn't like it one should really stay clear of vim.

If you really don't like not being able to save from I mode, may I suggest an editor called Cream - it is a variant of vim, modified in a way that emulates nowadays's editors (so to say, it stays in I mode all the time, and has usual windows shortcuts).

  • 1
    While I agree on the general rule, I don't think it applies to this case. If you're just writing a long text and want to save often, mapping some key to <C-o>:w<CR> ain't really that bad. – Matteo Riva Dec 26 '09 at 20:47
  • @Michael Krelin ... - I agree. But he said he wants insert mode, so there it is. Personally, I thought at first about suggesting Notepad2 (or some other particular flavour) but that would've just been downvoted as non answerin gthe question. – Rook Dec 26 '09 at 23:22
  • @kemp - No. If you're writing a long text and you want to save often you use vim's capabilities in terms of: backup, writebackup and swapfile (you can :help any of them for details). Vim is -the way it is-, and although I (like all others) like a bit of customization now and then, trying to avoid several modes is just wrong. And it will not end well. Better to use something else then. After all, there are some pretty powerful alternative editors nowadays. – Rook Dec 26 '09 at 23:24
  • well, I do not see how his use of insert mode (all of us use it!) implies his desire to spend the rest of his vim session therein. I personally have a mapping for <F2> in both modes just because ever since I had crazy keyboard back in late 80s I can't unlearn hitting <F2> once in a while when editing ;-) – Michael Krelin - hacker Dec 27 '09 at 0:26
  • 4
    I read it as "I do not want to leave insert mode just to save file". – Michael Krelin - hacker Dec 27 '09 at 10:40
1

I cannot add comment to the @Tordek's answer, due to lack of reputation :) Therefore complementing his answer:

inoremap <F2> <C-\><C-o>:w<CR>

Adding <C-\> will prevent moving cursor one character left.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy