{
"$type": "site.standard.document",
"description": "The mvim script included with MacVim is useful for launching the MacVim app from the shell. Sure, you can run Neovim from the shell with nvim . but I",
"path": "/streamline-opening-neovim-from-the-shell/",
"publishedAt": "2024-02-26T11:34:00.000Z",
"site": "at://did:plc:bryys25pc2fnagnyxqgsglhd/site.standard.publication/3mn26bjkkmh23",
"tags": [
"Scripts",
"vim",
"macOS"
],
"textContent": "The mvim script (included with MacVim) is useful for launching the MacVim app from the shell. Sure, you can run Neovim from the shell with nvim. but I want it to launch my instance of [Neovim running in Alacritty]({% post_url 2024-02-17-double-click-file-in-macos-to-open-in-neovim %}).\n\nThis requires running nvim with --listen as described in the linked post above.\n\nI use fish shell so I have defined this in ~/.config/fish/functions/v.fish:\n\nfunction v\n if count $argv > /dev/null\n set -l filename $argv[1]\n # Expand the filename to its absolute path\n set -l absolute_path (realpath $filename)\n #echo \"Arguments provided: $argv\"\n #echo \"Absolute path: $absolute_path\"\n nvim --server ~/nvim-server.pipe --remote-send \"<ESC>:tabe $absolute_path<CR>\"`\n open -a Alacritty\n else\n set tempfile (mktemp)\n #echo \"file: $tempfile\"\n ansifilter > $tempfile\n nvim --server ~/nvim-server.pipe --remote-send \"<ESC>:tabe $tempfile<CR>\"`\n open -a Alacritty\n end\nend\n\nv accepts 2 types of input:\n\nFILENAME AS AN ARG\n\nIt lets me open a file in Neovim:\n\nv some-file-name-to-open\n\nSTDIN AUTOMATICALLY WRITTEN TO A TEMPORARY FILE AND OPENING THAT FILE\n\nPipe some contents to Neovim:\n\ncat some-file-with-contents | v\n\nPipe some contents to Neovim again:\n\necho \"hello world\" | v\n\nPiping is useful because I can do:\n\n$ curl https://dog.ceo/api/breeds/image/random | json_pp | v\n\nand get the output:\n\n{\n \"message\" : \"https://images.dog.ceo/breeds/mountain-bernese/n02107683_4907.jpg\",\n \"status\" : \"success\"\n}\n\nThis would be similar to piping it to nvim -, but again, using the v script handles STDIN automatically (so you don't need -) and it writes the contents to a temporary file and open it in my preferred Neovim instance.\n\nSee also: Fixing gx for Neovim with a Ruby Script.",
"title": "Streamline Opening Neovim from the Shell"
}