How to make dd ignore empty lines but yank to system clipboard and delete non-empty lines in IdeaVim?

I'm trying to customise my .ideavimrc configuration to make the dd command smarter:

  • For empty lines: Delete without yanking (use black hole register)
  • For non-empty lines: Yank to system clipboard AND delete the line

I've tried several approaches but they don't seem to work properly in IdeaVim:

vim

" Attempt 1: Using <expr> (doesn't work in IdeaVim) 
nnoremap <expr> dd (getline('.') =~ '^\s*$' ? '"_' : '"+') . 'dd'

" Attempt 2: Using conditional (partial success) 
nnoremap dd :if getline('.') =~ '^\s*$'<Bar>normal! "_dd<Bar>else<Bar>normal! "+yydd<Bar>endif<CR>

The simple nnoremap dd "+yydd works for yanking to clipboard, but it also yanks empty lines which I want to avoid.

Is there a reliable way to achieve this behaviour in IdeaVim? Are Vim script functions supported, or is there a better approach?

Current setup:

  • JetBrains IntelliJ with IdeaVim plugin
  • Vim-surround and other standard IdeaVim plugins enabled

Any help would be appreciated!

0

Please sign in to leave a comment.