Kartikey Tanna
Kartikey Tanna

Reputation: 1459

Regex in .vimrc throwing "Not an editor command"

I am trying to create a keybinding to delete all the commented lines in the file.

The following gives me the desirable result :g/^\(#\|$\)/d

I am declaring the binding as following in ~/.vimrc

nnoremap <leader>dcl :g/\v^(#|$)/d<cr>

It is throwing the following error:

E492: Not an editor command: $)/d<cr>

What is the proper way to declare a keybinding with regex?

Upvotes: 1

Views: 389

Answers (1)

yolenoyer
yolenoyer

Reputation: 9465

Replace your binding by:

nnoremap <leader>dcl :g/\v^(#<bar>$)/d<cr>

Indeed, in scripts or in the command line, vim considers | characters as a command delimiter; so you have to replace it by <bar>.

Upvotes: 8

Related Questions