I am using Homebrew Vim from MacOS Terminal. The problem I am having now is to copy in vim to System Clipboard. I follow the guide online, which told me to use "+y after selection texts in visual mode. However, when I hit the corresponding keys on "+y, the system responds with a sound indicating that such key combination is illegal. What am I doing wrong?
I did what is suggested. Here is what my dot file looks like:
set runtimepath+=~/.vim_runtime
source ~/.vim_runtime/vimrcs/basic.vim
source ~/.vim_runtime/vimrcs/filetypes.vim
source ~/.vim_runtime/vimrcs/plugins_config.vim
source ~/.vim_runtime/vimrcs/extended.vim
try
source ~/.vim_runtime/my_configs.vim
catch
endtry
" Define Key Mapping
inoremap jj <Esc>
set clipboard=unnamedplus
" Run Python file with one command
nnoremap <buffer> <C-M> :exec '!python' shellescape(#%, 1)<cr>
"YouCompleteMe virtual env config
let g:ycm_global_ycm_extra_conf = '~/.vim/.ycm_extra_conf.py'
Further, the :reg does not show the "+ or "* registry.
You can try with add the line:
set clipboard=unnamed
to your .vimrc ^1. For using + you might want to try with set clipboard=unnamedplus.
If you are not sure how to do this, just type in:
cd ~ && echo 'set clipboard=unnamedplus' >> .vimrc
See more information by :h clipboard-unnamedplus.
Notice that this this option works only in vim that is compiled with X11 & clipboard feature.
Regards
Related
I open Vim in "easy mode" with: vim -y
Is it possible to configure .vimrc to always open Vim in "easy mode" with just vim instead (without typing the -y)?
You can, since vim -y simply sets a number of options for that mode. It's possible to set those exact same options in the vimrc as well. They are shown in the vim documentation for evim (which is equivalent to vim -y), summarised below, see the link given for full detail:
These options are changed from their default value:
:set nocompatible insertmode hidden backup backspace=2
:set autoindent history=50 ruler incsearch mouse=a
:set hlsearch whichwrap+=<,>,[,] guioptions-=a
Key mappings changed:
<Down> <Up> Q <BS> CTRL-X <S-Del> CTRL-C <C-Insert> CTRL-V
<S-Insert> CTRL-Q CTRL-Z CTRL-Y <M-Space> CTRL-A <C-Tab> <C-F4>
Additionally:
- ":behave mswin" is used.
- syntax highlighting is enabled.
- filetype detection is enabled, filetype plugins and indenting is enabled.
- in a text file 'textwidth' is set to 78.
You can also have a look into the actual source file used for this mode if you do the following within a vim session:
:e $VIMRUNTIME/evim.vim
This shows the actual code run when starting with vim -y.
But I suspect an easier way to do it, at least with a UNIX-style OS, would be to just set up an alias, something like the following in your start-up scripts:
alias vim='/usr/bin/vim -y`
This would allow command-line invocations to start with easy mode. It won't help non-command-line invocations but you could do that (in UNIXes and Windows) by providing a script earlier in the path to do so.
For example, you could create a bash script of the form:
/usr/bin/vim -y "$#"
and call it vim, ensuring that where you put it comes in the path before /usr/bin.
I use VIM via termux with and faced with the following ploblem i can't to paste data from external clipboard inside VIM. I checked that my vim installation support pasting from external clipboard via following command
:echo has('clipboard')
#its return me 1 but when
# i trying to paste in vim
#via "+p or "*p or Ctrl V or Ctrl Shift V
It is't paste anything. What i am doing wrong. Is it possible that i can't to paste data which is in Android clipboard
I solved my problem. Vim package in termux have problems with recognizing android clipboard. If you faced with same problem do following.To access android clipboard via vim you should to install Termux-api that allow to accessing some android features than inside VIM type the following command
:r !termux-clipboard-get
You can add short-key mapping for it in .vimrc file just type
nnoremap <C-v> :r !termux-clipboard-get <CR>
Now i can use Ctrl V for paste in Vim
I sent bug report to termux github page that standart short-key "*p isn't working
Add the following in .vimrc
au TextYankPost * call system('termux-clipboard-set &', #")
function Paste(p)
let sysclip=system('termux-clipboard-get')
if sysclip != #"
let #"=sysclip
endif
return a:p
endfunction
noremap <expr> p Paste('p')
noremap <expr> P Paste('P')
This works for all copy, cut, and paste commands, including dw, 2p, etc.
The tutorial gives this example:
<leader>c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line.
But pressing \c$ or ,c$ in vim copies the current line and switched to insert mode.
I've installed the plugin via pathogen and :help nerdcommenter does work, but there's no mention of nerdcommenter in the output of :scripts, don't know if that means the plugin hasn't been successfully installed.
This looks fine. Here are some troubleshooting tips:
Check the :scriptnames output for .../plugin/NERD_commenter.vim; it needs to be there.
Check :echo loaded_nerd_comments
Check :echo g:NERDCreateDefaultMappings
Check :nmap <Leader>c
Do other mappings work? Define :nmap <Leader>x :echomsg "Works"<CR> and press \x.
If mappings don't work, you may have accidentally :set paste. Undo with :set nopaste.
I am trying to map the '-' key to move a line down
in my vimrc I have
noremap - :m .+1 <cr>
but the carriage return is ignored and displayed in the terminal as <cr>
After reading Vim ignores <cr> i tried adding an additional <cr> but that just echoes the characters twice.
So after pressing the '-' key I have to physically press the <enter> key to get the command to run.
I have tried this in mac and linux and get the same results.
It works if I set nocp.
I haven't come across any instructions that this must be set for <cr> to work.
So this is the issue.
set nocp is set if a vimrc is detected.
if you are testing a custom vimrc and starting vim with vim -u mycustomvimrc then despite the fact it is loading a vimrc file it does not set nocp and maintains backward compatibility. In such cases you need to set nocp explicitly.
Thanks for all the suggestions to get this resolved.
When I open Vim from a terminal, copy some text to the system clipboard, and exit Vim, the system clipboard gets cleared.
How to keep the copied text in the clipboard?
Synthesizing answers from superuser, just add the following to your .vimrc
autocmd VimLeave * call system("xsel -ib", getreg('+'))
Install Parcellite, or glipper for Gnome and klipper for KDE.
Restart your computer or run it manually.
see: https://wiki.ubuntu.com/ClipboardPersistence
Based on Matt's answer, the following uses xclip instead of xsel:
autocmd VimLeave * call system('echo ' . shellescape(getreg('+')) .
\ ' | xclip -selection clipboard')
I ran into this issue and a related problem where suspending vim with ctrl-z would also clear the clipboard. I've extended Matt's solution to fix both:
set clipboard=unnamedplus
if executable("xsel")
function! PreserveClipboard()
call system("xsel -ib", getreg('+'))
endfunction
function! PreserveClipboadAndSuspend()
call PreserveClipboard()
suspend
endfunction
autocmd VimLeave * call PreserveClipboard()
nnoremap <silent> <c-z> :call PreserveClipboadAndSuspend()<cr>
vnoremap <silent> <c-z> :<c-u>call PreserveClipboadAndSuspend()<cr>
endif
The if executable("xsel") guard is there to avoid errors if xsel is not installed. The nnoremap mapping preserves the clipboard when suspending from normal mode and the vnoremap mapping handles suspending from visual or select modes.
I've confirmed this works on vim 7.4 and 8.0.
Use NeoVim. It by default doesn't clear the clipboard on exit. You will still need to set clipboard=unnamedplus (typically in ~/.config/nvim/init.vim) and have xsel or xclip tools installed.
Keep in mind that some other defaults are different as well.
Please correct me if I'm wrong but from my understandings of Vim...
1) Vim uses registers instead of the clipboard to store copied/cut data.
2) These registers are preserved when exiting vim in a status file but are not accessible outside of the running process unless you manually open the file and inspect its contents
3) Saving stuff to the + registre while Vim runs allows you to paste to other applications.
4) By suspending vim (CTRL-Z) instead of closing it, these registers are still accessible.
Does that provide assistance?
Based on Matt's answer
When using his method copying multiple lines added slashes to the end of lines when pasting.
This should remedy that.
autocmd VimLeave * exe ":!echo " . shellescape(getreg('+')) . " | xclip -selection clipboard"
When i used "shellescape" with "system" newlines kept getting escaped. But that didn't happen when i used exe.
Don't know the real reason. but this worked.