0

I'm new to VIM, using MacVim, and I'm trying to use Backslash as local leader. It seems like that is the default. If I do:

:let maplocalleader = "\\"

I just get a beep when I try to use local leader key \

If I do

:let maplocalleader = "-"

Then it works just fine. How do I get vim to stop beeping at me every time I try to use the backslash key?

newUserNameHere
  • 17,348
  • 18
  • 49
  • 79
  • backslash is default leader, you don't have to set it. – Kent Apr 19 '13 at 14:02
  • Yeah, I read that. But I'm not understanding why it's not working. The localleader command itself is working if the key is switched, but not by default, all I get is a beep. Any ideas? – newUserNameHere Apr 19 '13 at 14:10
  • How exactly are you trying to use it? Did you define a map using ``? – sidyll Apr 19 '13 at 16:16

2 Answers2

3

\\\ is definitely wrong way to escape backslash. Inside double quotes it should be written as "\\", inside single as '\'. "\\\" is an unfinished string '\"' (third backslash escapes double quote) thus it will show error after :let command.

The beep source is different: \ key on its own is no-op unlike -. If you have mapping to -a and type just - then cursor will move to the previous line: it is a valid action. If you have mapping \a (or no mappings at all) and type \ you will see beep because \ is not a valid action. Only mappings like \a are valid thus they won’t beep.

ZyX
  • 52,536
  • 7
  • 114
  • 135
0

You need to put that command in your vimrc. Leader and local leader commands to not affect commands that have already been parsed by vim.

FDinoff
  • 30,689
  • 5
  • 75
  • 96
  • From what I've read you have to use \\ and not just \ because \ is the escape character in Vimscript strings. So let maplocalleader = "\" is processed as let maplocalleader = "" – newUserNameHere Apr 19 '13 at 13:55
  • @user2229277 I realized what was happening with my original answer of `:let maplocalleader="\"`. This command errored and just used the default. Which just happens to be `\`. Can you try putting the command in your vimrc before plugins are loaded? – FDinoff Apr 19 '13 at 13:58
  • As Kent pointed out above the default leader is backslash. So I know I don't have to set it, I was just changing it to make sure it was working. When I keep it at the default of backslash, it just beeps at me. I'm unable to use that key and it's driving me nuts :/ – newUserNameHere Apr 19 '13 at 14:11
  • @newUserNameHere `let maplocalleader="\"` is processed similar to `let maplocalleader="`, not as `let maplocalleader=""`. If you escape quote (backslash does escape it) you will get unfinished string, not something else. – ZyX Apr 19 '13 at 17:21