aboutsummaryrefslogtreecommitdiffstats
path: root/bundle/cmd-escape
diff options
context:
space:
mode:
authorTeddy Wing2019-12-11 01:12:01 +0100
committerTeddy Wing2019-12-13 20:50:49 +0100
commit089771a8cf6eaf69aba0d7b37442a3b815aa7960 (patch)
treec2990a2fd930f39093c56c857360c3e8a8835969 /bundle/cmd-escape
parent88904fd725e31d614408c2a95b5d8a56f0de4ae0 (diff)
downloaddotvim-089771a8cf6eaf69aba0d7b37442a3b815aa7960.tar.bz2
cmd-escape: Make the plugin code more robust
* Move functions into autoload * Remove unused `s:Activate()` and `s:Deactivate()`. These were development ideas. * Add a load guard
Diffstat (limited to 'bundle/cmd-escape')
-rw-r--r--bundle/cmd-escape/autoload/cmd_escape.vim15
-rw-r--r--bundle/cmd-escape/plugin/cmd_escape.vim29
2 files changed, 20 insertions, 24 deletions
diff --git a/bundle/cmd-escape/autoload/cmd_escape.vim b/bundle/cmd-escape/autoload/cmd_escape.vim
new file mode 100644
index 0000000..dd87b64
--- /dev/null
+++ b/bundle/cmd-escape/autoload/cmd_escape.vim
@@ -0,0 +1,15 @@
+let s:active = 0
+
+" Toggles the <Space> key between normal self-insert and inserting an escaped
+" space ('\ ') in command mode.
+function cmd_escape#Toggle()
+ if s:active
+ cunmap <Space>
+ let s:active = 0
+ else
+ cnoremap <Space> \<Space>
+ let s:active = 1
+ endif
+
+ return ''
+endfunction
diff --git a/bundle/cmd-escape/plugin/cmd_escape.vim b/bundle/cmd-escape/plugin/cmd_escape.vim
index c37e335..f9952d4 100644
--- a/bundle/cmd-escape/plugin/cmd_escape.vim
+++ b/bundle/cmd-escape/plugin/cmd_escape.vim
@@ -1,25 +1,6 @@
-let s:active = 0
+if exists('g:loaded_cmd_escape')
+ finish
+endif
+let g:loaded_cmd_escape = 1
-function! s:Activate()
- cnoremap <Space> \<Space>
- let s:active = 1
-endfunction
-
-function! s:Deactivate()
- cunmap <Space>
- let s:active = 0
-endfunction
-
-function s:Toggle()
- if s:active
- cunmap <Space>
- let s:active = 0
- else
- cnoremap <Space> \<Space>
- let s:active = 1
- endif
-
- return ''
-endfunction
-
-cnoremap <C-x><Space> <C-r>=<SID>Toggle()<CR>
+cnoremap <C-x><Space> <C-r>=cmd_escape#Toggle()<CR>