Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get add folder to Projects (like Sublime Text) in VIM?

I just switched from Sublime Text to GVIM (on Windows). I am still debating whether I should continue ST or move completely to VIM. One feature that I desperately need (or miss) are

  1. Ctrl+P to go to any file that I want in my list of folders.
  2. Ctrl+Shift+f to find (and replace) any text in those list of folders.

I had added number of folders using Add Folders to Project feature in Sublime Text 3. It was really helpful. Now, I know that CtrlP plugin for VIM can do similar thing, but I can't figure out how to make it search the folders that I want, and not the root directory of current file.

I played around a bit with setting path in my vimrc file without much success.

Can you please help. If it is a repeated question, please excuse me.

Thanks.

like image 448
DigitalNomad Avatar asked Dec 02 '25 16:12

DigitalNomad


2 Answers

AFAIK, ctrlp plugin only searches within one directory (and its descendants). Use the Unix features: make a directory with links to out-of-project directories you are interested in. This way, the association with out-of-project directories is not just something the editor knows about, but something recorded in the actual project.

Search and replace is a bit stickier thing. You want to work with all the files you are interested in, then repeat the replace command through all of them. For example, if you want to do the search for foo and replace with bar on all C files here and under,

:args **/*.c
:argdo %s/foo/bar/g
like image 170
Amadan Avatar answered Dec 04 '25 11:12

Amadan


  1. Ctrl+P to go to any file that I want in my list of folders.

    The :find command can be used to "find" a file in the directories specified in the 'path' option:

    set path+=/some/arbitrary/path
    set path+=/another/one
    
    :find *foo
    

    I find these two mappings very handy:

    nnoremap <key> :find *                                    " search in every directory
                                                              " in 'path'
    nnoremap <key> :find <C-R>=expand('%:p:h').'/**/*'<CR>    " start from the directory
                                                              " of the current file
    
  2. Ctrl+Shift+f to find (and replace) any text in those list of folders.

    What amadan said above.

like image 40
romainl Avatar answered Dec 04 '25 11:12

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!