how to

flash.nvim with Neovim from Zero

Jul 5, 2025
25neovimvimflash.nvimvim-searchlazy.nvim
4 Minutes
770 Words

vim 模式下,想要跳转到屏幕上某个随机位置,并不是很方便. flash.nvim 是一个理想选择,与 easymotion, leap.nvim 相似但是更符合直觉.

本文假设你:

  • 已经安装了 neovim
  • 可能仅使用 neovim 的 init.vim
  • 可能用过 easymotion

flash.nvim 效果展示

假设当前状态如下,光标在第 18 行,你想跳到第一个 neovim

default

按下 / n e o 后,会在所有匹配 neo 的地方显示一个标识字母,按下 q 跳转到第一个 neo 处:

default

其实打下 / n 就会开始匹配,你输入几个字母就匹配几个字母. 原有的 / 搜索功能不受影响.

如何安装 (Starting from installing lazy.nvim)

注意 init.vim 和 init.lua 不能共存.

  • 将你的 init.vim 改名为 init2.vim.
  • 创建 init.lua,添加如下内容,它会加在你的 init2.vim,并安装 lazy.nvim 和 flash.nvim.
1
local vimrc = vim.fn.stdpath("config") .. "/init2.vim"
2
vim.cmd.source(vimrc)
3
4
-- Bootstrap lazy.nvim
5
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
6
if not (vim.uv or vim.loop).fs_stat(lazypath) then
7
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
8
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
9
if vim.v.shell_error ~= 0 then
10
vim.api.nvim_echo({
11
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
12
{ out, "WarningMsg" },
13
{ "\nPress any key to exit..." },
14
}, true, {})
15
vim.fn.getchar()
38 collapsed lines
16
os.exit(1)
17
end
18
end
19
vim.opt.rtp:prepend(lazypath)
20
21
-- Make sure to setup `mapleader` and `maplocalleader` before
22
-- loading lazy.nvim so that mappings are correct.
23
-- This is also a good place to setup other settings (vim.opt)
24
vim.g.mapleader = " "
25
vim.g.maplocalleader = "\\"
26
27
-- Setup lazy.nvim
28
require("lazy").setup({
29
spec = {
30
-- add your plugins here
31
-- [flash.nvim]
32
{
33
"folke/flash.nvim",
34
event = "VeryLazy",
35
---@type Flash.Config
36
opts = {
37
modes = {
38
search = { enabled = true }
39
}
40
},
41
-- stylua: ignore
42
keys = {
43
{ "s", mode = { "n", "x", "o" }, function() require("flash").treesitter() end, desc = "Flash Treesitter" },
44
{ "<c-s>", mode = { "c" }, function() require("flash").toggle() end, desc = "Toggle Flash Search" },
45
},
46
}
47
},
48
-- Configure any other settings here. See the documentation for more details.
49
-- colorscheme that will be used when installing plugins.
50
install = { colorscheme = { "habamax" } },
51
-- automatically check for plugin updates
52
checker = { enabled = true },
53
})

基于 flash.nvim 文档改动. search = { enabled = true } 这一行开启了 search 增强.

<c-s> 似乎是用于 Toggle flash.nvim.

  • 添加上述脚本后,重新启动 nvim,会弹出安装窗口,过一会儿就装好了.

其他功能

flit 功能

推荐. 这是默认开启的,可以增强你的 fF.

  • 比如你正常地 f{,你就会跳到后面第一个 {(允许跨行)
  • 此时第一个 { 后所有的 { 都会高亮,如果你想跳到的其实是第三个 {,那么再按两次 f.
  • 不喜欢这个功能的话上面配置里的 opts = {} 可以加入:
1
opts = {
2
modes = {
3
char = { enabled = false }
4
}
5
},

treesitter 功能

推荐. 在支持 treesitter 的环境下按下 s 可以显示附近作用域的首尾,按下 label 跳转过去.

default

remote 功能

不推荐,会 Ctrl + O 就用不着. 所以上面配置中我没有引入该功能.

Postscript

  • 搜索功能正常支持中文字符.
  • vim 插件我认为应该和 vim 原有键位贴近,不能离开了这个功能就不会用 vim 了,毕竟我们经常要在新电脑上用 vi 编辑东西.
  • 如果 git clone failed / checkout failed,可以尝试 .gitconfig 中加入 URL 替换 (works on my mac m1).
2
insteadOf = https://github.com/
3
5
insteadOf = git://github
Article title:flash.nvim with Neovim from Zero
Article author:Julyfun
Release time:Jul 5, 2025
Copyright 2025
Sitemap