duanji1056 2014-09-27 03:10
浏览 53
已采纳

VIM搜索 - 用于搜索特定文件的FuzzyFinder

I'm newbie at VIM using it as IDE. I'm trying to figure how to open in an easy way files within my "project".

I have this configurations in my .vimrc file:

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 <abrahamsustaita@gmail.com>'

" 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

So every new buffer is opened in a new tab.

I know if I do:

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

for instance, it will open the file library/Core/Session/Object.php But the problem is if I make one mistake, instead of open the file, it will open a new Buffer with the name libra*/Core/Sess*/Ob* (supposing the file does not exists). Also, I don't like to be writing every time all the / so will be better to just do:

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

But it will open a new buffer with that name (libr*Cor*Sess*Obj*.php), instead of opening the file...

I came to know also that I can do:

:fin libra(press tab here) 

And it will autocomplete... but the problem here is it will show (for this example) :find libexslt/ and I know for sure that folder is not within the folder I'm. Actually, here is an screenshot of the folders I have there:

Folders on working folder

So as you can see, I have no libexslt there... so I don't know where it is getting that info from...

Is there any way to open a file easily? In this example, I know the file is Session/Object.php so could I do something like:

:fin *Sessi*Obj*php

? Also, I know the file has inside the declaration:

<?php
class Core_Session_Object

Or, another example,

<?php
namespace Core\Session;
class Object 

Can I do something like:

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

?

  • 写回答

2条回答 默认 最新

  • dseigqk7443 2014-09-27 09:56
    关注

    You can use tab-completion for :edit and :find but the default mechanism is not very user-friendly. The "wildmenu" is a very nice feature that makes the whole process a lot easier. Enable it with:

    :set wildmenu
    

    and take a look at the following sections of the documentation:

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

    The ** wildcard allows you to recurse through subdirectories so you can do:

    :e **/obj*ph<Tab>
    

    The behavior of :find depends on the value of the path option whose default value is not very useful if you don't write C.

    Set it to this much more useful generic value to recurse through subdirectories:

    :set path=.,**
    

    With the settings above, you should be able to open your file with:

    :e **/obj*ph<Tab>
    

    or:

    :find obj*ph<Tab>
    

    Note that opening a file to access a method or some other symbol is not very efficient, whether you use clever commands/mappings or not. Tag-jumping is a much more efficient method. You'll need a symbol "database", usually crated before the search, for that, though.

    See these sections of the documentation:

    :help tags
    :help ctags
    :help cscope
    

    And :h include-search for a lightweight variant.

    Using :vimgrep or :grep can also serve your needs but I'd suggest you take a look at the faster ack and ag.


    Here is a cleaned up version of your vimrc with the relevant options added:

    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 <abrahamsustaita@gmail.com>'
    
    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'
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端