1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 22:20:06 +08:00

Add a new layer: ctrlspace (#3075)

This commit is contained in:
Jethro Cao 2019-10-23 10:54:29 +08:00 committed by Wang Shidong
parent ca284faa18
commit 3404dc74bd
2 changed files with 217 additions and 0 deletions

View File

@ -0,0 +1,90 @@
"=============================================================================
" ctrlspace.vim --- SpaceVim CtrlSpace layer
" Copyright (c) 2016-2019 Wang Shidong & Contributors
" Author: Jethro Cao < jethrocao at gmail dot com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
" Layer Options
" home-mapping-key : main keybinding for invoking CtrlSpace
" autosave-workspaces : autosave current workspace on exit & switch
" autoload-workspaces : autoload last workspace on start
" enable-spacevim-styled-keys : defines SpaceVim styled fuzzy finding keys
" Use the following default settings
if has('nvim')
" Neovim requires adding trailing space to the mapping key;
" see plugin GitHub page for explanation
let s:home_mapping_key = '<C-Space> '
else
let s:home_mapping_key = '<C-Space>'
endif
let s:autosave_ws = 1
let s:autoload_ws = 0
let s:enable_spacevim_styled_keys = 0
function! SpaceVim#layers#ctrlspace#plugins() abort
return [
\['vim-ctrlspace/vim-ctrlspace', { 'merged' : 0 }],
\]
endfunction
function! SpaceVim#layers#ctrlspace#set_variable(var) abort
let s:home_mapping_key = get(a:var, 'home-mapping-key', s:home_mapping_key)
let s:autosave_ws = get(a:var, 'autosave-workspaces', s:autosave_ws)
let s:autoload_ws = get(a:var, 'autoload-workspaces', s:autoload_ws)
let s:enable_spacevim_styled_keys = get(a:var,
\ 'enable-spacevim-styled-keys',
\ s:enable_spacevim_styled_keys)
endfunction
function! SpaceVim#layers#ctrlspace#config() abort
" configure CtrlSpace's main options
let g:CtrlSpaceDefaultMappingKey = s:home_mapping_key
let g:CtrlSpaceSaveWorkspaceOnExit = s:autosave_ws
let g:CtrlSpaceSaveWorkspaceOnSwitch = s:autosave_ws
let g:CtrlSpaceLoadLastWorkspaceOnStart = s:autoload_ws
" configure CtrlSpace's glob command for collecting files
if executable("rg")
let g:CtrlSpaceGlobCommand = 'rg --color=never --files'
elseif executable("ag")
let g:CtrlSpaceGlobCommand = 'ag -l --nocolor -g ""'
else
let g:CtrlSpaceGlobCommand = ''
let l:info1 = "CtrlSpace: no suitable grepping tool found"
let l:info2 = "CtrlSpace: using Vim's globpath() to collect files"
let l:info3 = "CtrlSpace: install rg or ag for faster file collection and .gitignore respect"
call SpaceVim#logger#info(l:info1)
call SpaceVim#logger#info(l:info2)
call SpaceVim#logger#info(l:info3)
endif
" define SpaceVim styled fuzzy finding keys for user preference/compatibility
if s:enable_spacevim_styled_keys
call SpaceVim#mapping#space#def('nnoremap', ['b', 'L'], 'CtrlSpace h', 'CtrlSpace: list tab-local buffers', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 'l'], 'CtrlSpace H', 'CtrlSpace: search tab-local buffers', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 'B'], 'CtrlSpace a', 'CtrlSpace: list all buffers', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 'b'], 'CtrlSpace A', 'CtrlSpace: search all buffers', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'F'], 'CtrlSpace |', 'CtrlSpace: list files in dir of curr buff', 1)
call SpaceVim#mapping#space#def('nnoremap', ['f', 'f'], 'CtrlSpace |/', 'CtrlSpace: search files in dir of curr buff', 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 'F'], 'CtrlSpace o', 'CtrlSpace: list project files', 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 'f'], 'CtrlSpace O', 'CtrlSpace search project files', 1)
call SpaceVim#mapping#space#def('nnoremap', ['w', 'T'], 'CtrlSpace l', 'CtrlSpace: list tabs', 1)
call SpaceVim#mapping#space#def('nnoremap', ['w', 't'], 'CtrlSpace L', 'CtrlSpace: search tabs', 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 'W'], 'CtrlSpace w', 'CtrlSpace: list workspaces', 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 'w'], 'CtrlSpace W', 'CtrlSpace: search workspaces', 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 'B'], 'CtrlSpace b', 'CtrlSpace: list bookmarks', 1)
call SpaceVim#mapping#space#def('nnoremap', ['p', 'b'], 'CtrlSpace B', 'CtrlSpace: search bookmarks', 1)
endif
endfunction

127
docs/layers/ctrlspace.md Normal file
View File

@ -0,0 +1,127 @@
---
title: "SpaceVim CtrlSpace layer"
description: "This layer provides a customized CtrlSpace centric workflow"
---
# [Available Layers](../) >> ctrlspace
<!-- vim-markdown-toc GFM -->
- [Description](#description)
- [Install](#install)
- [Layer Options](#layer-options)
- [Keybindings: CtrlSpace Defaults](#keybindings-ctrlspace-defaults)
- [Keybindings: SpaceVim Styled](#keybindings-spacevim-styled)
<!-- vim-markdown-toc -->
## Description
This layer is a customized wrapper for
[CtrlSpace](https://github.com/vim-ctrlspace/vim-ctrlspace), a plugin
dedicated to project navigation and workflow management, rather than a
traditional fuzzy finder like Denite or FZF. CtrlSpace strictly manages
5 source lists only:
* Buffers
* Files
* Tabs
* Workspaces (vim session for current project)
* Bookmarks (projects)
CtrlSpace has the unique property of allowing users to stay within it
after it has been invoked once (similar to SpaceVim's own Transient
Modes). Thereby granting you the ability to open multiple files,
move/copy many buffers to new tabs, change to your various project
bookmarks, and any combinations of its various actions, all without
needing to reinvoke it.
## Install
To use the CtrlSpace layer, add the following to your configuration file.
```toml
[[layers]]
name = "ctrlspace"
```
## Layer Options
* `home-mapping-key` (default: `<C-Space>`) - keybinding to enter CtrlSpace's
home menu, which displays the buffers list
* `autosave-workspaces` (default: `true`) - enable to autosave current
workspace on switching WS and exiting SpaceVim
* `autoload-workspaces` (default: `false`) - enable to autoload last workspace
on starting SpaceVim
* For more granular CtrlSpace options, refer to the [plugin's GitHub
page](https://github.com/vim-ctrlspace/vim-ctrlspace).
* `enable-spacevim-styled-keys` (default: `false`) - enable to make
available [SpaceVim styled keybindings](#keybindings-spacevim-styled).
**Note**: when disabled, another traditional fuzzy finder layer (such
as Denite or FZF) may still be used without concerns of keybinding
conflicts.
## Keybindings: CtrlSpace Defaults
From Vim's Normal mode, `<home-mapping-key>` enters CtrlSpace in its home
(buffers) list. Then using the following key shortcuts, all 5 lists can
be accessed via any of the other 4. Press `?` to show key reference for
the current list and mode (ex. search mode of files list).
| Keybindings | Descriptions |
| ----------------------------- | ---------------------------------------- |
| `h` | toggle view home (buffers) list |
| `H` | enter home (buffers) list in search |
| `o` | toggle view project files list |
| `O` | enter project files in search |
| `l` | toggle view tabs list |
| `L` | enter tabs search in search |
| `w` | toggle view workspaces list |
| `W` | enter workspaces list in search |
| `b` | toggle view bookmarks list |
| `B` | enter bookmarks list in search |
| `/` | toggle search mode for current list |
| `?` | display help for current list and mode |
To exit CtrlSpace, press `<Esc>`, `<C-c>` or `<home-mapping-key>` at
anytime.
For more comprehensive documentation of CtrlSpace's
keys, features and functionalities, [refer to
this guide](https://atlas-vim.readthedocs.io/vim/plugged/vim-ctrlspace/README/
).
## Keybindings: SpaceVim Styled
For those who prefer to use SpaceVim's style of fuzzy finding
buffers/files/projects, the following keybindings can be optionally
enabled with `enable-spacevim-styled-keys = true`.
| Keybindings | Descriptions |
| ----------------------------- | ------------------------------------- |
| `SPC b L` | list tab-local buffers |
| `SPC b l` | search tab-local buffers |
| `SPC b B` | list all buffers |
| `SPC b b` | search all buffers |
| `SPC f F` | list files in dir of current buffer |
| `SPC f f` | search files in dir of current buffer |
| `SPC p F` | list project files |
| `SPC p f` | search project files |
| `SPC w T` | list tabs |
| `SPC w t` | search tabs |
| `SPC p W` | list workspaces |
| `SPC p w` | search workspaces |
| `SPC p B` | list project bookmarks |
| `SPC p b` | search project bookmarks |
**Note**: to be consistent with other fuzzy finder layers in SpaceVim,
uppercased final keys will list the source, while lowercased ones will
search. This is opposite to CtrlSpace's default shortcuts.