19
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 :...
18
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
:...
17
votes
Accepted
change working directory to current opened file
:cd %:h
Explain:
:cd change directory Vim command
% - full path to current file
%:h - full path to current file without filename itself.
See :help expand and :help :cd for more information
14
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 $...
13
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 ...
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 ...
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 ...
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 ...
7
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 ...
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 ...
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, ...
4
votes
Accepted
How to change the directory to save a file
First of all wherever you open vim, you have access to the whole filesystem from within vim.
If you open vim without parameters or if you open a new buffer inside of vim with :new you can then save it ...
4
votes
Can't change directory to network drive
This was a bug, that was fixed in 7.4.096. (You didn't specify exact version, so I assume, you are using plain 7.4 version and I used to have the same problem when cding into a UNC path)
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.
4
votes
Accepted
CtrlP should never index particular directories
2 ways of doing that:
On your terminal, move to your project directory then execute vim.
Manually specify the working directory into vim using :cd command (You can check the current working directory ...
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
4
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 ...
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 ...
3
votes
How to change the directory to save a file
You could use
set autochdir
in the vimrc to make the working directory that of the current file. Apparently you need to be careful with this option and plugins.
3
votes
After changing lcd get parent directory of original file
Fugitive
If your project is under git's control then you use Fugitive.vim.
:echo fugitive#repo().tree()
To edit a file relative to the git root you an use :Gedit and a /:
:Gedit /tasks/mytask.js
...
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! ...
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 ...
3
votes
How to set up NERDTree to CD to current folder when opening it for the first time via :NERDTreeFind
Here is what I did in the end. Thanks to GitHub
function! NERDTreeToggleInCurDir()
" If NERDTree is open in the current buffer
if (exists("t:NERDTreeBufName") && bufwinnr(t:...
3
votes
How to set up NERDTree to CD to current folder when opening it for the first time via :NERDTreeFind
From the documention it would seem that it should be using your ~/Sites/project directory. (See :h :NERDTree)
:NERDTree [<start-directory> | <bookmark>] *:NERDTree*...
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 ...
2
votes
Accepted
Can't change directory to network drive
I solved this problem myself by using Haroogan vim. When I cd to h:\ in Haroogan vim it works, and it also successfully runs my vimrc files there.
I guess this was either something strange about my ...
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 ...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
working-directory × 38filesystem × 3
neovim × 2
vimrc × 1
vimscript × 1
search × 1
command-line × 1
gvim × 1
terminal × 1
autocmd × 1
autocompletion × 1
insert-mode × 1
microsoft-windows × 1
replace × 1
highlight × 1
netrw × 1
split × 1
statusline × 1
plugin-nerdtree × 1
variables × 1
error × 1
multiple-files × 1
invocation × 1
command × 1
plugin-fzf × 1