How to paste text from Vim editor to browser?

36,056

Solution 1

Either

  1. Select the text without pressing a shortcut key and middle-click in the browser window, or
  2. Select the text, press shift-ctrl-c and then use ctrl-v to paste, or
  3. I'm not entirely sure what vim has to do with sql files and what these sql files are (sqlite?), but maybe you have to use vim because the environment variable EDITOR is set to vim; maybe you could do whatever you do by setting

    export EDITOR=gedit
    

    before starting whatever program you start to edit the sql files.

Solution 2

Use "+y to yank the selected text to your Ctrl-V clipboard ("*y would be middle mouse button)

More on registers in Vim

Solution 3

  1. Select the text you want to copy using Visual Mode in Vim editor. v enters visual mode and selects the character at cursor location. Shift-v selects the entire line.

  2. In Vim, Copying is done using the y or "yanking". To copy selected text to system clipboard type "+y in Normal Mode. Now you can paste it anywhere else using Ctrl-v.

  3. To copy text from outside applications into Vim editor, first copy the text using the usual Ctrl-C command then go to Vim editor and type "+p in Normal Mode.

  4. I find the above commands very tedious to type every time I copy-paste from outside Vim, so I mapped the Ctrl-y to copy and the Ctrl-p to paste in Vim. Now I don't have to type "+y and "+p every time.

Add these to your .vimrc file:

nnoremap <C-y > "+y vnoremap <C-y> "+y nnoremap <C-p> "+p vnoremap <C-p> "+p

Edit: Before following the above steps,check vim --verison.Vim must have +xterm_clipboard feature installed for the above method to work. If not , then run sudo apt-get install vim-gtk to get the necessary packages.

Solution 4

you could simply use the mouse (right-click+copy) and (rightclick+Paste)

Solution 5

  1. Select the text using mouse
  2. Ctrl-Shift-C (Note the Shift)
  3. Switch to the new window where you want to paste
  4. Ctrl-V
Share:
36,056

Related videos on Youtube

Harshal Kshatriya
Author by

Harshal Kshatriya

Updated on September 18, 2022

Comments

  • Harshal Kshatriya
    Harshal Kshatriya about 1 year

    I need to copy text from vim to web browser since I'm not able to use gedit as I'm opening an sql file. How do I get this done?

    • Harshal Kshatriya
      Harshal Kshatriya about 11 years
      I need to copy text from a file opened in vim editor into a multiline textbox on a webpage in firefox.
    • chris.ritsen
      chris.ritsen about 11 years
      I wrote this in vim and then copied it to this textbox by doing the following: select the text with shift+v, then press "+y to yank to the system clipboard. Vim's clipboard setting is currently the default, which for me is clipboard=autoselect,exclude:cons\|linux. This yanks to xclip, so xclip -o on the command line should show whatever was copied. Then simply ctrl+v into the textbox.
  • nanofarad
    nanofarad about 11 years
    SQL files are just text files containing SQL commands in ASCII or UTF-8. They generally have no special characters other than math symbols, parentheses, or quotes.
  • January
    January about 11 years
    Yes. Except when they aren't, for example when they are sqlite3 files. Yes, some programs do that. In any case, that does not explain why the OP can't use gedit for them.
  • nanofarad
    nanofarad about 11 years
    SQLite files don't carry this file extension nor are they called SQL files.
  • January
    January about 11 years
    @ObsessiveFOSS You should have written "SQLite files should not carry this file extension"
  • Eliah Kagan
    Eliah Kagan about 11 years
    The EDITOR environment variable is often assumed to hold the name of an editor that can run without a GUI. For an editor like gedit, it's usually best to set the VISUAL environment variable instead. When a graphical editor can be used, VISUAL is usually consulted before EDITOR. Usually.
  • sks
    sks over 10 years
    To use "+y, you have to check X11-clipboard support first. This post explained how in detail.
  • SY_13
    SY_13 almost 7 years
    Note: This is an unrelated question but does anyone know what the <C means in Markdown. I tried entering the above code in a block quote but the <C-y> kept disappearing from the code block.
  • SY_13
    SY_13 almost 7 years
    The idea behind Vim is to not leave the Home Row of the Keyboard when you are typing. If you are still using the mouse then I don't see what benefit you can get out of using VIM.
  • notalentgeek
    notalentgeek about 5 years
    I use Vim to edit SSH-ed code in remote. Yet I use VSCode to develop my application.