1" 2" cream-expertmode.vim 3" 4" Cream -- An easy-to-use configuration of the famous Vim text editor 5" [ http://cream.sourceforge.net ] Copyright (C) 2001-2011 Steve Hall 6" 7" License: 8" This program is free software; you can redistribute it and/or modify 9" it under the terms of the GNU General Public License as published by 10" the Free Software Foundation; either version 3 of the License, or 11" (at your option) any later version. 12" [ http://www.gnu.org/licenses/gpl.html ] 13" 14" This program is distributed in the hope that it will be useful, but 15" WITHOUT ANY WARRANTY; without even the implied warranty of 16" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17" General Public License for more details. 18" 19" You should have received a copy of the GNU General Public License 20" along with this program; if not, write to the Free Software 21" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 22" 02111-1307, USA. 23" 24 25" Description: 26" Expert mode: <Esc> and <C-[> keys toggle between normal and insert 27" mode 28 29function! Cream_expertmode(state) 30" control expert mode--a:state must be 0 or 1 31 if a:state == 1 32 let g:CREAM_EXPERTMODE = 1 33 inoremap <silent> <Esc> <C-\><C-n> 34 noremap <silent> <Esc> a 35 inoremap <silent> <C-[> <C-\><C-n> 36 noremap <silent> <C-[> a 37 set selectmode= 38 else 39 let g:CREAM_EXPERTMODE = 0 40 silent! unmap! <Esc> 41 silent! unmap! <C-[> 42 set selectmode=key,mouse 43 endif 44endfunction 45 46function! Cream_expertmode_toggle() 47" toggle expert mode from existing state (assumes already initialized) 48 if g:CREAM_EXPERTMODE == 1 49 call Cream_expertmode(0) 50 call Cream_menu_settings_preferences() 51 else 52 let n = confirm( 53 \ "Expert mode uses the Esc and Ctrl+[ keys to toggle out of normal\n" . 54 \ "Cream behavior to Vim style:\n" . 55 \ " * Normal mode (insertmode turned off)\n" . 56 \ " * Visual mode (selectmode turned off)\n" . 57 \ "\n" . 58 \ "Unless you are an experienced Vim user, you are advised not to proceed.\n" . 59 \ "\n" . 60 \ "Continue?\n" . 61 \ "\n", "&Yes\n&Cancel", 2, "Warning") 62 if n == 1 63 call Cream_expertmode(1) 64 call Cream_menu_settings_preferences() 65 endif 66 endif 67endfunction 68 69function! Cream_expertmode_init() 70" initialize Cream environment for expert mode 71 if !exists("g:CREAM_EXPERTMODE") 72 call Cream_expertmode(0) 73 else 74 if g:CREAM_EXPERTMODE == 1 75 call Cream_expertmode(1) 76 else 77 call Cream_expertmode(0) 78 endif 79 endif 80endfunction 81 82