1

I have mapped a key shortcut to copy all lines to system clipboard, which is working fine

 nnoremap <localleader>o :silent %w !pbcopy<cr>

I would like to display the message as 'Copied' in the status bar. Reading other answers, I found echom or echo can be used to display the messages

I have tried below

 nnoremap <localleader>o :silent %w !pbcopy<cr>|:echom "Copied"
 nnoremap <localleader>o :silent %w !pbcopy<cr>|echom "Copied"

These lines are placed in .vimrc. It appears lines are getting copied to clipboard, but the message is not being displayed anywhere.

1) How do I display the message from mapped command?

2) When opening a file, before Vim actually opens, I see the 'Copied' message, and a line that says 'Press Enter to continue' in the terminal. It appears the mapping is being invoked on sourcing the vimrc. The message should not be echoed while sourcing the vimrc file. How do I stop this?

1 Answer 1

1

Once you have run an ex command, you can immediately press : again to enter another one.

Similarly, after <CR>, you can follow up with :another command<CR> with no need for | or anything else in between.

nnoremap <localleader>o :silent %w !pbcopy<cr>:echom "Copied"<CR>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.