Leader Commands Not Working

Hi everyone,

I’m new to Neovim and I’m setting up my configuration for the first time. I’ve followed some guides and set up my init.lua file, but I’m running into issues with my leader key commands not working.

Here’s what I’ve done so far:

Set the Leader Key: I’ve defined the leader key as space in my init.lua file with the following line:

vim.g.mapleader = " "

Defined Key Mappings: I’ve added some key mappings using the leader key, like this:

 -- Example mapping to clear search highlights
     keymap.set("n", "<leader>nh", ":nohl<CR>", { desc = "Clear search highlights" })

Issues:
The leader key commands don’t seem to work. For example, when I enter commands like <leader>sh, Neovim goes into Insert mode and inserts h into the file.

following this article : How I Setup Neovim On My Mac To Make it AMAZING in 2024

I don’t have a solution but can only say that for me on nvim 0.10.1 using the exact same setting for vim.g.mapleader works fine. I suggest to disable all plugins and see if it is still a problem. Also, because you are a new user, please see this pinned post: Use https://github.com/neovim/neovim/discussions