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.
Related
I can yank a visual selection into the X clipboard in vim using "+y - I would like to map this to something more convenient. I tried mapping to Ctrl-y by adding
:vmap <C-y> \"+y to my .vimrc but it doesn't work. How can I do this?
In ~/.vimrc add:
vnoremap <C-y> "+y<Esc>
or Ctrl-Shift-y:
vnoremap <C-S-y> "+y<Esc>
Make sure that your terminal does not already use that shortcut. For Gnome terminal see this.
Tip: if using default Gnome terminal shortcuts, paste that C-y yanked chars with: C-S-v in terminal or just C-v elsewhere.
The problem was that I was escaping the " character. This, it seems, is wrong in this context. simply:
:vmap <C-y> "+y
works, as expected.
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
I am looking for a way to automatically resize my open v-split panes in Vim after I call NERDTreeToggle.
I have NERDTreeToggle being called on the shortcut "ctrl+\" at the moment, and ideally what I want is to call the keyboard shortcut "ctrl+w =" immediately afterwards.
Any ideas? Thanks.
If this is your current mapping:
:nnoremap <C-\> :NERDTreeToggle<CR>
You can just append the window command after it:
:nnoremap <C-\> :NERDTreeToggle<CR><C-w>=
Alternatively, you can execute this from command-line mode as well, via :normal!:
:nnoremap <C-\> :NERDTreeToggle<Bar>execute "normal! \<lt>C-w>="<CR>
Note that for window commands, there's also a special :wincmd to invoke them:
:nnoremap <C-\> :NERDTreeToggle<Bar>wincmd =<CR>
I read this stack thread on how to save a mapping permanently in vim.
I went to /etc/vim/vimrc and added the :map ,k :!python % <enter> in the first line of the file. When I open a new python file with vim the command responds by showing :!python % <enter> at the bottom of the screen. But it doesn't execute automatically. How do I fix this command to execute 'enter' automatically?
i think you rather want to use a local version ~/.vimrc for local settings than editing global settings in the file /etc/vim/vimrc. There you can add:
let maplocalleader=","
map <localleader>k :!python %<cr>
i would advise to not use ^M as explained in ZyX comment to ghoti's answer see
Edit
ZyX' comment made me change the code above to
filetype plugin on
augroup ft_python
au!
au FileType python nnoremap ,k :!python %<cr>
augroup END
which keeps ,k from messing with other stuff
filetype plugin on says that we want to have things done if a file has a certain filetype - in our case python
augroup ft_python says i want to have a group of autocommands := "commands that are invoked when opening a file" with that group-name
au! removes all autocommands
au Filetype python declares an autocommand=au for all files of type python
augroup END leaves the group ft_python and goes back to general settings
so this makes it possible to have ,k act as 'compile' in python but when i accidentally press ,k in another file say a c-source code, it does nothing (or the things i told ,k to be for c-source code somewhere else in my .vimrc).
Put in a literal carriage return character instead - press Ctrl + V, then Enter when writing the map:
:map ,k :!python %^M
You'll see the carriage return shown as ^M after typing the sequence Ctrl + V, then press the enter key.
That Ctrl + V key tells vim to insert the next character that you type.
The answer I was looking for is to paste :map :!python % <enter> in ~/.vimrc
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.