Hot answers tagged

19 votes

Ignore folders when performing :find command

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+=** ...
bajocode's user avatar
  • 191
16 votes
Accepted

Is Vim's default 'path' option redundant?

"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 ...
romainl's user avatar
  • 38.3k
8 votes
Accepted

Access a file under subdirectories of a path through gf command

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 ...
nobe4's user avatar
  • 15.8k
7 votes
Accepted

How to set the vim path to your bash PATH?

&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 ...
Luc Hermitte's user avatar
  • 16.9k
7 votes
Accepted

Current VimL script path from inside a function

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 (...
statox's user avatar
  • 49k
7 votes

Is Vim's default 'path' option redundant?

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 ...
muru's user avatar
  • 24.7k
6 votes
Accepted

directory path search for :read

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 ...
grochmal's user avatar
  • 1,636
5 votes
Accepted

shortcut of the current directory path when vsplit/split

You're looking for %:h/ NB: you can tab-complete at any point after the :h.
Luc Hermitte's user avatar
  • 16.9k
5 votes

How do I get "~" (tilde) to expand when using File Name Completion in Insert Mode?

If you press Ctrl+xCtrl+f immediately after typing the ~, i.e. before typing the trailing slash, it is expanded to /home/user/.
Sakari Cajanus's user avatar
5 votes
Accepted

Unable to find files after setting path in vim

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 ...
D. Ben Knoble's user avatar
  • 24.7k
4 votes
Accepted

vim cannot access variable in autocmd

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 ...
grodzik's user avatar
  • 4,488
4 votes

How to compile vim for user only and use git to track it?

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 ...
peterh's user avatar
  • 1,147
4 votes
Accepted

how to deduplicate packpath / runtimepath?

packpath, the option packpath is an option, which means it can be altered using the set command. The set command already does de-duplication for appending values. For example, set packpath=a set ...
Mass's user avatar
  • 13.8k
3 votes
Accepted

file search with :e

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. ...
filbranden's user avatar
  • 28.1k
3 votes

Access a file under subdirectories of a path through gf command

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 ...
Yash Ranadive's user avatar
3 votes

Is it possible to define the pwd for an external command runs in without changing VIM's pwd?

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;...
garyjohn's user avatar
  • 6,244
3 votes

How to return to netrw from a file

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), ...
user21497's user avatar
  • 776
3 votes

Enabling rubocop linter the right way

Based on :help rubocop, I would do let g:ale_ruby_rubocop_executable = 'bundle' in your config somewhere: g:ale_ruby_rubocop_executable *g:ale_ruby_rubocop_executable* ...
D. Ben Knoble's user avatar
  • 24.7k
2 votes

How do I get "~" (tilde) to expand when using File Name Completion in Insert Mode?

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: ...
PhilippFrank's user avatar
  • 1,225
2 votes

Prevent ^X^F from expanding $HOME

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 ...
mMontu's user avatar
  • 6,570
2 votes

Quickfix with makeprg running in a different directory

For example, if your ninja output directory is '$SRC/out' :set makeprg=ninja\ -C\ $SRC/out Note: the space should escape by backslash
Daniel YC Lin's user avatar
2 votes

path seperator in vim

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 ...
Ryan Lue's user avatar
  • 871
2 votes

path seperator in vim

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 ...
Luc Hermitte's user avatar
  • 16.9k
2 votes
Accepted

Getting the path with a function key

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

vim sometimes displays full path of file instead of just the filename?

That's not a nitpicky concern. You should expect an editor to behave consistently. As @Raziman points out, buffer names are relative to the current working directory, unless the associated file is NOT ...
Niko Bellic's user avatar
  • 1,744
2 votes
Accepted

Error occurs while echoing system('echo %PATH%')

It sounds like you've overridden some of the settings used to invoke external programs. Is your Vim set up so programs run in either Cygwin or Windows Linux Subsystem by any chance? Try starting vim ...
B Layer's user avatar
  • 19.4k
2 votes

shortcut of the current directory path when vsplit/split

As Luc indicated, you can type: :vsplit %:h then <Tab>. I use this mapping to transform %% into the current directory from the command line: cnoremap <expr> %% getcmdtype() ==# ':' ? ...
LEI's user avatar
  • 1,586
2 votes

Adding directory (header and source) to autocompletition search

set complete=.,w,b,u,t,i the i flag makes vim autocompletion search the including files. Also, you can use gf command at the including file to verify vim can actually find the file. However, i flag ...
Tiny Lui's user avatar
2 votes
Accepted

How to use variables in a user defined command?

Can simply use exec and . to build the command: let PathToPluginsFolder = ~/.vim/plugins command! PS silent! exec ':w | PlugSnapshot! ' . PathToPluginsFolder . '/plugins.lock'
ruohola's user avatar
  • 626

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