![](/img/trans.png)
[英]NERDTreeToggle opens a second tree of parent directory that stays open after toggle (neovim/nerdtree)
[英]Open neovim/nerdtree in directory given as argument
我正在將 Neovim 與 nerdtree 一起使用。 當使用目錄作為參數打開nvim
時,我想將它用作 neovim 和 nerdtree 的根目錄。 開箱即用,nerdtree 在該目錄中打開,但是一旦我打開一個文件,nerdtree 的根目錄就會變回 shell 的當前目錄。 我希望 nerdtree 將該目錄保留為根目錄。
我目前在我的.bashrc
使用以下解決方法:
nvim_cd()
{
if [ -d "${1}" ]; then
local dir="${1}"
shift 1
( cd "${dir}" && nvim "." "${@}" )
else
\nvim "${@}"
fi
}
alias nvim=nvim_cd
alias vim=nvim
這工作得很好,但我想知道:有沒有辦法在init.vim
實現這init.vim
?
請注意,在使用目錄作為參數調用nvim
的特定情況下,我只想在啟動期間更改根目錄,因此set autochdir
不是我要找的。
您可以通過 .bash_profile 或 .bahrc 中的這一行將您的 neovim 設為默認編輯器。
export EDITOR='nvim'
然后你可以使用這個腳本來指定一個目錄並通過 xargs 命令將其通過管道傳輸到 neovim。 您可以將此行作為別名或函數。
$HOME/your/path/to/dir/ | xargs -r -I % $EDITOR %;
您可能需要考慮查看我的功能來搜索文件或目錄,然后在 neovim 中打開它們。 挺有用的。。
function ds() {
find $HOME -type d -name "*" ! -path "*/.git*" ! -path # You can exclude directories by specifiying their names.
"*/__pycache__*" ! -path "*/venv*" 2>/dev/null | fzf | xargs -r -I % $EDITOR %;
}
此函數搜索您的目錄並將所選目錄作為參數通過管道傳輸到 neovim。 上述函數搜索您的主目錄。 您可能想考慮它可能會彈出一些不需要的目錄,例如庫或 .locals 文件夾。 因此,使用此功能僅搜索您的密碼。
function ds() {
find . -type d -name "*" ! -path "*/.git*" ! -path # You can exclude directories by specifiying their names.
"*/__pycache__*" ! -path "*/venv*" 2>/dev/null | fzf | xargs -r -I % $EDITOR %;
}
如何設置 NERDTree 更改為當前工作目錄?
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
這將自動切換您的 NERDTree 並匹配您當前的工作目錄。
如果您發現這個驚人的結帳,請查看我的 NeoVim 配置鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.