2014-09-27 178 views
0

我是VIM的新手,将它用作IDE。我试图想象如何以简单的方式打开我的“项目”中的文件。VIM搜索 - FuzzyFinder搜索特定文件

我在.vimrc文件中这样配置:

colorscheme Tomorrow-Night 
" nocompatible has to be the first of all (use the real vimpower) 
set nocompatible 

" backup rules 
set backup " enable backup files (.txt~) 
set undofile " enable persistent undo 

silent execute '!mkdir -p $HOME/.vim/tmp/backup' 
set backupdir=$HOME/.vim/tmp/backup " where to store backup 
silent execute '!mkdir -p $HOME/.vim/tmp/swap' 
set directory=$HOME/.vim/tmp/swap " where to store swap 
silent execute '!mkdir -p $HOME/.vim/tmp/views' 
set viewdir=$HOME/.vim/tmp/views " where to store view 
silent execute '!mkdir -p $HOME/.vim/tmp/undo' 
set undodir=$HOME/.vim/tmp/undo " where to store undo 

" syntax 
syntax on " enable syntax highlighting 
" filetype 
filetype on " enable filetype detection 
filetype plugin on " enable filetype plugins 
filetype indent on " enable filetype indentation 

" tabstop settings 
set tabstop=4 " a tab found in a file will be represented with 4 columns 
set softtabstop=4 " when in insert mode <tab> is pressed move 4 columns 
set shiftwidth=4 " indentation is 4 columns 

" show linenumbers 
set number 

" Documentation configuration 
let g:pdv_cfg_Author = 'Abraham Cruz <[email protected]>' 

" Autocompletition 
" Complete options (disable preview scratch window) 
set completeopt = menu,menuone,longest 
" Limit popup menu height 
set pumheight = 15 

" SuperTab option for context aware completion 
let g:SuperTabDefaultCompletionType = "context" 
let g:SuperTabNoCompleteAfter = ['^', ',', '\s']   
let g:SuperTabMappingForward = '<c-space>' 
let g:SuperTabMappingBackward = '<s-c-space>' 

" Disable auto popup, use <Tab> to autocomplete 
" let g:clang_complete_auto = 0 
" Show clang errors in the quickfix window 
let g:clang_complete_copen = 1 

" TagBar Lint 
let g:tagbar_phpctags_memory_limit = '512M' 

" Upload on save if the project is configured to do so 
autocmd BufWritePost * :call SyncUploadFile() 

" Open each buffer in its own tab 
:au BufAdd,BufNewFile * nested tab sball 

所以每一个新的缓冲区在新标签打开。

我知道如果我这样做:

:e libra*/Core/Sess*/Ob* 

例如,它会打开文件library/Core/Session/Object.php但问题是,如果我做了一个错误,而不是打开该文件,它会打开一个新的缓冲区与名称libra*/Core/Sess*/Ob*(假设文件不存在)。还有,我不喜欢被写入每一个所有/时间,以便将更好地只是做:

:e libr*Cor*Sess*Obj*.php 

但它会打开一个新的缓冲与该名称(libr*Cor*Sess*Obj*.php),而不是打开该文件。 ..

我也来知道我可以这样做:

:fin libra(press tab here) 

它会自动完成......但这里的问题是,它会显示(在这个例子中):find libexslt/,我知道肯定文件夹不在我的文件夹内。其实,这里是我有文件夹的截图:

Folders on working folder

因此,大家可以看到,我没有libexslt那里......所以我不知道它正从这些信息。 ..

有什么方法可以轻松打开文件吗?在这个例子中,我知道文件是Session/Object.php所以我可以这样做:

:fin *Sessi*Obj*php 

?另外,我知道该文件的声明中:

<?php 
class Core_Session_Object 

或者,另一个例子,

<?php 
namespace Core\Session; 
class Object 

我可以做这样的事情:

:vimgrep /class*Core_Session_Object/ *.php 
:vimgrep /name*Core*Sess*Obj/ *.php 

回答

2

您可以使用制表符完成:edit:find,但默认机制不是非常用户友好。 “wildmenu”是一个非常不错的功能,使整个过程很多更容易。与启用:

:set wildmenu 

,并采取一看文档的以下部分:

:help wildmenu 
:help wildmode 
:help wildignore 
:help wildignorecase 

**通配符,您可以通过子目录递归,所以你可以这样做:

:e **/obj*ph<Tab> 

:find的行为取决于path选项其默认值不是非常有用的,如果你不写C.

将其设置为这个有用得多通用的价值通过子目录递归值:

:set path=.,** 

通过上面的设置,你应该能够打开文件以:

:e **/obj*ph<Tab> 

或:

:find obj*ph<Tab> 

注意,打开文件访问的方法或其他符号是不是非常有效的,无论你用聪明的命令/映射或没有。跳标是的一种更有效的方法。不过,你需要一个符号“数据库”,通常是在搜索之前创建的。

查看文档的以下部分:

:help tags 
:help ctags 
:help cscope 

而且:h include-search一个轻量级的变种。

使用:vimgrep:grep也可以满足您的需求,但我建议您看看更快的ackag


这是你vimrc的清理版本添加了相关的选项:

filetype plugin indent on 
syntax on 

colorscheme Tomorrow-Night 

set wildmenu 

set path=./** 

set backup 
set undofile 

silent execute '!mkdir -p $HOME/.vim/tmp/backup' 
set backupdir=$HOME/.vim/tmp/backup " where to store backup 
silent execute '!mkdir -p $HOME/.vim/tmp/swap' 
set directory=$HOME/.vim/tmp/swap " where to store swap 
silent execute '!mkdir -p $HOME/.vim/tmp/views' 
set viewdir=$HOME/.vim/tmp/views " where to store view 
silent execute '!mkdir -p $HOME/.vim/tmp/undo' 
set undodir=$HOME/.vim/tmp/undo " where to store undo 

set tabstop=4 
set softtabstop=4 
set shiftwidth=4 

set number 

set completeopt = menu,menuone,longest 
set pumheight = 15 

augroup VIMRC 
    autocmd! 
    autocmd BufWritePost * :call SyncUploadFile() 
    autocmd BufAdd,BufNewFile * nested tab sball 
augroup END 

let g:pdv_cfg_Author = 'Abraham Cruz <[email protected]>' 

let g:SuperTabDefaultCompletionType = "context" 
let g:SuperTabNoCompleteAfter = ['^', ',', '\s'] 
let g:SuperTabMappingForward = '<c-space>' 
let g:SuperTabMappingBackward = '<s-c-space>' 

let g:clang_complete_copen = 1 

let g:tagbar_phpctags_memory_limit = '512M' 
+0

非常感谢!这对我帮助很大。关于数据库,我试图使用ctag,但我真的不喜欢它的行为方式...... – Cito 2014-09-27 14:34:16

0

它总是好的学习纯Vim的方法用于导航的文件,这使得romainl的回答真的很不错。

还有一些插件可以提供模糊查找功能。

  1. Ctrl-p plugin
  2. Command-t plugin

这就是说,我已经CTRL-P安装了很长时间,但我很少使用它,因为我并不需要它。