0

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\'

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
lizhe
  • 137
  • 6

1 Answers1

5

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).

3N4N
  • 5,684
  • 18
  • 45