I'm using Twitvim for the first time. Seeing all the URLs in there made me wonder, is there any way to open the URL under the cursor in your favorite browser or a specified one?
相关问题
- Emacs shell: save commit message
- How to change the first two uppercase characters o
- Insert text into current buffer from function
- Hot reload on save
- Substituting zero-width match in vim script
相关文章
- 如何让 vim 支持 .cshtml 文件的代码高亮
- Auto-save in VIM as you type
- How can I use gcc's -I command to add recursiv
- Vim: overloaded mapping for multiple modes
- How to use relative line numbering universally in
- How to copy the value of a vim option to a registe
- E185: Cannot find color scheme*
- How do I fix vim to properly indent folds containi
As described above by @kev, modified for Linux environments.
Aside: when this function was executed (Vim 8.1) in my terminal, the Vim screen was obfuscated (mostly "blanked;" i.e., the text was there but not visible). The
:redraw!
command (see https://stackoverflow.com/a/1117742/1904943) redraws the screen.Add to
~/.vimrc
:I'm pretty late to this party, but here's another way of doing this that works especially well on Windows 7.
Install both vim-shell and vim-misc in vim I recommend doing this via ever-awesome Pathogen plugin and then simply
cd ~/vimfiles/bundle & git clone git@github.com:xolox/vim-misc.git & git clone git@github.com:xolox/vim-shell.git
from msysgit. (These two plugins open urls in your default browser without creating any extra command prompts or other silly nonsense usually required in windows. You can open urls in Vim like this::Open http://duckduckgo.com
. Try it. You'll like it.)Create some vim mappings so that you can quickly get the line under the cursor into the browser. I'd map this to u (for me, that's
,u
from normal mode). Here's how:nnoremap u :exec "Open ".getline(".")
To use this mapping, type your Leader key from normal mode + u. It should read the line under your cursor and open it in your default browser.
Add following line to .vimrc file:
So in normal mode it pressing \ it selects current word and open it as address in web browser.
Leader by default is \ (but I've mapped it to , with
let mapleader = ","
). Similarly, using imap you can map some key sequence in insert mode (but then, if it is 2 key sequence, it probably will override some default behaviour).This is a sort of improved version of the script originally proposed by @tungd here https://stackoverflow.com/a/9459366/7631731. Keeps vim context and handles correctly URLS containing "#".
I use this script to search gooogle for
keyword
under cursor:You should use
getline('.')
andmatchstr()
to extract url under cursor. The rest is the same.Updated: from tpope's tweet today
Press
gx
. You can customize the browser. On Gnome and Mac OS X it's already usegnome-open
/open
. Generally you can setg:netrw_browsex_viewer
to anything you want.Original answer:
Don't remember where I get this function. There is a bug with hash (#) in the url, but the function works well enough that I won't bother fixing it.
Note: If you are not on the Mac, use
gnome-open
/xdg-open
for Linux, or 'path to your web browser' for Windows