Pasting Text Into Vim
stackoverflow.com
stackoverflow.com
While the top voted answer is very complete, I prefer editing the command history.
In normal mode, type:
q:
This will give you a list of recent commands, editable and searchable with normal vim commands. You'll start on a blank command line at the bottom.For the exact thing that the article asks, pasting a yanked line (or yanked anything) into a command line, yank your text and then:
q:p
(get into command history edit mode, and then (p)ut your yanked text into a new command line. Edit at will, enter to execute.To get out of command history mode, it's the opposite. In normal mode in command history, type:
:q<enter> q/ - Search string history
q: - Ex cmdline history
q? - Search string history
Also note that if you normally use Ctrl-C to exit Insert mode, that fails here as Ctrl-C will close the history buffer. You need to use Escape or Ctrl-[.:%s/
and when you realise it's not as simple as you first thought.. doing ^f will take you "command line" buffer where you can do all the normal vim commands..
as for copy/paste .. if your vim is compiled with the option "+clipboard" then you can use the "+" register to interact with all your system copy/pasting..
however, what I most frequently end up doing is entering paste mode (:set paste) and just using my terminal emulator's paste buffer.. you can also sync these using tmux's buffers etc if you want, but it's a little less elegant imo..
once you have set/unset paste mode aliased to something sensible it makes the whole process as simple as it gets imo
for your vimrc
nmap <silent> <leader>p :set invpaste<CR>:set paste?<CR>
Do you have any idea how many tutorials there are out there that involve some kind of obscure plugin or xclip incantation for something as simple as pasting text over ssh with formatting?
To think all I needed to do was :set paste... Extraordinary.
You can leave command history just by typing <enter>, not :q<enter>.
It is about the more meta activity of pasting text (e.g. representing a vim command or an argument to a vim command) into the vim command line.
Life is suddenly easier :)
set pastetoggle=<Esc>[201~
noremap <Esc>[200~ :set paste<cr>0i
inoremap <Esc>[200~ <c-o>:set paste<cr>
cnoremap <special> <Esc>[200~ <nop>
cnoremap <special> <Esc>[201~ <nop>
let &t_ti="\<esc>[?2004h"
let &t_te="\<esc>[?2004l"
the ti/te sequences are passed from Vim to the client which tells Putty (and others) to bracket all pasting with \e[200~ and \e[201~. The other commands handle these sequences to make pasting happen transparently without having to hit F2 ;o)
[1]: http://www.gnu.org/software/emacs/manual/html_node/emacs/Reg...
I personally find this extremely useful--I use it far more than any other register-based feature. Of course I effectively use Emacs as my window manager for everything except web browsing, ergo I am certifiably insane.
And if ezbl or a similar project ever matures, I might start browsing from Emacs too :P.
"+y
Took me a year or so to learn that one set clipboard+=unnamedI've been using the "+ register intensively. Your tip will save me from quite a lot of keystrokes in the future.
:help clipboard
Also another AWESOME tip , if you set an "a" among your guioptions, your visual selects and mouse selects automatically get copied to the * register. : help quotestar
I realize that X environments mainly do this already, but not the visual select. Most of my editing is through SSH so I don't get to use the gui features much. The only time I use gvim is in windows, so it was pretty revolutionary for me.I believe the special + register for the system clipboard is enabled by a compile option, but that may not be entirely accurate. I have Vim 7.3 installed via Macports and it works for me.
[MacVim]: http://code.google.com/p/macvim/
brew install macvim --override-system-vim
to see if things improve.EDIT: it works.
pbcopy = xsel -bi
pbpaste = xsel -b C-r-w
Handy for renaming variables with :%s/oldname/newname/g, for example.Will solve your copy and paste problems across all UNIX applications.
Thank you Mr. Marriott. Great software.
(but you are right, tmux is great)