Skip to main content
Share Your Experience: Take the 2024 Developer Survey
21 votes
Accepted

opening another file with path relative to current directory

Have you tried the edit command? :edit b.pl Edit: Not sure if you edited in the last question, or I just missed it the first time. But the only reason you wouldn't be able to use relative paths on :...
Tumbler41's user avatar
  • 7,756
20 votes

opening another file with path relative to current directory

Use :e %:h<filename>, or specifically for your question :e %:hb.pl. Individually these tokens mean :e edit, but you could use :tabnew or :split etc % the current file path :...
do0g's user avatar
  • 301
15 votes
Accepted

How to run internal Vim terminal at current file's dir?

I am grateful to @statox for useful hints, but as I don't wont to change current dir each time I come to following: map <F6> :let $VIM_DIR=expand('%:p:h')<CR>:terminal<CR>cd $...
ephemerr's user avatar
  • 853
14 votes
Accepted

How to do :Sex but with a vertical split?

What you're looking for is :Vexplore. From your question, it sounds like you started off knowing only about :Sexplore and understandably thought that that was the basic command for bringing up the ...
Mike Holt's user avatar
  • 278
10 votes

How to run internal Vim terminal at current file's dir?

See :h :cd and :h :lcd. :cd changes the current directory for all the windows while :lcd changes the current directory for the current window. You can change the current directory to the directory ...
statox's user avatar
  • 50.1k
10 votes
Accepted

Edit a directory inside Vim

I'm assuming you are using netrw here, as it's the default action when you do vim . or vim some/directory/. You can create a file/directory from netrw with the following commands: d : create a ...
nobe4's user avatar
  • 16.1k
9 votes
Accepted

Set current working directory when opening vim

As long as you're in an environment that uses the PWD environment variable then you can use that with the :cd command in a VimEnter autocommand. For example... augroup cdpwd autocmd! autocmd ...
B Layer's user avatar
  • 19.9k
7 votes
Accepted

Exclude folder when searching files in working directory

Try the following: set wildignore=*/node_modules/* I just played a little with wildignore, so I don't know if it works in all cases. E.g. if you do a :vimgrep /pattern/ node_modules/** It will ...
Ralf's user avatar
  • 9,257
6 votes
Accepted

How do you go back to your to global current directory after inheriting an lcd

As of vim 8.0.1489, one may use getcwd(-1) to retrieve the global directory. Thus, the following will work to restore a window to the global directory and cause it to forget its local directory (as ...
Mass's user avatar
  • 14.1k
5 votes
Accepted

autochdir working with :sp but not :e?

This appears to be an issue that was introduced in a patch that was picked up by Ubuntu 16.04 and fixed in another patch. Here's a link to the bug report. It was fixed in patch 1716 but, ...
Cliff Stanford's user avatar
5 votes
Accepted

VimScript - How do you get file/directory vim was called on from the command line?

If you want to get the directory of the first file in :argv (the filename arguments when vim was opened): let g:session_default_name = fnamemodify(argv()[0], ':p:h'). This will fail if vim was opened ...
Nate Bosch's user avatar
4 votes

Working directory different than current file directory?

As of vim8, mkview by default stores current directory for every buffer. You can find lcd <path> lines inside your views. To disable this: set viewoptions-=curdir
Evgenii Burmentev's user avatar
4 votes

How to set up NERDTree to CD to current folder when opening it for the first time via :NERDTreeFind

Use :set autochdir command to change the current directory. It will set the working directory as specific to the opened file.
Prakhil TP's user avatar
3 votes
Accepted

switch current directory between a base directory and current file directory

There are two separate issues in your code: In most situations, if you want to use the contents of a variable in a Vim command, you need to use :execute to achieve this. lcd w:baseCwd will attempt to ...
Rich's user avatar
  • 32.1k
3 votes

How do you go back to your to global current directory after inheriting an lcd

You can access the working directory of another window with the function getcwd(). So although this isn't the most convenient or robust solution, if your root project (with the global working ...
Rich's user avatar
  • 32.1k
3 votes

How to run internal Vim terminal at current file's dir?

Building on the other answers, in neovim, you can do: command! LocalTerm let s:term_dir=expand('%:p:h') | below new | call termopen([&shell], {'cwd': s:term_dir }) (this assumes that your shell ...
Thayne's user avatar
  • 131
3 votes

Highlight current line, but not for files inside certain dirs

I assume by "Highlight current line" that you're referring to the set cursorline option? Sounds like a job for autocmd's I'd do something like: autocmd BufEnter * call UnhighlightLine() function! ...
Tumbler41's user avatar
  • 7,756
3 votes

Edit a directory inside Vim

Totally a different angle, but it works without having to install any plugins ... When I want to create or rename a directory from a running Vim session, I'll simply type :! followed by the ...
Christopher Bottoms's user avatar
2 votes

Highlight current line, but not for files inside certain dirs

This is a job for autocmds. This works for me: " set by default set cursorline " unset for specific cases autocmd BufEnter ~/Work/my_rails_project_1/*,~/Work/my_rails_project_2/* setlocal ...
muru's user avatar
  • 25k
2 votes

autochdir working with :sp but not :e?

I added this to my .vimrc and now it works as desired: " Automatically set current directory to browsing directory. let g:netrw_keepdir=0 For ...
Timothy Stewart's user avatar
2 votes

How can I set the working directory for only the job_start() process?

In Build-Tool-Wrapper, I've used sh -c to actually run cd compdir && make args: " the a:cmd is managed elsewhere in the plugin " it may contain many things, usually things like " `cd ...
Luc Hermitte's user avatar
  • 17.4k
2 votes

Working directory different than current file directory?

In your vimrc put set autochdir and your path will always follow your current file. Otherwise vim will usually stay in either your home directory or in the first file you edited without you explicitly ...
Tumbler41's user avatar
  • 7,756
2 votes

How to tell command-t to ignore a specific directory

What's missing is the leading * in the wildignore value. command-t's help docs have an initially inscrutable, but actually helpful matrix of 'pattern'->'match' patterns, but the sort of buried lede ...
Marcos's user avatar
  • 121
2 votes

How do you go back to your to global current directory after inheriting an lcd

One way to find out the current global directory, in case there exists a window where we aren't using a current local directory could be to search for this window. For each tab, we could filter the ...
Luc Hermitte's user avatar
  • 17.4k
2 votes
Accepted

How to have getcwd() give path with ~ in place of home folder?

substitute(getcwd(),$HOME,'~','')
D. Ben Knoble's user avatar
  • 26.4k
2 votes

How to handle multiple directories in vim?

One handy keymapping I found years ago and have had in my vimrc ever since is: cnoremap %% <C-R>=fnameescape(expand("%:p:h")."/")<CR> It's a command-line mode mapping that expands %% to ...
8bittree's user avatar
  • 1,536
2 votes
Accepted

Is there a way to revert :lcd to the "global" path?

Is there any way to get the last "global" directory Yes, it's getcwd(-1). So it could be, for example :exe 'lcd' fnameescape(getcwd(-1))
Matt's user avatar
  • 20.8k
2 votes
Accepted

Is there a way to quickly navigate to previously visited directories

I've made a start at dirstack-like set of commands; you could place the following in (e.g.) ~/.vim/plugin/dirstack.vim: let g:dir_stack = [] command -complete=dir -nargs=1 -bang -bar Pushd \ ...
D. Ben Knoble's user avatar
  • 26.4k
2 votes
Accepted

How to let buffer show relative path when splitting?

When you do: :vsplit %:p:h/foo.bar Vim expands %:p:h to the full path of the directory containing the current file. This means that you give Vim the full path of foo.bar, which becomes the name of ...
romainl's user avatar
  • 41.1k
1 vote

Vundle keeps installing plugins to C:\Users\<user name> despite being told not to in .vimrc

There are many mistakes in your current configuration. I can't really tell why you're seeing the behavior you're currently seeing or why things are apparently working that weren't supposed to... ...
filbranden's user avatar
  • 28.9k

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