首页 » PHP教程 » vimquickfixphp技巧_从零开始设备vim20模糊查询

vimquickfixphp技巧_从零开始设备vim20模糊查询

访客 2024-12-01 0

扫一扫用手机浏览

文章目录 [+]

本次我们要先容的是神级插件 telescope,一样平常只要先容 neovim 配置的文章98%以上的都会推举这个插件作为文件搜索和文本搜索的插件。
我们自然也不能免俗,这里我也要先容它,如果不先容就显得有点不太专业了。
虽然我也先容,但是这个系列毕竟是从0开始配置vim,我会从安装到配置进行描述,希望能比其他的教程要详细一点。
但是最详细的仍旧是它的官方文档。

安装

我们利用下面的代码进行安装

vimquickfixphp技巧_从零开始设备vim20模糊查询

use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = { {'nvim-lua/plenary.nvim'} }}

为了更好地利用体验可以安装一个 nvim-treesitter 插件,它紧张用于代码高亮,它采取语法剖析的形式对代码进行高亮,比较于利用正则表达式来说效果更好,后面会详细的先容如何进行配置,加上它之后 telescope 插件将会更加强大。
这个时候我们的安装代码该当改为

vimquickfixphp技巧_从零开始设备vim20模糊查询
(图片来自网络侵删)

use { 'nvim-telescope/telescope.nvim', tag = '0.1.0', requires = { {'nvim-lua/plenary.nvim'} , { 'nvim-treesitter/nvim-treesitter', run = function() require('nvim-treesitter.install').update({ with_sync = true }) end, }}}

这里加上一个 run 的配置紧张是安装 nvim-treesitter 插件之后,第一次会报错,后面是正常的,这句话是为了肃清第一次加载时报错

安装完成之后,我们就可以在命令中输入 :Telescope find_files 来按照名称搜索文件

它常用的命令有如下几个

find_files : 查找文件live_grep: 利用正则表达式来进行内容的搜索,它可以跨文件搜索buffers:查看当前打开的缓冲区,并且可以预览缓冲区的内容grep_string: 以当前光标所在单词进行搜索oldfile: 打开历史文件列表marks: 打开书签表jumplist: 打开跳转列表

如果我们希望能够利用 live_grep 和 grep_string 的功能须要提前在系统上安装 ripgrep。
例如在ubuntu 上可以利用下列命令安装

sudo apt-get install ripgrep配置

我们先对最常用的功能进行快捷键的映射

vim.api.nvim_set_keymap("n", "<leader>ff", "<Cmd>Telescope find_files<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>gg", "<Cmd>Telescope live_grep<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>fm", "<Cmd>Telescope marks<CR>", {noremap = true, silent = true})vim.api.nvim_set_keymap("n", "<leader>fj", "<Cmd>Telescope jumplist<CR>", {noremap = true, silent = true})

不知道各位小伙伴是否还记得,我们在配置启动界面的时候留下了几个功能没有添加,现在我们有了这个插件之后就可以添加一部分了

在 dashboard 的配置中,我们可以补充干系功能对应的命令如下

db.custom_center = { {icon = " ", desc = 'Recently lastest session ', shortcut = "Leader s l", action = ""}, {icon = " ", desc = "Recently opened files ", shortcut = "Leader f h", action = "Telescope oldfiles"}, {icon = " ", desc = "Find File ", shortcut = "leader f f", action = "Telescope find_files"}, {icon = " ", desc = "File Browser ", shortcut = "leader f b", action = "Telescope file_browser" }, {icon = " ", desc = "Find Word ", shortcut = "leader g g", action = "Telescope live_grep"}, {icon = " ", desc = "Open Personal dotfiles ", shortcut = "leader e e", action = "edit $MYVIMRC"}}

要利用 Telescope file_browser 的功能我们须要额外安装一个插件。
它扩展了 Telescope 插件的功能

use { "nvim-telescope/telescope-file-browser.nvim" }

并且我们须要在 telescope 配置中加载这个扩展

require('telescope').load_extension "file_browser"

这样我们就完成了险些所有的功能了,还差一个加载上次会话的功能,我们等到谈论会话的时候再来补上

到现在我们的配置基本就结束了,我们目前仅仅只利用了它极为有限的功能。
根据官方的文档,它有大量的导出函数用于各种功能,但是现在我们并不打算做太多的定制化开拓,仅仅拿来用即可,以是目前的配置我认为已经够用了。
各位小伙伴也可以根据自己的需求查阅官方文档进行额外的配置

标签:

相关文章