neovim中使用denite记录

Denite是Neovim / Vim统一所有接口的深色驱动插件。它可以用其界面替换许多功能或插件。它就像一个模糊查找器,但是更通用。您可以扩展接口并创建源。
您可以使用它做的一些事情包括:

  • 开启档案
  • 切换缓冲器
  • 插入寄存器的值
  • 更改当前目录
  • 搜索字符串

项目主页

https://github.com/Shougo/denite.nvim

要求

您必须使用pip安装“ pynvim”模块

pip3 install --user pynvim

安装

对于vim-plug

if has('nvim')
  Plug 'Shougo/denite.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plug 'Shougo/denite.nvim'
  Plug 'roxma/nvim-yarp'
  Plug 'roxma/vim-hug-neovim-rpc'
endif

示例:

" Define mappings
autocmd FileType denite call s:denite_my_settings()
function! s:denite_my_settings() abort
  nnoremap <silent><buffer><expr> <CR>
  \ denite#do_map('do_action')
  nnoremap <silent><buffer><expr> d
  \ denite#do_map('do_action', 'delete')
  nnoremap <silent><buffer><expr> p
  \ denite#do_map('do_action', 'preview')
  nnoremap <silent><buffer><expr> q
  \ denite#do_map('quit')
  nnoremap <silent><buffer><expr> i
  \ denite#do_map('open_filter_buffer')
  nnoremap <silent><buffer><expr> <Space>
  \ denite#do_map('toggle_select').'j'
endfunction

如何使用

怎么用呢?我一脸懵。看了半天不知道是如何使用的。神器就是这么让人难以琢磨?

后来才发现原来有个帮助文件单独放了。下面我会把帮助文档引用过来。
在这里插入图片描述

  • 按文件名搜索项目中的文件?
    比如搜索文件名中包含App.js的文件
:Denite -input=App.js file

在这里插入图片描述

总的来说,帮助文档比较长,等我有时间在去仔细看吧。
这个插件默认是没有配置按键绑定的,
然后我使用大佬配置好的配置,目前能实现项目文件的搜索和根据文本查找文件就够了。

大佬的配置在:
https://github.com/craftzdog/dotfiles-public/blob/master/.config/nvim/plugins/denite.rc.vim

根据文件名查找文件

使用上面的配置以后,可以按;f进行文件名搜索。非常方便!
在这里插入图片描述

帮助文档

原文在:https://github.com/Shougo/denite.nvim/blob/master/doc/denite.txt

我简单的用翻译软件翻译一下。
Dark powered异步将NeoVim / Vim的所有接口结合在一起。

Version: 3.3
Author: Shougo <Shougo.Matsu at gmail.com>
License: MIT license

目录denite-contents
介绍denite-introduction
用法denite-usage
安装denite-install
配置示例denite-examples
Interfacedenite-interface
Commandsdenite-commands
Key mappingsdenite-key-mappings
Functionsdenite-functions
Optionsdenite-options
Sourcesdenite-sources
Kindsdenite-kinds
Filtersdenite-filters
Create sourcedenite-create-source
Create kinddenite-create-kind
Create filterdenite-create-filter
External sourcedenite-external-sources
FAQdenite-faq
Compatibilitydenite-compatibility

介绍

denitedenite.nvim是一种常见的可扩展界面,用于搜索和
显示NeoVim / Vim中的信息列表。 它可以显示和搜索任意源,从文件和目录到缓冲区。

  • 从理论上讲,当主进程由python执行时,速度更快。

  • 理论上更稳定,但在以下情况下无法执行其他任何处理
    denite.nvim被执行。

  • 实现比unite.vim相对简单

  • Denite.nvim具有实施新功能的巨大潜力。

  • 使用Python3发送拉取请求比使用Vim脚本更容易。

  • 有很多有用的工具可以使代码保持简单(线性,测试器等)。
    在Python3中。

  • unite.vim已正式过时,次要错误(甚至主要错误)是
    不再固定。

用法

浏览当前打开的缓冲区列表,如:ls 命令。

:Denite buffer

在这里插入图片描述
浏览当前工作下所有文件的递归列表目录。

:Denite file/rec

在这里插入图片描述
或者,您可以组合源来浏览文件和缓冲区。

:Denite file/rec buffer

在这里插入图片描述
有许多命令行标志(请参见| denite-options |),用于设置初始搜索词(foo)来过滤文件搜索的示例。

:Denite -input=foo file/rec

在这里插入图片描述
可以使用多个关键字来缩小候选范围。 它们之间用空格“”分隔,并且起着逻辑“与”的作用。

foo bar

用破折号“!”指定否定条件。

foo !bar

它匹配包含“ foo”但不包含“ bar”的候选。

安装

(译:这个上面都有说明了,我就不翻译了)
Note: denite requires Neovim 0.4.0+ or Vim 8.0+ with |:python3| enabled.

Note: Please install/upgrade msgpack package (1.0.0+).
https://github.com/msgpack/msgpack-python

Note: You need to install Python 3.6.1+.

For neovim:

  1. Extract the files and put them in your Neovim directory
    (usually $XDG_CONFIG_HOME/nvim/).
  2. Execute the |:UpdateRemotePlugins| and restart Neovim.

If “:echo has(‘python3’)” returns 1, then you’re done; otherwise, see below.

You can enable Python3 interface with pip

  pip3 install --user pynvim

If you want to read for pynvim/python3 interface install documentation,
you should read |provider-python| and the Wiki.

You can check the Python3 installation |:checkhealth|
command.

For Vim8.0+:

Please install nvim-yarp plugin for Vim8.
https://github.com/roxma/nvim-yarp

Please install vim-hug-neovim-rpc plugin for Vim8.
https://github.com/roxma/vim-hug-neovim-rpc

Use |:python3| enabled Vim.

You must install “pynvim” module with pip

   pip3 install --user pynvim

配置示例

" Define mappings
	autocmd FileType denite call s:denite_my_settings()
	function! s:denite_my_settings() abort
	  nnoremap <silent><buffer><expr> <CR>
	  \ denite#do_map('do_action')
	  nnoremap <silent><buffer><expr> d
	  \ denite#do_map('do_action', 'delete')
	  nnoremap <silent><buffer><expr> p
	  \ denite#do_map('do_action', 'preview')
	  nnoremap <silent><buffer><expr> q
	  \ denite#do_map('quit')
	  nnoremap <silent><buffer><expr> i
	  \ denite#do_map('open_filter_buffer')
	  nnoremap <silent><buffer><expr> <Space>
	  \ denite#do_map('toggle_select').'j'
	endfunction

	autocmd FileType denite-filter call s:denite_filter_my_settings()
	function! s:denite_filter_my_settings() abort
	  imap <silent><buffer> <C-o> <Plug>(denite_filter_quit)
	endfunction

	" Change file/rec command.
	call denite#custom#var('file/rec', 'command',
	\ ['ag', '--follow', '--nocolor', '--nogroup', '-g', ''])
	" For ripgrep
	" Note: rg is faster than ag
	call denite#custom#var('file/rec', 'command',
	\ ['rg', '--files', '--glob', '!.git', '--color', 'never'])
	" For Pt(the platinum searcher)
	" NOTE: It also supports windows.
	call denite#custom#var('file/rec', 'command',
	\ ['pt', '--follow', '--nocolor', '--nogroup',
	\  (has('win32') ? '-g:' : '-g='), ''])
	" For python script scantree.py
	" Read bellow on this file to learn more about scantree.py
	call denite#custom#var('file/rec', 'command',
	\ ['scantree.py', '--path', ':directory'])

	" Change matchers.
	call denite#custom#source(
	\ 'file_mru', 'matchers', ['matcher/fuzzy', 'matcher/project_files'])
	call denite#custom#source(
	\ 'file/rec', 'matchers', ['matcher/cpsm'])

	" Change sorters.
	call denite#custom#source(
	\ 'file/rec', 'sorters', ['sorter/sublime'])

	" Change default action.
	call denite#custom#kind('file', 'default_action', 'split')

	" Add custom menus
	let s:menus = {}

	let s:menus.zsh = {
		\ 'description': 'Edit your import zsh configuration'
		\ }
	let s:menus.zsh.file_candidates = [
		\ ['zshrc', '~/.config/zsh/.zshrc'],
		\ ['zshenv', '~/.zshenv'],
		\ ]

	let s:menus.my_commands = {
		\ 'description': 'Example commands'
		\ }
	let s:menus.my_commands.command_candidates = [
		\ ['Split the window', 'vnew'],
		\ ['Open zsh menu', 'Denite menu:zsh'],
		\ ['Format code', 'FormatCode', 'go,python'],
		\ ]

	call denite#custom#var('menu', 'menus', s:menus)

	" Ag command on grep source
	call denite#custom#var('grep', {
		\ 'command': ['ag'],
		\ 'default_opts': ['-i', '--vimgrep'],
		\ 'recursive_opts': [],
		\ 'pattern_opt': [],
		\ 'separator': ['--'],
		\ 'final_opts': [],
		\ })

	" Ack command on grep source
	call denite#custom#var('grep', {
		\ 'command': ['ack'],
		\ 'default_opts': [
		\   '--ackrc', $HOME.'/.ackrc', '-H', '-i',
		\   '--nopager', '--nocolor', '--nogroup', '--column'
		\ ],
		\ 'recursive_opts': [],
		\ 'pattern_opt': ['--match'],
		\ 'separator': ['--'],
		\ 'final_opts': [],
		\ })

	" Ripgrep command on grep source
	call denite#custom#var('grep', {
		\ 'command': ['rg'],
		\ 'default_opts': ['-i', '--vimgrep', '--no-heading'],
		\ 'recursive_opts': [],
		\ 'pattern_opt': ['--regexp'],
		\ 'separator': ['--'],
		\ 'final_opts': [],
		\ })

	" Pt command on grep source
	call denite#custom#var('grep', {
		\ 'command': ['pt'],
		\ 'default_opts': [
		\   '-i', '--nogroup', '--nocolor', '--smart-case'],
		\ 'recursive_opts': [],
		\ 'pattern_opt': [],
		\ 'separator': ['--'],
		\ 'final_opts': [],
		\ })

	" jvgrep command on grep source
	call denite#custom#var('grep', {
		\ 'command': ['jvgrep'],
		\ 'default_opts': ['-i'],
		\ 'recursive_opts': ['-R'],
		\ 'pattern_opt': [],
		\ 'separator': [],
		\ 'final_opts': [],
		\ })

	" Specify multiple paths in grep source
	"call denite#start([{'name': 'grep',
	"      \ 'args': [['a.vim', 'b.vim'], '', 'pattern']}])

	" Define alias
	call denite#custom#alias('source', 'file/rec/git', 'file/rec')
	call denite#custom#var('file/rec/git', 'command',
	      \ ['git', 'ls-files', '-co', '--exclude-standard'])

	call denite#custom#alias('source', 'file/rec/py', 'file/rec')
	call denite#custom#var('file/rec/py', 'command',
	\ ['scantree.py', '--path', ':directory'])

	" 更改忽略的目录
	call denite#custom#filter('matcher/ignore_globs', 'ignore_globs',
	      \ [ '.git/', '.ropeproject/', '__pycache__/',
	      \   'venv/', 'images/', '*.min.*', 'img/', 'fonts/'])

	" Custom action
	" Note: denite#custom#action() with lambda parameter is only available
	"       in NeoVim; not supported in Vim8.
	call denite#custom#action('file', 'test',
	      \ {context -> execute('let g:foo = 1')})
	call denite#custom#action('file', 'test2',
	      \ {context -> denite#do_action(
	      \  context, 'open', context['targets'])})
	" Source specific action
	call denite#custom#action('source/file', 'test',
	      \ {context -> execute('let g:bar = 1')})

命令

:Denite [{options}] {sources}
创建一个新的Denite缓冲区。
可以使用一个或多个源调用Denite。 这可以通过在命令行上指定列表(以空格分隔)来完成。候选列表(通过过滤字符串在源中找到的匹配项)的排列顺序与您指定{sources}的顺序相同。
示例:

:Denite file/rec line

将首先列出文件,然后列出当前缓冲区的行。另请参见| denite-sources | 可用资源。
Denite可以接受以下字符串列表,并用":"分隔来源名称。
您必须使用“ \”转义“:”和“ \”在参数本身中,或在参数周围加上引号。
示例:

  • file/rec:foo:bar: 源文件的参数是 [“foo”, “bar”].
  • file/rec:foo\:bar: 源文件的参数是 [“foo:bar”].
  • file/rec:'foo:bar: 源文件的参数是 [“foo:bar”].
  • file/rec:foo::bar: 源文件的参数是 [“foo”, “”, “bar”].

您可以通过``使用评估命令行。 注意:在评估中,特殊字符(空格,“ \”和“:”)会自动转义。

:Denite -buffer-name=search%`bufnr('%')` line<CR>

{options} are options for Denite buffer: |denite-options|




INTERFACE						*denite-interface*

------------------------------------------------------------------------------
COMMANDS 						*denite-commands*


		

:DeniteBufferDir [{options}] {sources}			*:DeniteBufferDir*
		Equivalent to |:Denite| except that it targets the buffer
		directory.

:DeniteCursorWord [{options}] {sources}			*:DeniteCursorWord*
		Equivalent to |:Denite| except that it targets <cword> under
		the cursor for the initial narrowing text.
		Note: <cword> means 'iskeyword' characters.  If you want to
		custom <cword> pattern, you need to set 'iskeyword' option.
		Note: <cword> characters are escaped automatically.

:DeniteProjectDir [{options}] {sources}			*:DeniteProjectDir*
		Equivalent to |:Denite| except that it search the VCS project
		directory from parent.
		Note: You can change the search directory by
		|denite-option-path| instead of |getcwd()|.

------------------------------------------------------------------------------

----帮助文档未完----
这帮助文档内容比较多,目前时间有限先翻译到这里。
建议还是自己去看原文吧!
原文在:https://github.com/Shougo/denite.nvim/blob/master/doc/denite.txt

报错解决办法

报错如下:
E117: Unknown function: defx#get_candidate
E116: Invalid arguments for function has_key
E15: 无效的表达式: has_key(defx#get_candidate(), ‘action__path’)
[denite] option “-start_filter=”: type is invalid.
Pattern:

看这个错❌应该是缺少什么导致的。
安装如下插件:

https://github.com/Shougo/defx.nvim
For vim-plug

if has('nvim')
  Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
else
  Plug 'Shougo/defx.nvim'
  Plug 'roxma/nvim-yarp'
  Plug 'roxma/vim-hug-neovim-rpc'
endif

安装完上面的插件后,发现报错信息已经有所变化了,如下:

[denite] option “-start_filter=”: type is invalid.

这个错怎么办理呢?
在这里插入图片描述
编辑denite配置文件,把'start_filter': v:true,删除就没有这个报错了,也不影响搜索功能。
只是我不太明白这一行配置的作用是什么。实测功能不受影响。暂时也就样吧!

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值