Skip to content

Commit 5d26cab

Browse files
committed
New g:session_command_aliases option (issue #11)
1 parent 1a9e32a commit 5d26cab

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ The example above doesn't persist the `g:session_directory` variable because thi
135135

136136
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.
137137

138+
### The `g:session_command_aliases` option
139+
140+
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:
141+
142+
:let g:session_command_aliases = 1
143+
144+
When this option is enabled the session plug-in will define the following command aliases:
145+
146+
* `SessionOpen` is an alias for `OpenSession`
147+
* `SessionView` is an alias for `ViewSession`
148+
* `SessionSave` is an alias for `SaveSession`
149+
* `SessionDelete` is an alias for `DeleteSession`
150+
* `SessionClose` is an alias for `CloseSession`
151+
152+
The aliases support tab completion just like the real commands; they're exactly the same except for the names.
153+
138154
### The `g:loaded_session` option
139155

140156
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]:

autoload/xolox/session.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
" Vim script
22
" Author: Peter Odding
3-
" Last Change: November 26, 2011
3+
" Last Change: December 11, 2011
44
" URL: http://peterodding.com/code/vim/session/
55

6-
let g:xolox#session#version = '1.4.24'
6+
let g:xolox#session#version = '1.4.25'
77

88
" Public API for session persistence. {{{1
99

doc/session.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,35 @@ that the |:RestartVim| command will pass on to the new instance of Vim. This
240240
option is only useful on UNIX. By default the three environment variables
241241
'$TERM', '$VIM' and '$VIMRUNTIME' are included in this list.
242242

243+
-------------------------------------------------------------------------------
244+
The *g:session_command_aliases* option
245+
246+
The names of the commands defined by the session plug-in start with the action
247+
they perform, followed by the string 'Session'. Some people prefer it the
248+
other way around because they find it easier to remember and you can type
249+
':Session<Tab>' to get completion of all available commands (actually this
250+
works with the other style as well if you type ':*Session<Tab>' but I
251+
digress). If you are one of those people you can enable this option in your
252+
|vimrc| script like this:
253+
>
254+
:let g:session_command_aliases = 1
255+
256+
When this option is enabled the session plug-in will define the following
257+
command aliases:
258+
259+
- 'SessionOpen' is an alias for 'OpenSession'
260+
261+
- 'SessionView' is an alias for 'ViewSession'
262+
263+
- 'SessionSave' is an alias for 'SaveSession'
264+
265+
- 'SessionDelete' is an alias for 'DeleteSession'
266+
267+
- 'SessionClose' is an alias for 'CloseSession'
268+
269+
The aliases support tab completion just like the real commands; they're
270+
exactly the same except for the names.
271+
243272
-------------------------------------------------------------------------------
244273
The *g:loaded_session* option
245274

plugin/session.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim script
22
" Author: Peter Odding
3-
" Last Change: November 11, 2011
3+
" Last Change: December 11, 2011
44
" URL: http://peterodding.com/code/vim/session/
55

66
" Support for automatic update using the GLVS plug-in.
@@ -54,6 +54,12 @@ if !exists('g:session_directory')
5454
endif
5555
endif
5656

57+
" Define session command aliases of the form "Session" + Action in addition
58+
" to the real command names which are of the form Action + "Session"?
59+
if !exists('g:session_command_aliases')
60+
let g:session_command_aliases = 0
61+
endif
62+
5763
" Make sure the session scripts directory exists and is writable.
5864
let s:directory = fnamemodify(g:session_directory, ':p')
5965
if !isdirectory(s:directory)
@@ -84,6 +90,16 @@ command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names D
8490
command! -bar -bang CloseSession call xolox#session#close_cmd(<q-bang>, 0)
8591
command! -bang -nargs=* -complete=command RestartVim call xolox#session#restart_cmd(<q-bang>, <q-args>)
8692

93+
if g:session_command_aliases
94+
" Define command aliases of the form "Session" + Action in addition to
95+
" the real command names which are of the form Action + "Session" (above).
96+
command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionOpen call xolox#session#open_cmd(<q-args>, <q-bang>)
97+
command! -bar -nargs=? -complete=customlist,xolox#session#complete_names SessionView call xolox#session#view_cmd(<q-args>)
98+
command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionSave call xolox#session#save_cmd(<q-args>, <q-bang>)
99+
command! -bar -bang -nargs=? -complete=customlist,xolox#session#complete_names SessionDelete call xolox#session#delete_cmd(<q-args>, <q-bang>)
100+
command! -bar -bang SessionClose call xolox#session#close_cmd(<q-bang>, 0)
101+
endif
102+
87103
" Don't reload the plug-in once it has loaded successfully.
88104
let g:loaded_session = 1
89105

0 commit comments

Comments
 (0)