vim搜索插件ctrlsf

地址: https://github.com/dyng/ctrlsf.vim 

安装:

Make sure you have ack or ag installed.

建议安装ag,更快,且安装起来更简单一点

http://geoff.greer.fm/ag/

wget http://geoff.greer.fm/ag/releases/the_silver_searcher-0.27.0.tar.gz
tar -zxvf the_silver_searcher-0.27.0.tar.gz
./configure
make
sudo make install 即安装ag

在~/.vimrc 设置
let g:ctrlsf_ackprg = 'ag'   // 设置ctrlsf 使用ag


In vundle:
Plugin 'dyng/ctrlsf.vim'

然后PluginInstall 即可安装 ctrlsf。

基本用法:
:CtrlSF pattern dir  // 如果后面不带 dir 则默认是 . 当前目录搜索
这样 it will split a new window to show search result.

使用 j k h l 浏览CtrlSP窗口  使用 Ctrl + j/k 在匹配项中跳转。
使用 q 则退出 CtrlSP窗口

Running :CtrlSFOpen can reopen CtrlSF window if you are interested in other matches. It is free because it won't invoke a same but new search.

-i 选项表示 是否 忽略大小写

查看帮助  :help ctrlsf -options.

let g:ctrlsf_open_left = 0  // 表示窗口在左边还是右边打开
但在OS X 则
let g:ctrlsf_position = "right"  // "left"


Use Your Own Map

Besides the commands, there are also some useful maps.

<Plug>CtrlSFPrompt

Input :CtrlSF in command line for you, just a handy alias.

<Plug>CtrlSFVwordPath

Input :CtrlSF foo in command line where foo is the current visual selected word, waiting for further input.

<Plug>CtrlSFVwordExec

Similar to above, but execute it for you.

<Plug>CtrlSFCwordPath

Input :CtrlSF foo in command line where foo is the word under cursor.

<Plug>CtrlSFPwordPath

Input :CtrlSF foo in command line where foo is the last search pattern of vim.

For a detail list of all maps, please refer to the document file.

I strongly recommend you should do some maps for a nicer user experience, because 8 keystrokes for every single search are really boring even pain experience. Another reason is that one of the most useful feature 'Search Current Visual Selection' can be accessed by map only.

Example:

nmap     <C-F> <Plug>CtrlSFPrompt  使用 Ctrl + f 打开查找
vmap     <C-F>f <Plug>CtrlSFVwordPath
vmap     <C-F>F <Plug>CtrlSFVwordExec
nmap     <C-F>n <Plug>CtrlSFCwordPath
nmap     <C-F>p <Plug>CtrlSFPwordPath
nnoremap <C-F>o :CtrlSFOpen<CR>

在OS X按照
brew install the_silver_searcher

Plugin 'dyng/ctrlsf.vim'    // 前提按照了Vundle.vim

let g:ackprg='ag --nogroup --nocolor --nocolumn' 

然后PluginInstall 再重新打开Vim 输入 :CtrlSP

使用vim自带的的
vimgrep /weapon/**/*.*
copen
cclose 很好用。


如果安装ack 则需要确保perl版本, 本人安装遇到问题。

Linux系统自带的perl版本一般为:v5.8.8。但是目前很多模块要求perl版本必须要5.10以上,例如:Excel::Writer::XLSX。
升级步骤如下:
1:查询perl的真实安装路径
   whereis perl
perl: /usr/bin/perl /etc/perl /usr/lib/perl /usr/X11R6/bin/perl /usr/bin/X11/perl /usr/local/bin/perl /usr/local/lib/perl /usr/share/perl /usr/share/man/man1/perl.1.gz
   真实安装路径为:/usr/bin/perl
  
2:下载新版本perl
   http://www.cpan.org/src/5.0/perl-5.14.1.tar.gz

3:安装包
# tar xvf  perl-5.14.1.tar.gz
# cd perl-5.14.1
# ./Configure -des -Dprefix=/usr  ----/usr 为perl的安装路径根目录
# make
# make install

4:查询perl是否安装成功
# perl -version


ack requires Perl 5.8.8 or higher. Perl 5.8.8 was released January 2006.

# Required
perl Makefile.PL
make
make test
sudo make install # for a system-wide installation (recommended)
# - or -
make ack-standalone
cp ack-standalone ~/bin/ack2 # for a personal installation

猜你喜欢

转载自catdoc.iteye.com/blog/2162402