In vim how to map “save” to ctrl-s

前端 未结 4 990
伪装坚强ぢ
伪装坚强ぢ 2020-12-07 15:32

In vim, how can I map \"save\" (:w) to ctrl-s.

I am trying \"map\" the command, but xterm freezes when I press ctrl-

4条回答
  •  感情败类
    2020-12-07 16:15

    In linux with VI, you want to press Ctrl-S and have it save your document. This worked for me, put the following three lines in your .vimrc file. This file should be located in your home directory: /home/el/.vimrc If this file doesn't exist you can create it.

    :nmap  :w
    :imap  :wa
    

    The first line says: pressing Ctrl-S within a document will perform a :w keyboard combination.

    The second line says: pressing Ctrl-S within a document while in 'insert' mode will escape to normal mode, perform a :w , then press a to get back into insert mode. Your cursor may move during this event.

    You may notice that pressing Ctrl-S performs an 'XOFF' which stops commands from being received (If you are using ssh).

    To fix that, place these two commands in your ~/.bash_profile

    bind -r '\C-s'
    stty -ixon
    

    What that does is turn off the binding of Ctrl-S and gets rid of any XOFF onscreen messages when pressing Ctrl-S. Note, after you make changes to your .bash_profile you have to re-run it with the command 'source .bash_profile' or logout/login.

    More Info: http://vim.wikia.com/wiki/Map_Ctrl-S_to_save_current_or_new_files

提交回复
热议问题