26

I use Vi as my preferred (and, in fact, only) text editor on Linux Systems. I know how to change modes from normal to insert, and vice-versa.

Is it possible to have Vi automatically load into Insert Mode rather than Normal Mode?

I want this because I can only access my Linux over SSH, and my computer that I can use for SSH access is so slow, it takes ages to load command mode. (Also my Openwrt system is quite slow).

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65
  • This saves you a single keystroke when you don't need to navigate your file (i.e. in empty files) since navigation is easier in command mode. Why would you want to do this? – Earthliŋ Feb 04 '15 at 07:41
  • 1
    @Earthliŋ - Because I can only access my Linux over SSH, and my computer that I can use for SSH access is so slow, it takes ages to load command mode. (Also my Openwrt system is quite slow). –  Feb 04 '15 at 07:45
  • 3
    Thanks. Why don't you add this info to the question body? This way the question makes much more sense (to me at least) and will be easier findable (e.g. by searching "vim command mode slow to load"). – Earthliŋ Feb 04 '15 at 07:59
  • 4
    That tag is confusing me. If this question is about "original vi", why is a vim answer accepted? – muru Feb 06 '15 at 08:00
  • 2
    @muru Agreed. Changing the question two days afterwards, even if it was originally misinterpreted, makes a mess. At this point, it would be better to change the question to Vim and ask another question for Original Vi. I've voted to close as "Unclear what you are asking", and I would be glad to retract it if reverted. – 200_success Feb 06 '15 at 08:04
  • 3
    I've reverted the tag; this question can stay open, the OP can ask a new question .... IMHO that's the easier ... Also, I think the the OP uses nvi? – Martin Tournoij Feb 06 '15 at 08:22

3 Answers3

37

You can use the +startinsert option (or +star for short) to start Vim with insert mode.

vim +star myfile.txt

If you want this to happen by default when starting Vim, you can make an alias (in your .bashrc or .zshrc for example) as follows:

alias vim="vim +startinsert"

However, that works only when starting Vim. If you want Vim to be in Insert mode even when you open a file from within Vim, add the following to your .vimrc:

au BufRead,BufNewFile * startinsert
thameera
  • 17,434
  • 16
  • 40
  • 42
16
$ vim -y <file>

-y Easy mode. Implied for |evim| and |eview|. Starts with 'insertmode' set and behaves like a click-and-type editor. This sources the script $VIMRUNTIME/evim.vim. Mappings are set up to work like most click-and-type editors, see |evim-keys|. The GUI is started when available. {not in Vi}

source

OrangeTux
  • 3,566
  • 3
  • 20
  • 27
5

Although I think starting in insert mode is not the vim way, you can do this very easily. You should start vim with

vim -c startinsert 'file'

The -c flag passes in a command into vim. The :startinsert command changes to insert mode. As you can imagine, you could start vim with any number of commands if you so desired.

davidlowryduda
  • 2,424
  • 19
  • 27
  • Does this only work with Vim, or does it work also on Vi (My Openwrt system only has Vi). –  Feb 04 '15 at 16:58