Reputation: 38533
I need to remap C-x in Vim to behave like in some Windows editors:
Upvotes: 1
Views: 458
Reputation: 15264
" Source distribution script in $VIMRUNTIME directory
:runtime mswin.vim
if has('clipboard')
nmap <silent> <C-X> :call CutNonEmptyLineToClipboard()<CR>
" If the current line is non-empty cut it to the clipboard.
" Else do nothing.
function! CutNonEmptyLineToClipboard()
if strlen(getline('.')) != 0
normal 0"*D
endif
endfunction
endif
Updated version below. Had to google "black hole register", which I didn't know about. (Thanks!) I also put a different empty line matcher in. Pick the version that suits you best.
if has('clipboard')
nmap <silent> <C-X> :call CutNonEmptyLineToClipboard()<CR>
" If the current line is non-empty cut it out into the clipboard.
" Else delete it into the black hole register (named _).
function! CutNonEmptyLineToClipboard()
" Test if the current line is non-empty
" if strlen(getline('.')) != 0
if match(getline('.'), '^\s*$') == -1
normal 0"*D
else
normal "_dd
endif
endfunction
endif
Upvotes: 2