Hot answers tagged

24

Here are the relevant parts of my setup: enable the wildmenu, set wildmenu make filename-completion skip these files and directories, set wildignore+=*.swp,*.bak set wildignore+=*.pyc,*.class,*.sln,*.Master,*.csproj,*.csproj.user,*.cache,*.dll,*.pdb,*.min.* set wildignore+=*/.git/**/*,*/.hg/**/*,*/.svn/**/* set wildignore+=*/min/* set wildignore+=tags,...


14

The following enables fuzzy file search (i.e :find script.js) through every file in your project root while excluding the node_modules dir and its contents. set path+=** set wildignore+=**/node_modules/** Tested on: VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Sep 11 2017 13:57:34) ...


14

"Current directory" and "directory of the current file" are two different things. The "current directory" is by default the directory in which you started Vim. You ask Vim what it is with :pwd and change it with :cd or :lcd or by setting the autochdir option. If you never change it, it will stay the same until you close the current session. The "directory ...


8

let &path += fnamemodify(tagfiles()[0], ':p:h') should add the path of your tags file's parent directory to the path option. Updating path each time you enter a buffer is probably a good idea: augroup UpdatePath autocmd! autocmd BufNewFile,BufRead,BufEnter * set path&vim | let &path += fnamemodify(tagfiles()[0], ':p:h') augroup END


7

The directory of the current file and current directory are two entirely different things (that may, on occasion, have the same value). Consider: cd /tmp; vim /etc/bash.bashrc Unless I have autochdir (or something similar) set, the current directory is /tmp, yet the directory of the current file is /etc.


7

Edit If need to get the filename of your script I haven't found a good way to do that in the doc, so here is the solution I would suggested: At the beginning of your script define a script-variable (see :h script-variable) like this: let s:filename="MyFileName.vim" The variable will be locale to the script so it is accessible and modifiable only from ...


7

&path has nothing to do with $PATH. Also $PATH is set and used. See :echo $PATH. You should also be able to change its value with :let $PATH = $PATH.':some/path' -- there are a few write only things, $PATH is not one of them IIRC


6

You can add ** to your path: set path+=** This way it will find every file recursively based on your current directory. But apparently it's not recommended. If you want to add other paths, you can just add them as follow: set path+=/path/to/your/lib set path+=c:/include


6

You cannot configure the path that :read will use. It will always start from the current directory. :read is not affected by the path variable in vim (see :h path). Although, see the workaround sections below. Note that once you input :read into the prompt you can use tab for file and directory completion, including going up (with ..) and down the ...


5

:E[xplore] does the same thing as :e %:h, and is shorter to type. If you look up :help :Explore, you can see that there are also variations to open the directory of the current file in a new tab or split instead of in the current window.


5

I think you’ve misunderstood 'path'. The path option determines which directories are searched for included files. But what files are included are determined by the options include, suffixesadd, and includeexpr. These are used in combination to detect that the current file includes/imports some other filename; then that filename is searched for in the ...


4

If you press Ctrl+xCtrl+f immediately after typing the ~, i.e. before typing the trailing slash, it is expanded to /home/user/.


4

Would be nice to see the full error, on which line it complains. Nevertheless you have error in the script, the set command requires no spaces around =, or spaces at all after = sign. You should also use setlocal, since set works globally (it will set for all buffers). And whole auto-command expression should be enclosed in execute with concatenation with ...


4

Google for vim to find their homepage. You find http://www.vim.org . Look on their homepage, where is their upstream source. If you have luck, they are on the github. On the "Download" section, they show many of their upstreams, first is the github one. They say, git clone https://github.com/vim/vim.git is the clone command what you want, however you want ...


3

You're looking for %:h/ NB: you can tab-complete at any point after the :h.


3

Yes, it's possible. You can run the command in a sub-shell (assuming that you're running in Unix and not Windows) and include a cd command at the start of the sub-shell. For example, :!(cd /usr/local; ls) Or even simpler, :!cd /usr/local; ls


3

See :h :command-completion-custom We can adapt the last example to complete only files listed by git. command! -nargs=1 -bang -complete=customlist,GitFindComplete \ GitFind edit<bang> <args> function! GitFindComplete(ArgLead, CmdLine, CursorPos) let search_pattern = "*" . a:ArgLead . "*" let shell_cmd = "git ls-files " . shellescape(...


3

If you save, you can then use :e again, to display that information. Also, you can use g Ctrl-g and/or Ctrl-g at any time to find out some (or the other) of the original info.


3

Make and Ninja offer a -C flag. From Ninja: -C DIR change to DIR before doing anything else If I run Ninja in a shell with the -C flag pointing somewhere that isn't the working directory, then the reported paths are the same as if I had cd'd over to the build directory. Nonetheless, Vim knows to become more intelligent when you use this flag in your ...


3

Another alternative is to use a plugin for file search that automatically adds all directories in your project. I like to use the CtrlP plugin to navigate to files in my project. I open file under cursor by <Leader>gf. You will need this in your vimrc " Leader gf copies word under cursor to ctrlp nmap <leader>gf :CtrlP<CR><C-\>w


3

You can use the :find command to locate a file by name and open it for editing. :find will search for the file in the directories listed in 'path', which by default includes the current directory. You can add more directories to 'path' that you want to look up, and you can use wildcards, including ** to traverse multiple subdirectories. In particular, to ...


2

How about using an input abbreviation? E.g. using iabbrevv ~~ /home/duck, when you type ~~/ it will be expanded to /home/duck/ immediately and you can continue as normal. Or maybe just a mapping: inoremap <C-x><C-f> <C-[>viW:s/\~/\/home\/duck/<CR>Ea<C-x><C-f> This will simply substitute the tilde of the WORD you're ...


2

This is probably impossible without any plugins, as mentioned on the comments. But you wouldn't have to start from the scratch if you want to implement such functionality using VimL, you could use the BufNameComplete plugin as a starting point (note that it uses the CompleteHelper : Generic functions to support custom insert mode completions plugin, which ...


2

There are a lot of commands in netrw for directory navigation. Some that come to mind: :Rexplore (to return from a file to netrw); :help netrw-qb will inform you of netrw's history mechanism (u, U), :help g:netrw_keepdir, etc.


2

:e %:h navigates to the directory of the current file. See :help expand() for more info. Tim Pope's Vinegar plugin essentially binds - to this, and introduces a few small other conveniences. You could also use <c-o> to navigate to the previous jump/file shown in the current window.


2

For example, if your ninja output directory is '$SRC/out' :set makeprg=ninja\ -C\ $SRC/out Note: the space should escape by backslash


2

Rather than explicitly specifying paths to the files you have in mind, try using built-in file path handling functions like expand() (potentially with <sfile>) or glob()/globpath(). For instance, if you're looking for the root directory of your own plugin, you might try let s:plugin_dir = expand("<sfile>:h:h") I'm not sure how glob will work, ...


2

I'd either make sure that neither / nor \ are in the &isk(momentarily), then match \<vimf90\>, or I'd match [/\\] ([/\\\\] actually because of filter()) -- I've plenty examples in path.vim module from my lh-vim-lib library plugin. In mu-template, I didn't have your problem as I don't restrict my search for matching directories to {rtp}/...


2

This stores the current filename in the system clipboard with backslashes replaced with forward slashes: noremap <silent> <F5> :let @+ = substitute(expand("%:p"), '\', '/', 'g')<cr>


Only top voted, non community-wiki answers of a minimum length are eligible