Skip to content

Commit 9f8799a

Browse files
committed
Support opening files at line numbers
1 parent abb0111 commit 9f8799a

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Fast Neovim with file explorer, fuzzy finder, LSP, git, and markdown preview.
1212
bash <(curl -fsSL ifaka.github.io/vimzap/i)
1313
```
1414

15-
Then use `v`, `vi`, or `vim` to open Neovim.
15+
Then use `v`, `vi`, or `vim` to open Neovim. `v path/to/file:80` opens that file at line 80.
1616

1717
## Keymaps
1818

i

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,28 @@ add_aliases() {
5959
local rc_file
6060
rc_file=$(get_shell_rc)
6161

62-
# Skip if already added
63-
if grep -q "$VIMZAP_MARKER" "$rc_file" 2>/dev/null; then
64-
return 0
65-
fi
62+
# Replace older VimZap alias blocks so updates get the latest shell helpers.
63+
remove_aliases >/dev/null 2>&1 || true
6664

6765
echo "" >> "$rc_file"
6866
echo "$VIMZAP_MARKER" >> "$rc_file"
69-
echo "alias v='nvim'" >> "$rc_file"
70-
echo "alias vi='nvim'" >> "$rc_file"
71-
echo "alias vim='nvim'" >> "$rc_file"
67+
cat >> "$rc_file" <<'EOF'
68+
v() {
69+
if [ "$#" -eq 1 ]; then
70+
_vimzap_target="${1%:*}"
71+
_vimzap_line="${1##*:}"
72+
if [ "$_vimzap_target" != "$1" ] && [ -n "$_vimzap_target" ] && [ -e "$_vimzap_target" ]; then
73+
case "$_vimzap_line" in
74+
""|*[!0-9]*) ;;
75+
*) nvim "+$_vimzap_line" "$_vimzap_target"; return ;;
76+
esac
77+
fi
78+
fi
79+
nvim "$@"
80+
}
81+
alias vi='nvim'
82+
alias vim='nvim'
83+
EOF
7284
echo "$VIMZAP_MARKER end" >> "$rc_file"
7385
}
7486

@@ -294,6 +306,12 @@ update() {
294306
done
295307
fi
296308

309+
# Update shell aliases/functions
310+
echo ""
311+
echo " Updating aliases..."
312+
add_aliases
313+
echo " Updated: $(get_shell_rc)"
314+
297315
# Summary
298316
echo ""
299317
echo " Summary"
@@ -471,13 +489,14 @@ main() {
471489
# Add shell aliases
472490
echo " [6/6] Setting up aliases..."
473491
add_aliases
474-
echo " v, vi, vim -> nvim"
492+
echo " v -> nvim (supports path:line), vi/vim -> nvim"
475493

476494
echo ""
477495
echo " Done! Run: source $(get_shell_rc)"
478496
echo ""
479497
echo " Usage:"
480498
echo " v Open Neovim (also vi, vim)"
499+
echo " v file:line Open file at line"
481500
echo " <Space> Show all commands"
482501
echo " <Space>e File explorer"
483502
echo " <Space>ff Find files"

0 commit comments

Comments
 (0)