Roadside Picnic :::
  • Friends
  • About
  • Categories
  • Tags

>> Home / Posts / Computer

A Farewell to netrw pt2

Navigating back through cyberspace

I’ve written a much better solution to this than what PT1 ended with, this gives you relative pathing, and appears to be more robust against filenames with ‘annoying’ characters. It does require that your system has realpath installed, so in a shell make sure the following returns a version number:


$ realpath --version

Put This Line in vifmrc


"send to remote vim 
nnoremap R :!remoteVimSend.sh %f:p <cr>

Write the following in ~/Code/bash_scripts/remoteVimSend.sh


#!/bin/bash 

# enable debug 
#set -x 

# store vimserver's working directory 
vim_cwd=$(vim --remote-expr "getcwd()")

# I expect our filelist with spaces intact 
declare -a file_list=("$@")

# loop through args 
for i in "${file_list[@]}"
do
    # our relative path (if one exists)
    adj_path=$(realpath -e -q --relative-to="$vim_cwd" "$i")
    # check if not null or space
    if [ ! -z "$adj_path" -a "$adj_path" != " " ]; then 
        # build out arg command
        vim_args=(--remote-send "<C-\><C-N>:\$argadd $(printf '%q' "$adj_path") <CR><CR>")
        # run command 
        vim "${vim_args[@]}"
    fi
done 

Add the script’s location to your $PATH in your .bashrc


export PATH="/home/redrickSchuhart/Code/bash_scripts:$PATH"

As before; any selected files will be sent to your running vimserver and be silently appended to your existing arglist and buffer list, as well as leaving your cursor and window unchanged (with the exception of exiting whatever mode the user is currently in).

If any problems arise, uncomment #set -x to check the debug output of the bash script and tweak as needed.

∵ Redrick Schuhart ∴ 2025-12-16

  • Photo
  • Posts

  • Book
  • Computer
  • Sodas

RSS FEED | ATOM FEED | 2025 © Redrick Schuhart | No JavaScript used