Skip to content

十分钟Spacevim入门

字数
1815 字
阅读时间
9 分钟

来源

这篇文章的主要目的是让用户快速了解Spacevim,尝试Spacevim并不会删除你的原有vim 配置,如果你不喜欢Spacevim,你随时可以安全快速地切换回原来的配置。

只需要10分钟,来尝试一下吧。

目录

一、安装

1. Install spacevim (Linux & macOS, for ),它不会删除你原有配置

curl -sLf https://spacevim.org/install.sh | bash

然后,开始尝试吧

vim

第一次使用spacevim时,需要一些时间安装插件。

2. 卸载并回滚到原vim

curl -sLf https://spacevim.org/install.sh | bash -s -- --uninstall

3. 同时使用你原有的vim和spacevim

See

怎么进行安装的?

其实只是重命名了你的~/.vim,名字改成~/.vim_back,用下面的命令查看安装脚本的更多信息 curl -sLf https://spacevim.org/install.sh | bash -s -- -h

强烈建议:

更新你的vim到neovim(neovim体验更好) 或者 vim8.0 以便有更好的SpaceVim体验

二、基本概念

SpaceVim中有非常多的快捷键,最常用的快捷键是空格键,我猜这是为什么它叫spacevim。接下来 我们用简称spc来表示空格键。

1. 快捷键

有许多不同的快捷键,可以归为下面几类

PrefixPrefix nameExampleDescriptionMore info
space[SPC]spc f t打开/关闭 文件浏览器just press space key and wait 1s
s`
\<Leader>\ [0-9]跳到其他tab(页面)或buffer(缓存)just press \ key and wait 1s
ggo tog 0跳到第一个tab
zfoldz a触发代码折叠

进入spacevim后,按一下空格键,等待1秒,你可以看到有用的提示信息,通过这些 信息来浏览一下spacevim的更多快捷键吧。

2. 一些概念

名称解释
WindowA window can split into more windows
BufferA buffer is a file loaded into memory for editing
Tab/FrameA tab could contain different file
TagbarDisplay tags of current file
FiletreeFile browser

对于vim新手

如果你仍然不熟悉vim,可以在linux终端中输入vimtutor,进入vim的实战教程,大概 需要花半小时掌握vim的基本技能。

对于vim的老用户

SpaceVim 有些快捷键是和原生vim冲突的,例如sg,如果你想使用原生vim的配置, 在~/.SpaceVim.d/init.toml中加入

toml
[options]
  vimcompatible = true

更多vim兼容模式信息请查看特别是你只想更正其中的某个快捷键而保持其他不变。

SpaceVim默认使用vimfiler,你可能更喜欢用nerdtree,同样,在~/.SpaceVim.d/init.toml中加入

toml
[options]
  filemanager = "nerdtree"

三、开始尝试

1. 最常用快捷键

虽然快捷键看起来很多,但是记起来并不麻烦,而且SpaceVim有很多提示,所以不要担心

留意:如果你使用了vim兼容模式(vimcompatible=true),下面的一些快捷键可能不生效

ShortcutsDescription
基本操作
h j k lmove around
spcwait 1 second to get hint for more shortcuts
<F3> / spc f ttrigger file tree
spc t tOpen tab manager
F2Open tagbar
<Leader> [1-9]switch to different tabs or buffers
spc [1-9]switch to different windows
ctrl j/h/k/lswitch to different windows
文件浏览器
spc f oopen file tree and locate to current directory
s gopen file and split window horizontally
s vopen file split window vertically
注释代码
spc c lcomment/uncomment current line
spc c p/Pcomment/uncomment current paragraph
spc ; [num] jcomment num lines
页面Tab管理器
spc t topen tab manager
spc w Fopen a new tab, equal to spc t t + n
spc w oswitch tab
显示相关
spc s cclear search highlight
SPC t 8highlight any character past the 80th column
SPC t h htoggle highlight of the current line
SPC t h ctoggle highlight indentation current column
搜索
spc s sSearching in current file
spc s dSearching in current directory
spc s bSearching in all loaded buffers
spc s pSearching in current proj, equal to spc /
有用的快捷键
[ spcinsert space above
] spcinsert space below

探索快捷键的最好方式依然是在spacevim中按下空格键等待一秒,它会弹出有用的提示框,亲自尝试其中的快捷键才能更加准确知道它的效果。

2. 高级设置

(1) 特定编程语言支持

这里以python为例,其他语言可见

~/.SpaceVim.d/init.toml中加入

toml
[layers](layers)
  name = "lang#python"

安装依赖

pip install --user flake8 yapf autoflake isort
  • flake8 : for syntax checking feature
  • yapf : for formatting code
  • autoflake : for uppress unused imports
  • isort : for sort your imports
ShortcutsDescription
g dGo to function definition
spc b fformat code according to pep8 standard
spc l g dgenerate docstring
spc l s iopen ipython
spc l rrun python code

(2) 模糊搜索

模糊搜索是一个比较强大的功能,参见 .

这里使用unite作为例子,在~/.SpaceVim.d/init.toml中加入

toml
[layers](layers)
  name = "unite"

在终端中

sudo apt-get install silversearcher-ag

对于linux用户,需要使终端的ctrl-s(停止屏幕变化)失效才能方便使用模糊搜索的功能。 在初始化脚本如(~/.bashrc) 中加入 stty -ixon

最后,开始使用模糊搜索,如模糊搜索当前文件夹下的文件

spc f f
ShortcutsDescription
<Tab> / Ctrl-jSelect next line
Shift-Tab / Ctrl-kSelect previous line
j kLeave Insert mode (Only for denite/unite)
Ctrl-wDelete backward path
<Enter>Run default action
Ctrl-sOpen in a split
Ctrl-vOpen in a vertical split
Ctrl-tOpen in a new tab
Ctrl-gExit unite

四、探索和自定义

1. 自定义

(1) Config ~/.SpaceVim.d/init.toml

你可能想让默认的缩进为4个空格,那么在~/.SpaceVim.d/init.toml中加入

toml
[options]
  default_indent = 4

实际上,上面的修改等价于在~/.SpaceVim/autoload/SpaceVim.vim中修改

vim
    let g:spacevim_default_indent = 4

两种方式效果是一样的,只不过第一种多了前缀 let g:spacevim_

所以可设置的Spacevim选项可以在:h SpaceVim-config 或者文件~/.SpaceVim/autoload/SpaceVim.vim中找到

(2)

举例说明如何使用bootstrap-functions

比如你想要每次vim启动的时候都自动换行set wrap,首先,新建一个文件.SpaceVim.d/autoload/myspacevim.vim,在里面添加如下内容

vim
func! myspacevim#before() abort
  set wrap
endf

然后在~/.SpaceVim.d/init.toml中添加

toml
[options]
  bootstrap_before = "myspacevim#before"

before 替换为 after如果你想要你自定义的函数在spacevim主脚本运行后再运行。

好吧,我知道上述的步骤有些麻烦。

(3)

2. 探索

  1. 更详细更全面的官方文档 Official document
  2. SpaceVim的扩展组件 Available layers
  3. 如果你有问题,不妨先看一下Frequently asked questions FAQ

需要注意的是,官方文档中,中文版本相对英文版本部分地方可能会有些过时。

3. 更多

  1. 更新SpaceVim :SPUpdate
  2. SpaceVim debug 信息SPDebugInfo! or spc h I, 如果你想要提交一个issue,这将会很有帮助

参考

  1. Spacevim tutorial 中文
  2. Hack-SpaceVim

贡献者

文件历史

布局切换

调整 VitePress 的布局样式,以适配不同的阅读习惯和屏幕环境。

全部展开
使侧边栏和内容区域占据整个屏幕的全部宽度。
全部展开,但侧边栏宽度可调
侧边栏宽度可调,但内容区域宽度不变,调整后的侧边栏将可以占据整个屏幕的最大宽度。
全部展开,且侧边栏和内容区域宽度均可调
侧边栏宽度可调,但内容区域宽度不变,调整后的侧边栏将可以占据整个屏幕的最大宽度。
原始宽度
原始的 VitePress 默认布局宽度

页面最大宽度

调整 VitePress 布局中页面的宽度,以适配不同的阅读习惯和屏幕环境。

调整页面最大宽度
一个可调整的滑块,用于选择和自定义页面最大宽度。

内容最大宽度

调整 VitePress 布局中内容区域的宽度,以适配不同的阅读习惯和屏幕环境。

调整内容最大宽度
一个可调整的滑块,用于选择和自定义内容最大宽度。

聚光灯

支持在正文中高亮当前鼠标悬停的行和元素,以优化阅读和专注困难的用户的阅读体验。

ON开启
开启聚光灯。
OFF关闭
关闭聚光灯。

聚光灯样式

调整聚光灯的样式。

置于底部
在当前鼠标悬停的元素下方添加一个纯色背景以突出显示当前鼠标悬停的位置。
置于侧边
在当前鼠标悬停的元素旁边添加一条固定的纯色线以突出显示当前鼠标悬停的位置。