Fix nvim :zz zoxide mapping to correctly change directory#903
Fix nvim :zz zoxide mapping to correctly change directory#903
Conversation
Replaced nanotee/zoxide.vim's :Zi mapping with fzf-lua's zoxide picker for the :zz command. This ensures that selecting a directory correctly triggers a directory change (cd), addressing the issue where it only displayed a list without navigating. - Removed nanotee/zoxide.vim from plugins/filer.lua - Added fzf-lua.zoxide mapping to :zz and <leader>z in plugins/fzf.lua
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the :zz command in Neovim failed to change directories correctly. By replacing the problematic zoxide.vim plugin with fzf-lua's built-in zoxide support, the configuration is simplified and the directory navigation functionality is restored to expected behavior. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
このプルリクエストでは、zoxide.vim プラグインを廃止し、fzf-lua を使用した zoxide 連携機能に移行しています。レビューでは、コマンドラインマッピング zz が他のコマンド入力を妨げる可能性への対策として、コマンドラインの先頭でのみ動作する条件付きマッピングへの改善が提案されています。また、プラグイン削除に伴い失われるディレクトリ移動の自動記録機能を補完するための DirChanged オートコマンドの活用についても指摘されています。
I am having trouble creating individual review comments. Click here to see my feedback.
dot_config/nvim/lua/plugins/fzf.lua (98-99)
cnoremap zz は、コマンドライン上のどの位置でも zz が入力されると発火するため、例えば :help zz や :!grep zz といった他のコマンドの入力を妨げる可能性があります。他のマッピングと同様に keymap ( vim.keymap.set ) を使用し、コマンドラインの先頭( : の直後)でのみ動作するように条件判定を追加することを推奨します。
-- :zz で zoxide を起動 (コマンドラインの先頭でのみ有効化)
keymap("c", "zz", function()
return (vim.fn.getcmdtype() == ":" and vim.fn.getcmdline() == "")
and "<C-u>lua require('fzf-lua').zoxide()<CR>"
or "zz"
end, { expr = true })
References
- 既存ユーザー環境を壊す変更(他のコマンド入力の妨げ)を優先して確認する方針に基づいています。 (link)
dot_config/nvim/lua/plugins/filer.lua (125-134)
zoxide.vim を削除したことで、vim.g.zoxide_hook = "pwd" による Vim 内でのディレクトリ移動( cd 等)を zoxide データベースに自動登録する機能が失われます。Vim での移動履歴も zoxide に反映させたい場合は、DirChanged オートコマンド等を利用して zoxide add を呼び出す設定を別途追加することを検討してください。
References
- 既存ユーザー環境を壊す変更(機能の消失)を優先して確認する方針に基づいています。 (link)
📝 WalkthroughWalkthroughこのプルリクエストではNeovimの設定におけるZoxideを使用したディレクトリ操作の実装を変更しています。従来の 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 12285323-3d2f-4a12-a310-a95229b55832
📒 Files selected for processing (2)
dot_config/nvim/lua/plugins/filer.luadot_config/nvim/lua/plugins/fzf.lua
💤 Files with no reviewable changes (1)
- dot_config/nvim/lua/plugins/filer.lua
| -- zoxideを使用してディレクトリ移動 | ||
| keymap("n", "<leader>z", fzf.zoxide, { noremap = true, silent = true, desc = "Zoxide ディレクトリ検索" }) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# _ZO_DATA_DIR の設定箇所を一覧化し、nvim 起動経路に確実に伝播するか確認する
rg -nP '_ZO_DATA_DIR' -C2Repository: ryo246912/dotfiles
Length of output: 1752
🏁 Script executed:
#!/bin/bash
# Check all shell startup files for _ZO_DATA_DIR export and zoxide initialization
echo "=== Checking shell startup files ==="
for file in dot_config/zsh/.zshenv dot_config/zsh/.zprofile dot_config/zsh/.zshrc dot_config/zsh/.zlogin; do
if [ -f "$file" ]; then
echo "--- $file ---"
rg -n '_ZO_DATA_DIR|zoxide' "$file" -A 2 -B 2
fi
doneRepository: ryo246912/dotfiles
Length of output: 99
🏁 Script executed:
#!/bin/bash
# Check if Neovim config references or handles environment variables related to zoxide
echo "=== Checking Neovim config for zoxide/env var handling ==="
rg -n 'zoxide|_ZO_DATA_DIR|os.getenv|os.environ' dot_config/nvim/ -A 2Repository: ryo246912/dotfiles
Length of output: 600
🏁 Script executed:
#!/bin/bash
# Check if there's any shell wrapper or launcher config for Neovim
echo "=== Checking for nvim launchers or wrappers ==="
fd -t f 'nvim' . --exclude=.git --exclude=node_modules | head -20
rg -l 'nvim|NEOVIM' --type sh --type bash . | head -10Repository: ryo246912/dotfiles
Length of output: 157
🏁 Script executed:
#!/bin/bash
# Find actual zsh configuration files
echo "=== Zsh config structure ==="
find dot_config/zsh -type f -name ".*" | head -20
ls -la dot_config/zsh/Repository: ryo246912/dotfiles
Length of output: 750
🏁 Script executed:
#!/bin/bash
# Check how mise.zsh gets sourced/initialized
echo "=== How mise.zsh is sourced ==="
rg -n 'mise.zsh|lazy' dot_config/zsh/ -t zshRepository: ryo246912/dotfiles
Length of output: 739
🏁 Script executed:
#!/bin/bash
# Look for main zsh init files that might not be in lazy directory
echo "=== All zsh files ==="
find dot_config/zsh -type f | xargs basename -a | sort | uniqRepository: ryo246912/dotfiles
Length of output: 300
🏁 Script executed:
#!/bin/bash
# Check the zshenv template and main zshrc for environment variable setup
echo "=== dot_zshenv.tmpl content ==="
cat -n dot_config/zsh/dot_zshenv.tmpl
echo ""
echo "=== dot_zshrc content ==="
cat -n dot_config/zsh/dot_zshrc
echo ""
echo "=== lazy.zsh content ==="
cat -n dot_config/zsh/lazy.zshRepository: ryo246912/dotfiles
Length of output: 6034
🏁 Script executed:
#!/bin/bash
# Check main.zsh which might source lazy files
echo "=== main.zsh content ==="
cat -n dot_config/zsh/main.zshRepository: ryo246912/dotfiles
Length of output: 1457
🏁 Script executed:
#!/bin/bash
# Check if zoxide has any special initialization or requirements in Neovim
echo "=== Check fzf-lua documentation or code for zoxide requirements ==="
rg -n 'zoxide' dot_config/nvim/ -B 3 -A 3
# Check if there's any mention of environment setup in Neovim config
echo ""
echo "=== Check for any shell integration or env setup in Neovim ==="
rg -n 'shell|env|spawn|system' dot_config/nvim/init.lua -i | head -20Repository: ryo246912/dotfiles
Length of output: 977
🏁 Script executed:
#!/bin/bash
# Verify: is _ZO_DATA_DIR needed in zshenv or is lazy loading sufficient?
# Check if mise.zsh is always sourced before zoxide is used
echo "=== When is zoxide actually used/called ==="
rg -rn 'zoxide|_ZO_DATA_DIR' dot_config/ --exclude-dir=nvim | grep -v 'Binary'
echo ""
echo "=== Check if there are any early uses of zoxide (before lazy loading) ==="
rg -n 'j ' dot_config/zsh/*.zsh | grep -v lazy | head -10Repository: ryo246912/dotfiles
Length of output: 615
<leader>z マッピングは適切です
fzf.zoxide 呼び出しは fzf-lua のネイティブピッカーで、選択後に cd を実行する仕様のため、PR 目的(選択後にディレクトリ変更されない問題の解消)と整合しています。
補足として、本リポジトリでは zoxide のデータディレクトリを ~/.local/state/zoxide にカスタマイズしており、_ZO_DATA_DIR は lazy ロード時の mise.zsh および tmux.conf で設定されています。ただし、zshenv では設定されていないため、GUI ランチャーなど shell 初期化が完全に実行されない環境から nvim を起動した場合、デフォルトの ~/.local/share/zoxide を参照する可能性があります。
| -- zoxideを使用してディレクトリ移動 | ||
| keymap("n", "<leader>z", fzf.zoxide, { noremap = true, silent = true, desc = "Zoxide ディレクトリ検索" }) | ||
| -- :zz で zoxide を起動 | ||
| vim.cmd("cnoremap zz <C-u>lua require('fzf-lua').zoxide()<CR>") |
There was a problem hiding this comment.
🧩 Analysis chain
🌐 Web query:
fzf-lua zoxide picker cd behavior and cnoreabbrev expr command alias pattern in Neovim
💡 Result:
In fzf-lua, the zoxide picker (:FzfLua zoxide) lists recent directories from zoxide query --list --score, formatted with scores excluded from fuzzy matching via fzf_opts --nth=2... . Default enter action is actions.cd, which extracts the directory path, optionally detects git root if enabled, then executes vim.cmd with "cd", "lcd", "tcd", or "tcd" based on zoxide.scope ("global" default for :cd, "local" for :lcd, "win" for :lcd, "tab" for :tcd). It also runs zoxide add to increment the score and prints confirmation. To create a Neovim command-line alias like "z" for :FzfLua zoxide using cnoreabbrev , use a pattern that checks command type and line start: cnoreabbrev z ((getcmdtype ==# ':' && getcmdline =~# '^z\s*$') ? 'FzfLua zoxide' : 'z') This expands ":z " to ":FzfLua zoxide " only when "z" is the full command followed by space/end, avoiding interference with other uses like ":Zz" or searches. More robust versions check getcmdpos <= len("z")+1 for beginning-of-line matching, as in common alias functions from Vim/Neovim configs.
Citations:
- 1: https://github.com/ibhagwan/fzf-lua
- 2: https://github.com/ibhagwan/fzf-lua/blob/d39620ba/doc/fzf-lua.txt
- 3: https://github.com/ibhagwan/fzf-lua/
- 4: https://github.com/ibhagwan/fzf-lua/blob/d39620ba/lua/fzf-lua/actions.lua
- 5: https://stackoverflow.com/questions/3878692/how-to-create-an-alias-for-a-command-in-vim
- 6: https://vi.stackexchange.com/questions/33220/make-cabbrev-work-from-command-line-but-not-search-prompt
- 7: https://github.com/monaqa/dotfiles/blob/424b0ab2d7623005f4b79544570b0f07a76e921a/.config/nvim/scripts/abbr.vim
cnoremap zz はコマンドライン中の zz 部分一致でも発火します
cnoremap はコマンドラインの「キー入力シーケンス」を置換するため、:zz 単体だけでなく zz を含む任意の入力(例::buzz、:e fizz.txt、:s/foo/zz/ など)でもマッピングが発動します。さらに <C-u> でコマンドラインが消去されるため、ユーザーが途中まで入力した別のコマンドが破壊される副作用があります。
:zz 専用のエイリアスにする場合は、cnoreabbrev <expr> でコマンドライン全体が zz のときだけ展開するのが安全かつ標準的です。
♻️ 提案(cnoreabbrev による厳密マッチ)
- vim.cmd("cnoremap zz <C-u>lua require('fzf-lua').zoxide()<CR>")
+ vim.cmd("cnoreabbrev <expr> zz (getcmdtype() == ':' && getcmdline() ==# 'zz') ? \"lua require('fzf-lua').zoxide()\" : 'zz'")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| vim.cmd("cnoremap zz <C-u>lua require('fzf-lua').zoxide()<CR>") | |
| vim.cmd("cnoreabbrev <expr> zz (getcmdtype() == ':' && getcmdline() ==# 'zz') ? \"lua require('fzf-lua').zoxide()\" : 'zz'") |
The user reported that :zz in Neovim was only listing directories but not changing to them. I investigated the configuration and found that zoxide.vim was used for :Zi (mapped to :zz), which seemed to have issues or was incomplete. Since fzf-lua is already used in the repository and has native zoxide support, I switched the mapping to use fzf-lua's zoxide picker, which correctly performs a 'cd' after selection. I also removed the now-redundant zoxide.vim plugin configuration.
PR created automatically by Jules for task 12308758324455625214 started by @ryo246912
変更内容概要
Neovim の
:zzコマンドと<leader>zキーマップを、zoxide.vim から fzf-lua の zoxide picker に置き換えました。<leader>z(ノーマルモード):fzf.zoxideを呼び出してディレクトリ検索:zz(コマンドラインモード):lua require('fzf-lua').zoxide()を実行変更理由
既存の zoxide.vim を使用した
:Ziコマンドは、ディレクトリのリストを表示するのみで、選択後にディレクトリが変わらない問題がありました。fzf-lua は既に導入済みであり、zoxide のネイティブサポートがあるため、同じ機能を zoxide.vim から fzf-lua に統一することで、選択後に自動的にディレクトリが変わる正常な動作を実現できます。確認した項目
<leader>zと:zzの 2 つのマッピングが新たに追加されていることを確認fzf-luaの zoxide picker を使用していることを確認