9

I have tried wiping my .vimrc, uninstalling all plugins, updating Vim, trying different shells, etc. but I absolutely can't get 'gx' to work over a given URL. I have used it before and it worked fine, it even use to open up my finder directory if I 'gx'ed on a blank line. I tried running 'gx' over numerous URLs, above them, below them, adding "/" at the end, etc. Still no luck. I am simply at my wits end trying to figure out why it no longer works when it use to. Sometimes it will open a URL in a blank buffer with the buffer name equal to the URL and other times nothing happens. I would be grateful to anyone who actually knew what the hell is going on with this stupid thing.

I am on the latest version of OS X and have the latest version of Vim.

UPDATE

I found the answer to this question but still am not quite sure why it worked and my original approach didn't.

Original Approach

I installed iTerm2 and was forced to set Preferences >Profiles >General >Command >Command >/usr/local/bin/zsh -l. Even though I ran $ chsh -s /usr/local/bin/zsh and added /usr/local/bin/zsh to /etc/shells, I could not get >Profiles >General >Command >Login (radio button) to work.

I would either get an error message in Terminal or the window would simply flash and disappear in iTerm. However, running my profile command /usr/local/bin/zsh -l in my mind should have forced the shell to run in login mode (the same mode as my default) but it caused major issues in vim where I couldn't get any shell command or function that relied on shell commands to work (e.g :!ls, gx).

ANSWER

Moreover, I finally managed to get everything working perfectly after running chsh -s /bin/bash (e.g. back to its default). Suddenly, I was able to run both Terminal and iTerm with the radio button for Login checked and all my issues went away. It should be noted that I tried to chsh -s /usr/local/bin/zsh and received an error that I didn't receive the first time--something about a non-standard login shell.

This wasn't good enough though because I really wanted to use my Homebrew zsh (and bash) shells since they are more current. Finally, I found the answer, I ran sudo dscl . change /users/$USER UserShell /bin/bash /opt/local/bin/zsh and I was then able to leave the Login radio button checked and actually use -zsh for the first time without any issues.

NOW MORE QUESTIONS

My questions now are: 1.) Why didn't my original profile command, /usr/local/bin/zsh -l work as though it was my default Login shell? Aren't they the same (e.g. a login shell is a login shell)? 2.) If I update /etc/shells with /usr/local/bin/zsh why would I receive a "non-standard shell error"? 3.) I read the MAN page on dscl but don't understand how that actually changed my Login shell when chsh -s /new/shell/path didn't work? 4.) Does ANYBODY really know what the heck is going on here?!

If you are a moderator please let me know if I should break these questions up into different posts but this is sort of a big issue and I can't believe I am the only one who has had this problem as I couldn't find ANY Q & As that thoroughly explained what is going on. Thank you all in advance for your help!

tommyc38
  • 703
  • 1
  • 8
  • 21
  • Total guess -- what is the value of `g:netrw_nogx`? – Ismail Badawi Dec 23 '15 at 21:11
  • Another guess, do you have `netrwFileHandlers.vim` available? and is it accessible to vim. For me it is in `/usr/share/vim/vim74/autoload/netrwFileHandlers.vim` and `gx` is working as expected – dvvrt Dec 24 '15 at 18:24
  • @IsmailBadawi I ran :g:netrw_nogx in command mode and it said Pattern not found. Let me know how I should check the value if this isn't correct. – tommyc38 Dec 24 '15 at 18:45
  • @dvvrt yes, I have the same file in the same location. – tommyc38 Dec 24 '15 at 18:51
  • I don't know the solution off hand, but a couple of things I can recommend to help troubleshoot. 1. Check vim startup log to see if netrw plug is loaded. `$vim -c 'quit' --startuptime startup.log && grep -ih netrw startup.log` which should show something like `399.537 001.674 001.674: sourcing /usr/share/vim/vim74/plugin/netrwPlugin.vim` 2. Check if the `g` + `x` key combination is being used by another application. 3. check if `g:netrw_browsex_viewer` is set to some value. `E121: Undefined variable: g:netrw_browsex_viewer` would mean that is it not set and default is being used – dvvrt Dec 27 '15 at 00:14
  • @dvvrt 1.) looked good 2.) I ran :map to look at my key mappings and see that gx is mapped to NetrwBrowseXVis in visual mode and NetrwBrowseX in normal mode. 3.) I ran :g:netrw_browsex_viewer and get an error "Pattern not found: netrw_brosex_viewer – tommyc38 Dec 30 '15 at 07:19
  • 1
    I also tried put 'let g:netrw_broswer_viewer='open' and it doesn't work. I should point out though that the window flashes when I hit 'gx' on top of a url. Moreover, I think this issue is related my shell because I can't run shell commands in Vim like everyone else. For example, If i run ':!ls' I get 'Cannot execut shell /usr/local/bin/zsh. If I run ':r !ls' I get the same output as before but also 'E485: Can't read file /path/to/temp/file'. I have also tried running this in bash and can't get it to work either. – tommyc38 Dec 30 '15 at 07:37
  • Lastly I have tried all of the above by opening a Vim session in the terminal by running 'vim -u NONE' so that it doesn't source any .vimrc files but still no luck. The more I think about it the more certain I am that this is a shell related issue since vim uses the shell to execute 'gx'. – tommyc38 Dec 30 '15 at 07:37

2 Answers2

1

I'm on OS X and running the following command in vim worked for me:

:let g:netrw_browser_viewer='open'

See also this similar answer for Fedora:

:let g:netrw_browsex_viewer="setsid xdg-open"
jtpereyda
  • 6,987
  • 10
  • 51
  • 80
1

I had the exact same problem, and it ended-up getting resolved (+quite a few bonuses) from this small but effective plugin:

https://github.com/stsewd/gx-extended.vim

Adds support for partial URLs, markdown URLs, 'Plugin' -> github paths, etc. It is much better behaved than netrw.

dougpa
  • 31
  • 3
  • Does this plugin also supports URI with page referencing e.g. `#page=10` at the end? Or in other words... Does it solve my problem [here](https://github.com/vim/vim/issues/7856)? – 71GA Nov 25 '21 at 10:59