Ⅰ. 插件描述
Vim's wincmd-style tab / window moving commands (vim plugin).Ⅱ. 基本信息
|
Ⅲ. 安装方法
使用Vundle管理器安装
在你的.vimrc下添加:Plugin 'yssl/twcommand'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall
对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。
使用NeoBundle管理器安装
在你的.vimrc下添加:NeoBundle 'yssl/twcommand'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall
使用VimPlug管理器安装
在你的.vimrc下添加:Plug 'yssl/twcommand'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall
使用Pathogen管理器安装
在终端中运行以下命令:cd ~/.vim/bundle
git clone https://github.com/yssl/twcmd.vim
Ⅳ. 文档说明
# TWcmd.vim
TWcmd.vim is a set of useful commands for moving & managing tabs and windows in vim.
- Move a tab / window

Stack visited windows and recover them when closing
<!--
-->- The cursor can jumps to the lastest window of the current tab or to the latest [tab, window] pair in history when closing a window. (see
:help g:twcmd_focus_after_closingfor more details.)
- The cursor can jumps to the lastest window of the current tab or to the latest [tab, window] pair in history when closing a window. (see
Installation
Using plugin managers (recommended)
Using Pathogen
cd ~/.vim/bundle; git clone https://github.com/yssl/TWcmd.vim.git
Manual install (not recommended)
- Download this plugin and extract it in
~/.vim/
- Download this plugin and extract it in
Usage
In vim normal mode, type the following command and press <Enter>.
:TWcmd {cmd} {arg}
- {cmd} : sub-commands for tabs or windows
- {arg} : vim's
:wincmd-style single character arguments
For example,
:TWcmd tcm l |" go to the right tab
:TWcmd tmv l |" move the current tab right
:TWcmd wmv h |" move the current window left
:TWcmd tcm q |" close current tabIt must be much more convenient to define key mappings for frequently used commands.
My key mapping recommendation is given in the last section of this page.
Commands
| {cmd} | description |
|---|---|
| tcm | tab commands |
| tmv | tab moving commands |
| wcm | window commands |
| wmv | window moving commands |
| wmvt | window moving commands between tabs |
| twh | tab-window history commands |
Arguments
| {cmd} | {arg} | description |
|---|---|---|
| tcm / wcm |
h | Go to the left tab / window. |
| l | Go to the right tab / window. | |
| j | Go to the below window. (wcm only) | |
| k | Go to the above window. (wcm only) | |
| W | Go to the left tab / left or above window. Wraps around from the first to the last one. |
|
| w | Go to the right tab / right or below window. Wraps around from the last to the first one. |
|
| t | Go to the first tab / top-left window. |
|
| b | Go to the last tab / bottom-right window. |
|
| p | Go to the previous tab / previous window in the current tab. |
|
| q | Close the current tab / window and go to the latest one in the tab-window history. |
|
| n | Open a new tab / window. |
|
| o | Close all other tabs / windows except the current one. | |
| m | Toggle maximizing the current window. (wcm only) |
- wcm can be used with all other arguments that used in the vim's
:wincmdcommand.
| {cmd} | {arg} | description |
|---|---|---|
| tmv / wmv / wmvt |
h | Move the current tab left / window left / window to the left tab. |
| l | Move the current tab right / window right / window to the right tab. | |
| j | Move the current window below. (wmv only) | |
| k | Move the current window above. (wmv only) | |
| W | Move the current tab left / window left or above / window to the left tab.
Wraps around from the first to the last one. |
|
| w | Move the current tab right / window right or below / window to the right tab.
Wraps around from the last to the first one. |
|
| t | Move the current tab to first position / window to top-left position / window to the first tab. |
|
| b | Move the current tab to last position / window to bottom-right position / window to the last tab. |
|
| p | Move the current tab to previous position / window to previous position / window to the previous tab. |
For wmvt,
- The current tab will be closed after moving its window if it is the only one.
- If the target tab has only one window with [No Name] title and empty buffer, the moved window will replace it.
- Otherwise, the moved window will be located as a new vertical split window in the target tab.
| {cmd} | {arg} | description |
|---|---|---|
| twh |
h | Move forward in the tab-window history stack. |
| l | Move backward in the tab-window history stack. |
Tab-Window History
When you leave a window in vim, TWcmd.vim pushes [tab_id, window_id] information of the window into its tab-window history stack.
TWcmd.vim moves the cursor to the last focused window using the history stack
when closing a window or tab. (see :help g:twcmd_focus_after_closing for more details.)
You can also walk through windows in the history with twh sub-command.
Recommended Key Mappings
TWcmd.vim does not provide default key mappings to keep your key mappings clean.
Instead, I suggest convenient one what I'm using now.
You can add them to your .vimrc and modify them as you want.
function! s:nnoreicmap(option, shortcut, command)
execute 'nnoremap '.a:option.' '.a:shortcut.' '.a:command
execute 'imap '.a:option.' '.a:shortcut.' <Esc>'.a:shortcut
execute 'cmap '.a:option.' '.a:shortcut.' <Esc>'.a:shortcut
endfunction
" tab cursor moving and managing
call s:nnoreicmap('','<A-H>',':TWcmd tcm h<CR>')
call s:nnoreicmap('','<A-L>',':TWcmd tcm l<CR>')
call s:nnoreicmap('','<A-P>',':TWcmd tcm p<CR>')
call s:nnoreicmap('','<A-Q>',':TWcmd tcm q<CR>')
call s:nnoreicmap('','<A-N>',':TWcmd tcm n<CR>')
" tab moving
call s:nnoreicmap('','<A-J>',':TWcmd tmv h<CR>')
call s:nnoreicmap('','<A-K>',':TWcmd tmv l<CR>')
call s:nnoreicmap('','<A-)>',':TWcmd tmv p<CR>')
" window cursor moving and managing
call s:nnoreicmap('','<A-h>',':TWcmd wcm h<CR>')
call s:nnoreicmap('','<A-j>',':TWcmd wcm j<CR>')
call s:nnoreicmap('','<A-k>',':TWcmd wcm k<CR>')
call s:nnoreicmap('','<A-l>',':TWcmd wcm l<CR>')
call s:nnoreicmap('','<A-p>',':TWcmd wcm p<CR>')
call s:nnoreicmap('','<A-q>',':TWcmd wcm q<CR>')
call s:nnoreicmap('','<A-n>',':TWcmd wcm n<CR>')
call s:nnoreicmap('','<A-v>',':TWcmd wcm v<CR>')
call s:nnoreicmap('','<A-s>',':TWcmd wcm s<CR>')
call s:nnoreicmap('','<A-m>',':TWcmd wcm m<CR>')
" window moving
call s:nnoreicmap('','<A-y>',':TWcmd wmv h<CR>')
call s:nnoreicmap('','<A-u>',':TWcmd wmv j<CR>')
call s:nnoreicmap('','<A-i>',':TWcmd wmv k<CR>')
call s:nnoreicmap('','<A-o>',':TWcmd wmv l<CR>')
call s:nnoreicmap('','<A-0>',':TWcmd wmv p<CR>')
" window moving between tabs
call s:nnoreicmap('','<A-U>',':TWcmd wmvt h<CR>')
call s:nnoreicmap('','<A-I>',':TWcmd wmvt l<CR>')
call s:nnoreicmap('','<A-(>',':TWcmd wmvt p<CR>')I've define the function s:nnoreicmap() to map for normal, insert and command-line modes simultaneously,
and installed plugin to use alt-key mappings.
<A-H> means alt+shift+h.