I think the title says it all but just to give some context, I have this set on my .vimrc
set wildignore+=*.o,*.obj,**/.git/*,**/.svn/*,**/node_modules/**,node_modules/**,.git/*,svn/*
And from the readme:-
:CommandT
A prompt will appear at the bottom of the screen along with a file window
showing all of the files in the current directory (as returned by the
|:pwd| command).
It mentions that it should show all files in the current directory but even if I cd into any directory, Command-T still goes all the way up to my Desktop and lists all the files and folders which is not what I want. I just want to search on current working directory like it says in the readme.
I also tried checking if I was indeed in the right directory by doing :pwd and it's showing me I'm in the right directory and still lists out everything. However, if I have .git folder in my root directory then it seems to work.
Am I missing something? If it helps, I also have this in my .vimrc file:-
imap <C-t> <C-c>:CommandT<CR>
vmap <C-t> <C-c>:CommandT<CR>
nmap <C-t> :CommandT<CR>
Add this line to .vimrc file
let g:CommandTTraverseSCM='pwd'
It will search in current directory instead of SCM root directory.
Warning: This is a non-answer answer to your question.
Please take #romainl's advice and look at the plugin's issue tracker.
Documentation
Command T and all good Vim plugins come with documentation. Please read all of it before asking questions. See :h command-t. The things you might have noticed if you had:
g:CommandTScanDotDirectories - basically the default config means CommandT will not search dot directories. Meaning your 'wildignore' probably doesn't need .git/.svn/... entries.
See :h command-t-wildignore for more information on CommandT and 'wildignore'
g:CommandTTraverseSCM dictates how CommandT find its root directory. The default looks for a SCM root marker, e.g. .git. If it can't find one it will fall back to the current directory. Please look at this option for more options. You may want to use let g:CommandTTraverseSCM = 'pwd'
Mappings
I have some concerns:
You should be using *noremap style mapping unless you are mapping to a <Plug>(something) or you really want recursive mappings (Hint: not usually).
Please use <esc> instead of <c-c> as they are not the same. Sure they are similar but they are not the same.
Overshadowing the <c-t> command in normal mode which pops the tag stack.
Overshadowing the <c-t> command in insert mode which increases indentation.
Probably should not even worry about creating mappings for any mode except normal mode because that is the Vim way.
My recommendation is to use the default CommandT mappings which are <leader>t and <leader>b (See :h command-t-mappings). The <leader> defaults to \ however this changes if you change the mapleader. See :h mapleader.
Related
I have a very weird problem which did not exist in my environment before but now happened. When editing files, I'm used to doing this way:
gvim . #open current directory browsing
scroll up/down to select file, enter then edit.
ctrl-6 #back to previous directory
However one day I found the step3 was failed, it said "No alternate file".
My .vimrc file only contains:
colorscheme darkblue
set number
set autoindent
set nowrap
set ignorecase
set cursorline
I tried to clean all content in .cshrc but the same.
Can anyone tell me what's wrong with my gvim ?
Thanks in advance.
This looks to be a change in behavior introduced in Vim 7.4. The netrw view is no longer stored as an alternate file. See this discussion.
The Vim maintainers seemed split on what the correct behavior should be, but Bram himself offered up this advice with a mapping:
I do realize that editing the directory of the current file is
something I often do, but I never bothered to set up a mapping for
it. Typing ":e %:h" is not too difficult, but CTRL-O to jump back to
the netrw %directory view was easier.
I now added a mapping:
map ,d :e %:h<CR>
Let's see if I can get used to that.
Another related discussion can be found here.
You are likely using netrw to edit a directory. This is the equivalent of :Explore. Sadly netrw has a bad habit of not maintaining the alternative buffer, #. You maybe able to upgrade netrw or use :Rexplore (:Rex for short) to resume exploring.
Another option is to just use :e with wildcards and tab completion to explore files. Use <c-d> to list out completions as well.
I've opened a file and modified it - now I want to do :Explore without splitting.
It splits - because I have an unsaved buffer. By default this is nice, becasuse Vim generally doesn't allow to switch files, until you do something with the modified buffer (save or discard changes).
But I have set hidden option, so I can jump from buffer to buffer, switch files and everything - and save or not when I feel I want to. It seems Netrw doesn't follow this policy. How could I help it?
One way I know of is to map netrw explore to save & explore, but I'm not sure if autowriting is a good way of doing things... I am actually using other autowriting settings now, but I was just rethinking to maybe get rid of them.
So here is the function, that does just that:
function! ExploreWithHidden()
let s:cw = getcwd()
lcd %:p:h
enew
Explore
cd `=s:cw`
endfunction
Seems to work like expected.
You could use :Texplore instead. This is the same as explore except in a new tab (and will have no splits).
:h Texplore
Another thing you could do is use :lcd %:p:h to change the current working directory to the directory of the file. Then use :enew to create another buffer then open explore. (Make sure hidden is on if the buffer is modified)
:command! BExplore :lcd %:p:h | enew | Explore
To run the command use :BExplore.
The old buffer will be sitting in the background and the explore window is pointing at the directory the file was in.
You could just upgrade your netrw -- its up to v153s at http://www.drchip.org/astronaut/vim/index.html#NETRW, and it does avoid the split if the modified buffer is hidden.
tpope's vim-vinegar operates like this. It maps - to Explore the current file's directory. (That's the same key netrw uses to go up one directory.) It uses the current window instead of splitting.
When the current file is modified:
If you have 'hidden' set, it will not split and Explore from the current window.
If you do not have 'hidden' set, it will issue an error and do nothing.
In Zsh, I can use filename completion with slashes to target a file deep in my source tree. For instance if I type:
vim s/w/t/u/f >TAB<
zsh replaces the pattern with:
vim src/wp-contents/themes/us/functions.php
What I'd like is to be able to target files the same way at the Vim command line, so that typing
:vi s/w/t/u/f >TAB<
will autocomplete to:
:vi src/wp-contents/themes/us/functions.php
I'm trying to parse the Vim docs for wildmode, but I don't see what settings would give me this. It's doing autocompletion for individual filenames, but not file paths. Does Vim support this natively? Or how can I customize the autocomplete algorithm for files?
Thanks for any advice!
-mykle-
I couldn't find a plugin to do this, so I wrote one. It's called vim-zsh-path-completion. It does what you're looking for, although via <C-s> rather than <Tab>. You can use it with <Tab> for even more control over what matches, though.
It's got bugs, but for basic paths without spaces/special characters, it should work. I think it's useful enough in its current state to be helpful. I hope to iron out the bugs and clean up the code, but I figured I'd start soliciting feedback now.
Thanks for the idea!
Original (wrong) answer, but with some useful information about Vim's wildmode.
Put the following in your .vimrc:
set wildmenu
set wildmode=list:longest
That will complete to the longest unique match on <Tab>, including appending a / and descending into directories where appropriate. If there are multiple matches, it will show a list of matches for what you've entered so far. Then you can type more characters and <Tab> again to complete.
I prefer the following setting, which completes to the first unique match on <Tab>, and then pops up a menu if you hit <Tab> again, which you can navigate with the arrow keys and hit enter to select from:
set wildmode=list:longest,list:full
Check out :help wildmenu and :help wildmode. You might also want to set wildignore to a list of patterns to ignore when completing. I have mine as:
set wildignore=.git,*.swp,*/tmp/*
Vim doesn't have such a feature by default. The closest buil-in feature is the wildmenu/wildmode combo but it's still very different.
A quick look at the script section of vim.org didn't return anything but I didn't look too far: you should dig further. Maybe it's there, somewhere.
Did you try Command-T, LustyExplorer, FuzzyFinder, CtrlP or one of the many similar plugins?
I use CtrlP and fuzzy matching can be done on filepath or filename. When done on filepath, I can use the keysequence below to open src/wp-contents/themes/us/functions.php (assuming functions.php is the only file under us that starts with a f):
,f " my custom mapping for the :CtrlP command
swtuf<CR>
edit
In thinking about a possible solution I'm afraid I was a little myopic. I was focused on your exact requirements but Vim has cool tricks when it comes to opening files!
The :e[dit] command accepts two types of wildcards: * is like the * you would use in your shell and ** means "any subdirectory".
So it's entirely possible to do:
:e s*/w*/t*/u*/f*<Tab>
or something like:
:e **/us/f<Tab>
or even:
:e **/fun<Tab>
Combined with the wildmode settings in Jim's answer, I think you have got a pretty powerful file navigation tool, here.
I installed Nerd_tree plugin for vim on ubuntu 10.04. It is great plugin. But I met the following problems:
after open nerd_tree to browse the files in /etc/apache2/sites-available/, now I close it, and go on with my work. Later I want open nerd_tree again to edit another file in /etc/apache, but nerd_tree shows me always the user home directory /home/toledot, So I have to up dir->up-dir->up-dir again. Is there a way let nerd_tree to remember the path, which I have used at the last minute?
I opened nerd_tree and select one file to edit. After my update on this file, and want to select another file to make some change. But I can not go back to the nerd_tree. I tried to make double click and tab and so on. It doesn't work. What is the hotkey to switch nerd_tree and the opened files in vim?
I am absolute new with vim and plugins, so please help me and explain the solution in details. I am very thankful for any suggestion or infos.
A couple of points that may be helpful.
If you set autochdir the current working directory will be automatically be set to that of the current file. You can do this either interactively or in your .vimrc file.
The official way to open the NERDTree window seems to be with the command :NERDTree. You can map this to any convenient key sequence.
You should be able to view the helpfile with the command :help NERDTree. If you have trouble getting the help, change to the directory containing file NERD_tree.txt (in vim) and execute :helptags .
You can also add bookmarks for file/directories that you often use. See
:help NERDTreeBookmarkCommands.
What you need is a handy map to :NERDTreeToggle. Put this in your .vimrc
nmap <silent> <F4> :NERDTreeToggle<CR>
And just hit <F4> to open/close NERDTree, just like that, just as you last toggle-closed it.
You can also open a specific directory using :NERDTree /my/dir
I advise you to set autochdir so that whenever you open a file, working directory (you can find out this with :pwd) will be changed accordingly
I'm looking for a way to make Vim have the ability to open a file by fuzzy-searching its name.
Basically, I want to be able to define a project once, and then have a shortcut which will give me a place to type a file name, and will match if any letters match up.
This kind of functionality exists in most editors I've seen, but for the life of me I can't understand how to get Vim to do this.
Note that I'm looking for something that won't require me to have any idea where in my directory tree a file is. I just want to be able to open it by the filename, regardless of what directory it's in.
Thanks
There are two great vim plugins for this.
ctrlp:
Written in pure VimL
Works pretty much everywhere
Supports custom finders for improved performance
Most popular fuzzy search plugin for Vim
Command-T:
Written in C, VimL and Ruby
Fast out of the box
Requires +ruby support in Vim
Recommends Vim version >= 7.3
EDIT:
I use CtrlP with ag as my custom finder and it's incredibly quick (even on massive projects) and very portable.
An example of using ag with CtrlP:
if executable('ag')
" Use Ag over Grep
set grepprg=ag\ --nogroup\ --nocolor
" Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
endif
CommandT for Vim is very much the comparable feature as in TextMate. My work flow is now
1) open up MacVim
2) :cd ~/my_project
3) (I have this mapped as described in the installation help)
4) C-v the file to open the file in a vertical split, or CR to open a new horizontal split.
5) to close the split, use :bd (buffer delete)
6) to switch to another buffer, I have BufferExplorer installed, so just \be and select
This workflow is comparable to TextMate, it takes a while to get used to, and I'm still learning.
Basic solution
Simply add this to your .vimrc
nnoremap <C-p> :find ./**/*
Pressing Ctrl+p will now allow you to fuzzyfind files in your current working directory and sub-directories thereof. Use the tab key to cycle through options.
Related solution
For those who want to keep it basic i.e. no plugins, this entertaining video shows another way to achieve fuzzy file find in vim.
They actually use
set path+=**
set wildmenu
in their .vimrc to find files in current sub-directories.
For example, with :find *Murph followd by tab, I would find the files KilianMurphy2012Why.R and KilianMurphy2014ROLE.R in subdir code which I can cycle through with the tab key. The first solution above has the advantage that the relative path is also shown.
Note that your current working directory will matter and that other files on your path (:set path?) will also be found with the this type of solution. The wildmenu option adds visual information and is not essential.
For a keyboard shortcut, add
nnoremap <C-p> :find *
to your .vimrc. Now you will be able to quickly search for files inside your project/current dir with Ctrl+p in normal mode.
What about http://www.vim.org/scripts/script.php?script_id=1984 Then there is http://github.com/jamis/fuzzy_file_finder .
Also see these blog posts: http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim and http://weblog.jamisbuck.org/2009/1/28/the-future-of-fuzzyfinder-textmate
HTH