mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-13 02:05:40 +08:00
Create 2018-01-31-grep-on-the-fly-in-spacevim.md
This commit is contained in:
parent
84ff2ffb52
commit
a5d76d787c
@ -1,13 +1,14 @@
|
||||
let s:JOB = SpaceVim#api#import('job')
|
||||
let s:job_id = 0
|
||||
let s:server_address = ''
|
||||
function! SpaceVim#dev#website#open()
|
||||
function! SpaceVim#dev#website#open() abort
|
||||
let path = expand('~/.SpaceVim/docs/')
|
||||
let cmd = ['bundle', 'exec', 'jekyll', 'serve']
|
||||
if s:job_id == 0 && s:server_address == ''
|
||||
if s:job_id == 0 && s:server_address ==# ''
|
||||
let s:job_id = s:JOB.start(cmd, {
|
||||
\ 'cwd' : path,
|
||||
\ 'on_stdout' : function('s:on_stdout'),
|
||||
\ 'on_stderr' : function('s:on_stderr'),
|
||||
\ 'on_exit' : function('s:on_exit'),
|
||||
\ })
|
||||
else
|
||||
@ -21,6 +22,9 @@ function! SpaceVim#dev#website#terminal() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" @vimlint(EVL103, 1, a:event)
|
||||
" @vimlint(EVL103, 1, a:id)
|
||||
" @vimlint(EVL103, 1, a:data)
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
for data in a:data
|
||||
if data =~# 'Server address:'
|
||||
@ -30,6 +34,17 @@ function! s:on_stdout(id, data, event) abort
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
function! s:on_stderr(id, data, event) abort
|
||||
for data in a:data
|
||||
echohl WarningMsg
|
||||
echom 'SpaceVim website:' . data
|
||||
echohl None
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" @vimlint(EVL103, 0, a:id)
|
||||
" @vimlint(EVL103, 0, a:data)
|
||||
" @vimlint(EVL103, 0, a:event)
|
||||
|
||||
function! s:on_exit(...) abort
|
||||
let s:job_id = 0
|
||||
|
44
.ci/detach_plugin.sh
Executable file
44
.ci/detach_plugin.sh
Executable file
@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
_detect () {
|
||||
cp -f ../../$1 $1
|
||||
}
|
||||
|
||||
_checkdir () {
|
||||
if [[ ! -d "$1" ]]; then
|
||||
mkdir -p $1
|
||||
fi
|
||||
}
|
||||
|
||||
main () {
|
||||
case "$1" in
|
||||
flygrep)
|
||||
git clone https://github.com/wsdjeg/FlyGrep.vim.git detach/$1
|
||||
cd detach/$1
|
||||
_checkdir autoload/SpaceVim/api
|
||||
_checkdir autoload/SpaceVim/api/vim
|
||||
_checkdir autoload/SpaceVim/mapping
|
||||
_checkdir autoload/SpaceVim/plugins
|
||||
_detect autoload/SpaceVim/plugins/flygrep.vim
|
||||
_detect autoload/SpaceVim/api.vim
|
||||
_detect autoload/SpaceVim/api/logger.vim
|
||||
_detect autoload/SpaceVim/api/vim/buffer.vim
|
||||
_detect autoload/SpaceVim/api/prompt.vim
|
||||
_detect autoload/SpaceVim/api/job.vim
|
||||
_detect autoload/SpaceVim/api/system.vim
|
||||
_detect autoload/SpaceVim/mapping/search.vim
|
||||
_detect autoload/SpaceVim/logger.vim
|
||||
git add .
|
||||
git commit -m "Auto Update"
|
||||
git remote add wsdjeg_flygrep https://SpaceVimBot:${BOTSECRET}@github.com/wsdjeg/FlyGrep.vim.git
|
||||
git push wsdjeg_flygrep master
|
||||
cd -
|
||||
rm -rf detach/$1
|
||||
exit 0
|
||||
;;
|
||||
spacevim-theme)
|
||||
exit 0
|
||||
esac
|
||||
}
|
||||
|
||||
main $@
|
@ -169,7 +169,9 @@ function! SpaceVim#default#SetMappings() abort
|
||||
|
||||
" Save a file with sudo
|
||||
" http://forrst.com/posts/Use_w_to_sudo_write_a_file_with_Vim-uAN
|
||||
" use w!! in cmdline or use W command to sudo write a file
|
||||
cnoremap w!! %!sudo tee > /dev/null %
|
||||
command! W w !sudo tee % > /dev/null
|
||||
|
||||
|
||||
" Use Ctrl+* to jump between windows
|
||||
|
@ -95,7 +95,7 @@ endfunction
|
||||
|
||||
function! SpaceVim#mapping#search#default_tool() abort
|
||||
if !has_key(s:search_tools, 'default_exe')
|
||||
for t in g:spacevim_search_tools
|
||||
for t in get(g:, 'spacevim_search_tools', ['rg', 'ag', 'pt', 'ack', 'grep'])
|
||||
if executable(t)
|
||||
let s:search_tools.default_exe = t
|
||||
let key = s:search_tools.namespace[t]
|
||||
|
46
docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md
Normal file
46
docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md
Normal file
@ -0,0 +1,46 @@
|
||||
---
|
||||
title: "Vim 异步实时代码检索"
|
||||
categories: feature_cn
|
||||
excerpt: "Run grep asynchronously, show search results in real-time based on user input, support searching the entire project, searching loaded files or only searching current file"
|
||||
image: https://user-images.githubusercontent.com/13142418/35278709-7856ed62-0010-11e8-8b1e-e6cc6374b0dc.gif
|
||||
comments: true
|
||||
permalink: /cn/:title/
|
||||
lang: cn
|
||||
---
|
||||
|
||||
# Vim 异步实时代码检索
|
||||
|
||||
{{ page.date | date_to_string }}
|
||||
|
||||
SpaceVim 中代码检索采用的是 FlyGrep 这个插件,包括了常用的全工程代码检索,局部文件夹代码检索等特性。搜索结果实时展示。
|
||||
这个插件是 SpaceVim 的内置插件,当然也已分离出一个备份仓库供给非 SpaceVim 用户使用。
|
||||
|
||||
<https://github.com/wsdjeg/FlyGrep.vim>
|
||||
|
||||

|
||||
|
||||
## 特性
|
||||
|
||||
- 实时检索全工程文件
|
||||
- 实时检索全工程文件,指定初始输入伺,适合搜光标单词或选择的词语
|
||||
- 实时检索已载入文件,这不同于全工程搜索,只搜索vim中已打开的文件,能更准确定位
|
||||
- 同上,支持指定输入词来检索已载入文件
|
||||
- 指定检索目录,适合跨工程检索或检索子目录,也可用于同时检索多个工程
|
||||
- 支持正则表达式输入
|
||||
- 支持中文检索
|
||||
- 输入框采用的是终端那一套快捷键,bash 用户应该非常喜欢这样快捷键,可以快速编辑单行输入内容。
|
||||
- 鼠标支持,用 Vim 其实也有鼠标党,在这个插件里面,可以用鼠标滚轮上下移动选择行,也可以用鼠标双击打开匹配位置,单击移动匹配位置
|
||||
以上这些功能已经在 SpaceVim 中实现了,文中的连接是一波演示效果图。
|
||||
|
||||
**补充:**
|
||||
|
||||
首先是增加了 filter 模式,也就是当我们搜索一个关键词,出现了很多结果,而我们需要的结果排在很后,以至于下拉很久看不到,这时候你可以启用 filter 模式,filter 模式其实类似于 flygrep,但是,他是对前一次的结果进行筛选。默认快捷键是 flygrep 模式下按下 ctrl+f
|
||||
|
||||
## 计划中的特性
|
||||
|
||||
一个比较实用的 todo,提供一个快捷键,将搜索结果转变为 quickfix 列表,这有助于对这些搜索结果进行后期处理。
|
||||
另外一个 TODO 是全工程替换,或局部替换,大致思路是由flygrep 删选结果,由 Iedit 多光标编辑,再应用至文件.
|
||||
|
||||
后期还有那些特性会去实现呢?首先当然是neovim的悬浮窗特性,在我前面的文章里面已经展示过悬浮窗的特性,那只是一个粗略的效果图, 具体细节当然还需要时间去实现。
|
||||
|
||||
关于代码检索,大家还有什么建议吗?欢迎留言.
|
@ -11,9 +11,9 @@ going on.
|
||||
<ul>
|
||||
{% for post in site.posts %}
|
||||
<li>
|
||||
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
|
||||
<h3><a href="{{ post.url }}">{{ post.title }}</a></h2>
|
||||
<span class="post-date">{{ post.date | date_to_string }}</span>
|
||||
<h3>{{ post.excerpt | truncatewords: 100 }}</h3>
|
||||
<p>{{ post.excerpt | truncatewords: 100 }}</p>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
@ -10,7 +10,7 @@ lang: cn
|
||||
|
||||
{% for post in site.post %}
|
||||
<ul>
|
||||
{% if post.lang == "cn" %}
|
||||
{% if post.lang %}
|
||||
<li>
|
||||
<h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
|
||||
<span class="post-date">{{ post.date | date_to_string }}</span>
|
||||
|
Loading…
x
Reference in New Issue
Block a user