Skip to content

Commit

Permalink
New g:session_command_aliases option (issue #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Dec 11, 2011
1 parent 1a9e32a commit 5d26cab
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 3 deletions.
16 changes: 16 additions & 0 deletions README.md
Expand Up @@ -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<Tab>` to get completion of all available commands (actually this works with the other style as well if you type `:*Session<Tab>` 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]:
Expand Down
4 changes: 2 additions & 2 deletions 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

Expand Down
29 changes: 29 additions & 0 deletions doc/session.txt
Expand Up @@ -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<Tab>' to get completion of all available commands (actually this
works with the other style as well if you type ':*Session<Tab>' 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

Expand Down
18 changes: 17 additions & 1 deletion 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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -84,6 +90,16 @@ command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names D
command! -bar -bang CloseSession call xolox#session#close_cmd(<q-bang>, 0)
command! -bang -nargs=* -complete=command RestartVim call xolox#session#restart_cmd(<q-bang>, <q-args>)

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(<q-args>, <q-bang>)
command! -bar -nargs=? -complete=customlist,xolox#session#complete_names SessionView call xolox#session#view_cmd(<q-args>)
command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionSave call xolox#session#save_cmd(<q-args>, <q-bang>)
command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionDelete call xolox#session#delete_cmd(<q-args>, <q-bang>)
command! -bar -bang SessionClose call xolox#session#close_cmd(<q-bang>, 0)
endif

" Don't reload the plug-in once it has loaded successfully.
let g:loaded_session = 1

Expand Down

0 comments on commit 5d26cab

Please sign in to comment.