Skip to main content
added 4 characters in body
Source Link
Sam
  • 1
  • 1

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>" )

The & 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 gxgx to run that function.

nnoremap gx :call OpenURL()<CR>

The <CR> is again to actually execute the command in Vim.

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>

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>" )

The & is used to open firefox in the background.

We put this into a function and then remap gx to run that function.

nnoremap gx :call OpenURL()<CR>

The <CR> is to actually execute the command in Vim.

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>

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>" )

The & 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>

The <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>
added 4 characters in body
Source Link
Sam
  • 1
  • 1

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

function!let OpenURLurl = expand('<cWORD>')
 

and then use bash to open firefox with the url as argument:

call feedkeys(':!bash firefox "' store. url in register a:
. ' &' . norm"\<CR>\<ESC>" 0"ayiW)
    let

The & is used to open firefox in the background.

We put this into a function and then remap gx to run that function.

nnoremap urlgx =:call @a
OpenURL()<CR>
 

The <CR> is to actually execute the command in Vim.

In total it looks like this:

function! OpenURL()
  " then openlet url in= firefox:expand('<cWORD>')
    call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
endfunction

nnoremap gx :call OpenURL()<CR>

I had the same problem, so I wrote my own function for it.

function! OpenURL()
    " store url in register a:
    norm 0"ayiW
    let url = @a

    " then open url in firefox:
    call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
endfunction

nnoremap gx :call OpenURL()<CR>

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>" )

The & is used to open firefox in the background.

We put this into a function and then remap gx to run that function.

nnoremap gx :call OpenURL()<CR>

The <CR> is to actually execute the command in Vim.

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>
added 4 characters in body
Source Link
Sam
  • 1
  • 1

I had the same problem, so I wrote my own function for it.

function! OpenURL()
    " store url in register a:
    norm 0"ayiW
    let url = @a 

    " then open url in firefox:
    call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
endfunction 

nnoremap gx :call OpenURL()<CR>

I had the same problem, so I wrote my own function for it.

function! OpenURL()
    " store url in register a:
    norm 0"ayiW
    let url = @a
    " then open url in firefox:
    call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
endfunction
nnoremap gx :call OpenURL()<CR>

I had the same problem, so I wrote my own function for it.

function! OpenURL()
    " store url in register a:
    norm 0"ayiW
    let url = @a 

    " then open url in firefox:
    call feedkeys(':!bash firefox ' . url . ' &' . "\<CR>\<ESC>" )
endfunction 

nnoremap gx :call OpenURL()<CR>
Source Link
Sam
  • 1
  • 1
Loading