From 5d26cab34c19536750c4f0c646014d67462920ff Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Sun, 11 Dec 2011 16:02:17 +0100 Subject: [PATCH] New g:session_command_aliases option (issue #11) --- README.md | 16 ++++++++++++++++ autoload/xolox/session.vim | 4 ++-- doc/session.txt | 29 +++++++++++++++++++++++++++++ plugin/session.vim | 18 +++++++++++++++++- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e03830..a262206 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,22 @@ The example above doesn't persist the `g:session_directory` variable because thi This option is a list of environment variable names (without the dollar signs) that the `:RestartVim` command will pass on to the new instance of Vim. This option is only useful on UNIX. By default the three environment variables `$TERM`, `$VIM` and `$VIMRUNTIME` are included in this list. +### The `g:session_command_aliases` option + +The names of the commands defined by the session plug-in start with the action they perform, followed by the string 'Session'. Some people prefer it the other way around because they find it easier to remember and you can type `:Session` to get completion of all available commands (actually this works with the other style as well if you type `:*Session` but I digress). If you are one of those people you can enable this option in your [vimrc script] [vimrc] like this: + + :let g:session_command_aliases = 1 + +When this option is enabled the session plug-in will define the following command aliases: + + * `SessionOpen` is an alias for `OpenSession` + * `SessionView` is an alias for `ViewSession` + * `SessionSave` is an alias for `SaveSession` + * `SessionDelete` is an alias for `DeleteSession` + * `SessionClose` is an alias for `CloseSession` + +The aliases support tab completion just like the real commands; they're exactly the same except for the names. + ### The `g:loaded_session` option This variable isn't really an option but if you want to avoid loading the `session.vim` plug-in you can set this variable to any value in your [vimrc script] [vimrc]: diff --git a/autoload/xolox/session.vim b/autoload/xolox/session.vim index 347c444..b315208 100644 --- a/autoload/xolox/session.vim +++ b/autoload/xolox/session.vim @@ -1,9 +1,9 @@ " Vim script " Author: Peter Odding -" Last Change: November 26, 2011 +" Last Change: December 11, 2011 " URL: http://peterodding.com/code/vim/session/ -let g:xolox#session#version = '1.4.24' +let g:xolox#session#version = '1.4.25' " Public API for session persistence. {{{1 diff --git a/doc/session.txt b/doc/session.txt index 8b0ca21..e322998 100644 --- a/doc/session.txt +++ b/doc/session.txt @@ -240,6 +240,35 @@ that the |:RestartVim| command will pass on to the new instance of Vim. This option is only useful on UNIX. By default the three environment variables '$TERM', '$VIM' and '$VIMRUNTIME' are included in this list. +------------------------------------------------------------------------------- +The *g:session_command_aliases* option + +The names of the commands defined by the session plug-in start with the action +they perform, followed by the string 'Session'. Some people prefer it the +other way around because they find it easier to remember and you can type +':Session' to get completion of all available commands (actually this +works with the other style as well if you type ':*Session' but I +digress). If you are one of those people you can enable this option in your +|vimrc| script like this: +> + :let g:session_command_aliases = 1 + +When this option is enabled the session plug-in will define the following +command aliases: + + - 'SessionOpen' is an alias for 'OpenSession' + + - 'SessionView' is an alias for 'ViewSession' + + - 'SessionSave' is an alias for 'SaveSession' + + - 'SessionDelete' is an alias for 'DeleteSession' + + - 'SessionClose' is an alias for 'CloseSession' + +The aliases support tab completion just like the real commands; they're +exactly the same except for the names. + ------------------------------------------------------------------------------- The *g:loaded_session* option diff --git a/plugin/session.vim b/plugin/session.vim index 8c3b4dd..b9b1d53 100644 --- a/plugin/session.vim +++ b/plugin/session.vim @@ -1,6 +1,6 @@ " Vim script " Author: Peter Odding -" Last Change: November 11, 2011 +" Last Change: December 11, 2011 " URL: http://peterodding.com/code/vim/session/ " Support for automatic update using the GLVS plug-in. @@ -54,6 +54,12 @@ if !exists('g:session_directory') endif endif +" Define session command aliases of the form "Session" + Action in addition +" to the real command names which are of the form Action + "Session"? +if !exists('g:session_command_aliases') + let g:session_command_aliases = 0 +endif + " Make sure the session scripts directory exists and is writable. let s:directory = fnamemodify(g:session_directory, ':p') if !isdirectory(s:directory) @@ -84,6 +90,16 @@ command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names D command! -bar -bang CloseSession call xolox#session#close_cmd(, 0) command! -bang -nargs=* -complete=command RestartVim call xolox#session#restart_cmd(, ) +if g:session_command_aliases + " Define command aliases of the form "Session" + Action in addition to + " the real command names which are of the form Action + "Session" (above). + command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionOpen call xolox#session#open_cmd(, ) + command! -bar -nargs=? -complete=customlist,xolox#session#complete_names SessionView call xolox#session#view_cmd() + command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionSave call xolox#session#save_cmd(, ) + command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionDelete call xolox#session#delete_cmd(, ) + command! -bar -bang SessionClose call xolox#session#close_cmd(, 0) +endif + " Don't reload the plug-in once it has loaded successfully. let g:loaded_session = 1