Skip to content

Commit 665a2b5

Browse files
committed
Extract :Maximize from :Fullscreen (suggested by Benjamin Bergman)
1 parent 34ef803 commit 665a2b5

File tree

4 files changed

+61
-33
lines changed

4 files changed

+61
-33
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ This plug-in aims to improve the integration between [Vim][vim] and its environm
44

55
* The `:Fullscreen` command and `<F11>` mapping toggle Vim between normal and full-screen mode (see the [screenshots](http://peterodding.com/code/vim/shell/screenshots/)). To invoke this functionality without using the `:Fullscreen` command see the `xolox#shell#fullscreen()` and `xolox#shell#is_fullscreen()` functions.
66

7+
* The `:Maximize` command and `<Control-F11>` mapping toggle Vim between normal and maximized state: They show/hide Vim's menu bar, tool bar and/or tab line without hiding the operating system task bar.
8+
79
* The `:Open` command and `<F6>` mapping know how to open file and directory names, URLs and e-mail addresses in your favorite programs (file manager, web browser, e-mail client, etc). To invoke this functionality without using the `:Open` command see my [open.vim](http://peterodding.com/code/vim/open-associated-programs/) plug-in, which was split off from `shell.vim` so that other Vim plug-ins can bundle it without bringing in all the other crap :-).
810

911
* The `xolox#shell#execute()` function enables other Vim plug-ins (like my [easytags.vim] [easytags] plug-in) to execute external commands in the background (i.e. asynchronously) *without opening a command prompt window on Windows*.
@@ -12,11 +14,13 @@ Two [Windows DLL files][dll] are included to perform these functions on Windows,
1214

1315
## Usage (commands & functions)
1416

15-
### The `:Fullscreen` command
17+
### The `:Maximize` command
1618

17-
The `:Fullscreen` command toggles Vim between normal and [full-screen mode](http://peterodding.com/code/vim/shell/screenshots/). It's mapped to `<F11>` by default, see `g:shell_mappings_enabled` if you don't like this.
19+
This command toggles the visibility of Vim's main menu, tool bar and/or tab line. It's mapped to `<Control-F11>` by default, see `g:shell_mappings_enabled` if you don't like this. If you want to change which items are hidden see the `g:shell_fullscreen_items` option.
20+
21+
### The `:Fullscreen` command
1822

19-
When you enter full-screen mode the main menu, toolbar and tabline are all hidden (see `g:shell_fullscreen_items` if you want to change this) and when possible Vim's [GUI window] [gui] is switched to real full-screen mode (hiding any [taskbars, panels or docks](http://en.wikipedia.org/wiki/Taskbar)). When you leave full-screen Vim's main menu, toolbar and tabline are restored and the [GUI window] [gui] is switched back to normal mode.
23+
The `:Fullscreen` command toggles Vim between normal and [full-screen mode](http://peterodding.com/code/vim/shell/screenshots/). It's mapped to `<F11>` by default, see `g:shell_mappings_enabled` if you don't like this. This command first executes `:Maximize` and then (if possible) switches Vim's [GUI window] [gui] to real full-screen mode (hiding any [taskbars, panels or docks](http://en.wikipedia.org/wiki/Taskbar)). When you leave full-screen Vim's main menu, toolbar and tabline are restored and the [GUI window] [gui] is switched back to normal mode.
2024

2125
Note that on UNIX this command even works inside of graphical terminal emulators like `gnome-terminal` or `xterm` (try it out!).
2226

autoload/xolox/shell.vim

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: September 4, 2011
3+
" Last Change: September 18, 2011
44
" URL: http://peterodding.com/code/vim/shell/
55

6-
let g:xolox#shell#version = '0.9.11'
6+
let g:xolox#shell#version = '0.9.12'
77

88
if !exists('s:fullscreen_enabled')
99
let s:enoimpl = "%s() hasn't been implemented on your platform! %s"
1010
let s:contact = "If you have suggestions, please contact peter@peterodding.com."
1111
let s:fullscreen_enabled = 0
12+
let s:maximized = 0
1213
endif
1314

1415
function! xolox#shell#open_cmd(arg) " -- implementation of the :Open command {{{1
@@ -137,16 +138,9 @@ function! xolox#shell#execute(command, synchronous, ...) " -- execute external c
137138
endtry
138139
endfunction
139140

140-
function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-screen mode {{{1
141-
142-
" When entering full-screen...
143-
if !s:fullscreen_enabled
144-
" Save the window position and size when running Windows, because my
145-
" dynamic link library doesn't save/restore them while "wmctrl" does.
146-
if xolox#misc#os#is_win()
147-
let [s:lines_save, s:columns_save] = [&lines, &columns]
148-
let [s:winpos_x_save, s:winpos_y_save] = [getwinposx(), getwinposy()]
149-
endif
141+
function! xolox#shell#maximize(...) " -- show/hide Vim's menu, tool bar and/or tab line {{{1
142+
let new_state = a:0 == 0 ? !s:maximized : a:1
143+
if new_state && !s:maximized
150144
" Hide the main menu, tool bar and/or tab line. Remember what was hidden
151145
" so its visibility can be restored when the user leaves full-screen.
152146
let s:go_toggled = ''
@@ -161,6 +155,31 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
161155
let s:stal_save = &stal
162156
set showtabline=0
163157
endif
158+
let s:maximized = 1
159+
elseif s:maximized && !new_state
160+
" Restore display of previously hidden GUI components?
161+
let &go .= s:go_toggled
162+
if exists('s:stal_save')
163+
let &stal = s:stal_save
164+
unlet s:stal_save
165+
endif
166+
unlet s:go_toggled
167+
let s:maximized = 0
168+
endif
169+
return s:maximized
170+
endfunction
171+
172+
function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-screen mode {{{1
173+
174+
" When entering full-screen...
175+
if !s:fullscreen_enabled
176+
" Save the window position and size when running Windows, because my
177+
" dynamic link library doesn't save/restore them while "wmctrl" does.
178+
if xolox#misc#os#is_win()
179+
let [s:lines_save, s:columns_save] = [&lines, &columns]
180+
let [s:winpos_x_save, s:winpos_y_save] = [getwinposx(), getwinposy()]
181+
endif
182+
call xolox#shell#maximize(1)
164183
endif
165184

166185
" Now try to toggle the real full-screen status of Vim's GUI window using a
@@ -187,13 +206,7 @@ function! xolox#shell#fullscreen() " -- toggle Vim between normal and full-scree
187206

188207
" When leaving full-screen...
189208
if s:fullscreen_enabled
190-
" Restore display of previously hidden GUI components?
191-
let &go .= s:go_toggled
192-
if exists('s:stal_save')
193-
let &stal = s:stal_save
194-
unlet s:stal_save
195-
endif
196-
unlet s:go_toggled
209+
call xolox#shell#maximize(0)
197210
" Restore window position and size only on Windows -- I don't know why
198211
" but the following actually breaks when running under "wmctrl"...
199212
if xolox#misc#os#is_win()

doc/shell.txt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ This plug-in aims to improve the integration between Vim and its environment
88
without using the |:Fullscreen| command see the 'xolox#shell#fullscreen()'
99
and 'xolox#shell#is_fullscreen()' functions.
1010

11+
- The |:Maximize| command and '<Control-F11>' mapping toggle Vim between
12+
normal and maximized state: They show/hide Vim's menu bar, tool bar and/or
13+
tab line without hiding the operating system task bar.
14+
1115
- The |:Open| command and '<F6>' mapping know how to open file and directory
1216
names, URLs and e-mail addresses in your favorite programs (file manager,
1317
web browser, e-mail client, etc). To invoke this functionality without
@@ -26,19 +30,23 @@ while on UNIX external commands are used.
2630
*shell-usage-(commands-functions)*
2731
Usage (commands & functions) ~
2832

33+
-------------------------------------------------------------------------------
34+
The *:Maximize* command
35+
36+
This command toggles the visibility of Vim's main menu, tool bar and/or tab
37+
line. It's mapped to '<Control-F11>' by default, see |g:shell_mappings_enabled|
38+
if you don't like this. If you want to change which items are hidden see the
39+
|g:shell_fullscreen_items| option.
40+
2941
-------------------------------------------------------------------------------
3042
The *:Fullscreen* command
3143

3244
The |:Fullscreen| command toggles Vim between normal and full-screen mode [1].
3345
It's mapped to '<F11>' by default, see |g:shell_mappings_enabled| if you don't
34-
like this.
35-
36-
When you enter full-screen mode the main menu, toolbar and tabline are all
37-
hidden (see |g:shell_fullscreen_items| if you want to change this) and when
38-
possible Vim's |GUI| window is switched to real full-screen mode (hiding any
39-
taskbars, panels or docks [5]). When you leave full-screen Vim's main menu,
40-
toolbar and tabline are restored and the |GUI| window is switched back to normal
41-
mode.
46+
like this. This command first executes |:Maximize| and then (if possible)
47+
switches Vim's |GUI| window to real full-screen mode (hiding any taskbars,
48+
panels or docks [5]). When you leave full-screen Vim's main menu, toolbar and
49+
tabline are restored and the |GUI| window is switched back to normal mode.
4250

4351
Note that on UNIX this command even works inside of graphical terminal
4452
emulators like 'gnome-terminal' or 'xterm' (try it out!).

plugin/shell.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: August 31, 2011
3+
" Last Change: September 18, 2011
44
" URL: http://peterodding.com/code/vim/shell/
55

66
" Support for automatic update using the GLVS plug-in.
@@ -28,15 +28,18 @@ augroup END
2828
" Regular commands. {{{1
2929

3030
command! -bar -nargs=? -complete=file Open call xolox#shell#open_cmd(<q-args>)
31+
command! -bar Maximize call xolox#shell#maximize()
3132
command! -bar Fullscreen call xolox#shell#fullscreen()
3233

3334
" Default key mappings. {{{1
3435

3536
if g:shell_mappings_enabled
36-
inoremap <F11> <C-o>:Fullscreen<CR>
37-
nnoremap <F11> :Fullscreen<CR>
3837
inoremap <F6> <C-o>:Open<CR>
3938
nnoremap <F6> :Open<CR>
39+
inoremap <F11> <C-o>:Fullscreen<CR>
40+
nnoremap <F11> :Fullscreen<CR>
41+
inoremap <C-F11> <C-o>:Maximize<CR>
42+
nnoremap <C-F11> :Maximize<CR>
4043
endif
4144

4245
" Make sure the plug-in is only loaded once.

0 commit comments

Comments
 (0)