Here is my command: nnoremap <Leader>pwd :!pwd | tr -d '\n' | xclip<CR>

And I get error like this how to fix it? I havent found something useful to my issue

Error detected while processing BufWritePost Autocommands for "/home/li                                                                          │
│zhe/.config/nvim/init.vim"..script /home/lizhe/.config/nvim/init.vim:                                                                            │
│line  422:                                                                                                                                       │
│E488: Trailing characters: -d '\n':  tr -d '\n'  

I try to escape my command but not work either like: \-d \'\n\'


1 Answer 1


In a keybinding, you have to replace the vertical bars with <Bar>.

nnoremap <Leader>pwd :!pwd<Bar>tr -d '\n'<Bar>xclip<CR>

For explanation, see :h map-bar:

Since the '|' character is used to separate a map command from the next
command, you will have to do something special to include  a '|' in {rhs}.
There are three methods:
   use       works when                    example      ~
   <Bar>     always                        :map _l :!ls <Bar> more^M
   \|        'b' is not in 'cpoptions'     :map _l :!ls \| more^M
   ^V|       always                        :map _l :!ls ^V| more^M

(here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you
cannot use the <> notation "<C-V>" here).

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