When I press gx over a link in vim, it opens it in an external application, when it does this it also suspends Vim.
How do I prevent it from suspending Vim, so that I can use Vim while browsing whatever it opened externally.
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.Sign up to join this community
Use vim-shell plugin instead with this config:
let g:netrw_nogx = 1 " disable netrw's gx mapping. nnoremap gx :Open<CR>
What works for me with neovim v0.2.2 on lubuntu 17.10 is the open-browser.vim plugin (https://github.com/tyru/open-browser.vim) with the following settings in my
let g:netrw_nogx = 1 " disable netrw's gx mapping. nmap gx <Plug>(openbrowser-smart-search) vmap gx <Plug>(openbrowser-smart-search)
I had the same problem, so I wrote my own function for it. (Thanks to the guy below who had a way to do it without having to use the registry. I modified my own with this.)
The strategy is to store the url under the Vim-cursor to a variable
let url = expand('<cWORD>')
and then use bash to open firefox with the url as argument:
call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
& is used to open firefox in the background, and the
\<CR>\<ESC> is to enter the command and escape the message box that it prompts.
We put this into a function that we call
OpenURL() and then remap
gx to run that function.
nnoremap gx :call OpenURL()<CR>
<CR> is again to actually execute the command.
In total it looks like this:
function! OpenURL() let url = expand('<cWORD>') call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" ) endfunction nnoremap gx :call OpenURL()<CR>