vim : ctrlp

thanks to the author:

https://blog.csdn.net/dark_tone/article/details/52914218

Ctrlp到底是做什么的?

先看看spf13里对它的描述:


Ctrlp replaces the Command-T plugin with a 100% viml plugin. It provides an intuitive and fast mechanism to load files from the file system (with regex and fuzzy find), from open buffers, and from recently used files.

QuickStart Launch using<c-p>.

 

渣翻译:

ctrlp 完全取代 command-t插件在vim中,它提供了一种直观和快速的机制装载文件,从文件系统,从打开的缓冲区以及最近使用过的文件里。

快速启动 <ctrl+p>

 

Full path fuzzy file, buffer, mru, tag,... finder for Vim.

  • Written in pure Vimscript for MacVim, gVim and Vim 7.0+.
  • Full support for Vim's regexp as search patterns.
  • Built-in Most Recently Used (MRU) files monitoring.
  • Built-in project's root finder.
  • Open multiple files at once.
  • Create new files and directories.

渣翻译:

完全模糊路径在vim寻找文件,缓冲区,最近用过的文件,标签等等。

由纯vim脚本写成,适用于macvim,gvim和vim7.0+

完全支持vim正则表达式作为搜索

内置监测大多数最近用过的文件

内置工程根目录寻找

一次打开多个文件

创建新文件和目录

 

个人总结:

ctrlp 和nerdtree都可以划分到文件系统管理。

nerdtree尽管提供了书签和nerdtreefind功能,但如果文件比较多的情况下,使用起来依然不够便捷。

我们需要一种机制,能在大量零散的文件里快速定位,查找并打开我们需要的哪部分文件,这就是ctrlp的功能。

同时,ctrlp还能完成nerdtree中创建文件及目录的功能。

 

Basic Usage

  • Run :CtrlP or:CtrlP [starting-directory] to invoke CtrlP in find file mode.
  • Run :CtrlPBuffer or:CtrlPMRU to invoke CtrlP in find buffer or find MRU file mode.
  • Run :CtrlPMixed to search in Files, Buffers and MRU files at the same time.

Check :help ctrlp-commands and:help ctrlp-extensions for other commands.

Once CtrlP is open:

  • Press <F5> to purge the cache for the current directory to get new files, remove deleted files and apply new ignore options.
  • Press <c-f> and<c-b> to cycle between modes.
  • Press <c-d> to switch to filename only search instead of full path.
  • Press <c-r> to switch to regexp mode.
  • Use <c-j>,<c-k> or the arrow keys to navigate the result list.
  • Use <c-t> or<c-v>, <c-x> to open the selected entry in a new tab or in a new split.
  • Use <c-n>,<c-p> to select the next/previous string in the prompt's history.
  • Use <c-y> to create a new file and its parent directories.
  • Use <c-z> to mark/unmark multiple files and<c-o> to open them.

Run :help ctrlp-mappings or submit? in CtrlP for more mapping help.

  • Submit two or more dots.. to go up the directory tree by one or multiple levels.
  • End the input string with a colon: followed by a command to execute it on the opening file(s): Use :25 to jump to line 25. Use :diffthis when opening multiple files to run:diffthis on the first 4 files.

渣翻译:

基础用法

   执行  :CtrlP 或 :CtrlP [starting-directory] 来借助ctrlp查找文件
   执行:CtrlPBuffer 或 :CtrlPMRU 来借助ctrlp查找缓冲区或最近使用过的文件
   执行:CtrlPMixed 同时搜索文件夹,缓冲区,以及最近试用过的文件
   执行:help ctrlp-commands 和 :help ctrlp-extensions 了解其他命令


一旦ctrlp打开了:
   按F5清除当前目录的缓冲以便获取新文件,移除被删掉的文件以及应用新的忽略选项。
    按<ctrl-f>和<ctrl-b>在两种模式间循环
    按<ctrl-d>切换到仅搜索文件名而不是完整路径
    按<ctrl-r>切换到正则表达式模式
    使用<ctrl-j>,<ctrl-k>或者方向键在结果列表移动
    使用<ctrl-t>或<ctrl-v>,<ctrl-x>以新表,新窗口分割方式打开选定项
    使用<ctrl-n>,<ctrl-p>在历史记录里选择上一项或下一项
    使用<ctrl-y>来创建新文件和它的父目录
    使用<ctrl-z>来标记(取消标记)多个文件,使用<ctrl-o>来打开它们
在ctrlp中执行:help ctrlp-mappings或?获取更多快捷键映射帮助。

    使用两个或多个符号..来升起单层或多层目录树

    使用:25会跳转到打开文件的第25行,当打开多个文件的时候使用:diffthis,会在最开始的4个文件里执行。

 

Basic Options

  • Change the default mapping and the default command to invoke CtrlP:

    let g:ctrlp_map = '<c-p>'
    let g:ctrlp_cmd = 'CtrlP'
  • When invoked without an explicit starting directory, CtrlP will set its local working directory according to this variable:

    let g:ctrlp_working_path_mode = 'ra'

    'c' - the directory of the current file.
    'a' - the directory of the current file, unless it is a subdirectory of the cwd
    'r' - the nearest ancestor of the current file that contains one of these directories or files:.git .hg .svn .bzr_darcs
    'w' - modifier to "r": start search from the cwd instead of the current file's directory
    0 or '' (empty string) - disable this feature.

    If none of the default markers (.git.hg .svn .bzr _darcs) are present in a project, you can define additional ones withg:ctrlp_root_markers:

    let g:ctrlp_root_markers = ['pom.xml', '.p4ignore']

    If more than one mode is specified, they will be tried in order until a directory is located.

  • If a file is already open, open it again in a new pane instead of switching to the existing pane

    let g:ctrlp_switch_buffer = 'et'

  • Exclude files and directories using Vim'swildignore and CtrlP's own g:ctrlp_custom_ignore. If a custom listing command is being used, exclusions are ignored:

    set wildignore+=*/tmp/*,*.so,*.swp,*.zip     " MacOSX/Linux
    set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe  " Windows
    
    let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
    let g:ctrlp_custom_ignore = {
      \ 'dir':  '\v[\/]\.(git|hg|svn)$',
      \ 'file': '\v\.(exe|so|dll)$',
      \ 'link': 'some_bad_symbolic_links',
      \ }
  • Use a custom file listing command:

    let g:ctrlp_user_command = 'find %s -type f'        " MacOSX/Linux
    let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d'  " Windows
  • Ignore files in .gitignore

      let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']

Check :help ctrlp-options for other options.

 

渣翻译:

基本设定

改变CTLRP启动默认映射和默认的命令,vimrc中添加

let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
 

当引用没有明确的开始目录时,CTLRP会按照以下值来设定工作目录

let g:ctrlp_working_path_mode = 'ra'
‘c’--当前文件的目录
‘a’--当前文件的目录,除非它是cwd的子目录
‘r’--最近的当前文件,包含了这些.git .hg .svn .bzr_darcs文件或目录
‘w’--和r类似,以cwd开始搜索,而非以当前文件目录


如果默认文件标记(.git .hg .svn .bzr _darcs)都不在项目里,你可以用g:ctrlp_root_markers添加进去

  1. let g:ctrlp_root_markers = ['pom.xml''.p4ignore']  


如果超过一种模式被指定,它们会试图按次序执行直到一个目录被定位。
 
如果一个文件已经打开,会在新框里再次打开它,而非切换到当前方框。
  1. let g:ctrlp_switch_buffer = 'et'  


 
排除文件和文件件使用vim的wildignore以及ctrlp自己的g:ctrlp_custom_ignore,如果使用了自定义文件列表命令,排除会被忽略
  1. set wildignore+=*/tmp/*,*.so,*.swp,*.zip     " MacOSX/Linux  
  2. set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe  " Windows  
  3.   
  4.   
  5. let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'  
  6. let g:ctrlp_custom_ignore = {  
  7.   \ 'dir':  '\v[\/]\.(git|hg|svn)$',  
  8.   \ 'file''\v\.(exe|so|dll)$',  
  9.   \ 'link''some_bad_symbolic_links',  
  10.   \ }  


 
使用自定义文件列表命令
  1. let g:ctrlp_user_command = 'find %s -type f'        " MacOSX/Linux  
  2. let g:ctrlp_user_command = 'dir %s /-n /b /s /a-d'  " Windows  


 
在.gitignore中忽略文件
  1. let g:ctrlp_user_command = ['.git''cd %s && git ls-files -co --exclude-standard']   



插件使用个人总结:

ctrlp插件主页文档写的真烂,很多地方含糊不清,要详细了解它的设定(options),必须观看doc部分。
概括的说,ctrlp在搜索定位文件或目录时,大体可分成两种模式,第一是文件名模式,第二是正则表达式模式。
每一种模式又适用于三种不同的工作范围,文件系统(磁盘上),缓冲区(内存里),使用过的文件(内部维护记录列表)。
当然,也可以同时在三个范围里进行。
插件提供的所有模式切换和命令都取决于此。
对于初学者,没有必要每项都详细记忆,特别是options设置部分,大量需要在vimrc配置文件中添加。
我们只需要了解基础用法,比如<F5>类似于重置,<ctrl+f>和<ctrl+b>在文件系统和缓冲区mode切换。

<ctrl+d>是文件名模式,<ctrl+r>是正则表达式模式。

<ctrl+y>创建新文件和目录,<ctrl+z>配合<ctrl+o>打开多个文件。

符号..用来收起目录树,冒号:25可以迅速跳转到打开文件的第25行。


个人实践: 

spf13提供的快速启动键是<ctrl+p>,打开gvim,按下快捷键如图:

    

我的工作路径是在桌面,ctrlp插件自动将桌面上的所有文件列举了出来。

并且等待用户输入。

想在结果列表中移动光标,使用方向键上下,按<ENTER>即可打开。

如何关闭掉ctrlp窗口呢?此时再按<ctrl+p>无效,实测按<ESC>键。

那么spf13提供的<ctrl+p>快捷键,启动的是ctrlp哪一种模式?

和:CtrlP ,:CtrlPBuffer以及:CtrlPMRU区别在哪里?

手工输入:CtrlPBuffer



因为没有打开文件,buffer缓冲区里肯定没有结果。

再次手工输入CtrlPMRU



最近使用过的文件列表都显示出来了。
由此可见,spf13默认提供的启动快捷键,是工作在文件系统(files)上的,每一种工作模式都被黄色高亮显示。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值