Skip to content

Commit

Permalink
better support for neovim #203
Browse files Browse the repository at this point in the history
Call find_vim_executable() before find_vimpagerrc_files() and
read_vim_settings(), and use the found $tvim (terminal vim) in the
latter two functions instead of hardcoding `vim`.

This fixes properly finding ~/.config/nvim/init.vim if the user does not
have the ~/.vimrc symlink.

Also check for "$user_vimrc_dir/.vimpagerrc" etc. more carefully, by
making sure $user_vimrc_dir is set and quote "$vim_cmd" on invokation of
vim.

Also s/vim/(n)vim/g in the usage() text to make neovim compatibility
more explicit.
  • Loading branch information
rkitover committed Oct 17, 2016
1 parent 919848a commit 5299f55
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions vimpager
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ main() {

expand_config_vars

find_vim_executable

find_vimpagerrc_files

read_vim_settings

find_vim_executable

parse_pstree

# if no args, assume stdin
Expand Down Expand Up @@ -348,7 +348,7 @@ find_vimpagerrc_files() {
OLDIFS=$IFS
IFS='
'
for var in $(vim -NEnR -i NONE ${vimrc:+-u "$vimrc"} +'call writefile(["", "VAL:" . $VIM, "VAL:" . $MYVIMRC], "/dev/stderr")' +q </dev/tty 2>&1 >/dev/null); do
for var in $("$tvim" -NEnR -i NONE ${vimrc:+-u "$vimrc"} +'call writefile(["", "VAL:" . $VIM, "VAL:" . $MYVIMRC], "/dev/stderr")' +q </dev/tty 2>&1 >/dev/null); do
case "$var" in
VAL:*)
case $i in
Expand All @@ -368,7 +368,7 @@ find_vimpagerrc_files() {
IFS=$OLDIFS

# find system vimrc
system_vimrc=$(vim --version | sed -n '/system vimrc file: "/{
system_vimrc=$("$tvim" --version | sed -n '/system vimrc file: "/{
s|\$VIM|'"$vim_dir"'|
s/.*: "\([^"]*\).*/\1/p
q
Expand All @@ -381,11 +381,11 @@ find_vimpagerrc_files() {
elif [ -n "$VIMPAGER_RC" ]; then
vimrc=$VIMPAGER_RC
# check for vimpagerrc in same dir as vimrc in case it is set in VIMINIT
elif [ -r "$user_vimrc_dir/.vimpagerrc" ]; then
elif [ -n "$user_vimrc_dir" -a -r "$user_vimrc_dir/.vimpagerrc" ]; then
vimrc=$user_vimrc_dir/.vimpagerrc
elif [ -r "$user_vimrc_dir/_vimpagerrc" ]; then
elif [ -n "$user_vimrc_dir" -a -r "$user_vimrc_dir/_vimpagerrc" ]; then
vimrc=$user_vimrc_dir/_vimpagerrc
elif [ -r "$user_vimrc_dir/vimpagerrc" ]; then
elif [ -n "$user_vimrc_dir" -a -r "$user_vimrc_dir/vimpagerrc" ]; then
vimrc=$user_vimrc_dir/vimpagerrc
# check standard paths, according to :h initialization
elif [ -r ~/.vimpagerrc ]; then
Expand Down Expand Up @@ -420,7 +420,7 @@ read_vim_settings() {
OLDIFS=$IFS
IFS='
'
for var in $(vim -NEnR -u "$vimrc" -i NONE --cmd 'let g:vimpager = { "enabled": 1 }' +'
for var in $("$tvim" -NEnR -u "$vimrc" -i NONE --cmd 'let g:vimpager = { "enabled": 1 }' +'
if !exists("g:vimpager.gvim")
if !exists("g:vimpager_use_gvim")
let g:vimpager.gvim = 0
Expand Down Expand Up @@ -617,7 +617,7 @@ quit() {
usage() {
cat <<'EOF'
Usage: vimpager [OPTION]... [FILE | -]...
Display [1;35mFILE[0m(s) in vim with a pager emulating less.
Display [1;35mFILE[0m(s) in (n)vim with a pager emulating less.
With no FILE, or when FILE is -, read standard input.
Expand All @@ -626,8 +626,8 @@ With no FILE, or when FILE is -, read standard
+G, + Go to the end of the file.
-N, --LINE-NUMBERS Show line numbers.
-s Squeeze multiple blank lines into one.
[1;37m--cmd [1;35mCOMMAND[0m Run vim [1;35mCOMMAND[0m before initialization.
[1;37m-c [1;35mCOMMAND[0m Run vim [1;35mCOMMAND[0m after initialization.
[1;37m--cmd [1;35mCOMMAND[0m Run (n)vim [1;35mCOMMAND[0m before initialization.
[1;37m-c [1;35mCOMMAND[0m Run (n)vim [1;35mCOMMAND[0m after initialization.
-u FILE Use FILE as the vimrc.
-x  Give debugging output on stderr.
Expand Down Expand Up @@ -811,7 +811,7 @@ page_files() {

init_opts="'columns': $cols, 'tmp_dir': '$tmp', 'line_numbers': ${line_numbers:-0}, 'is_doc': ${is_doc:-0}, 'runtime': '$runtime'"

$vim_cmd -N -i NONE \
"$vim_cmd" -N -i NONE \
$vim_options \
--cmd "set rtp^=$runtime" \
--cmd "call vimpager#Init({ $init_opts })" \
Expand Down

0 comments on commit 5299f55

Please sign in to comment.