Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between ‘mapleader’ and ‘g:mapleader’ in Vim?

I don’t understand the difference between let mapleader="," and let g:mapleader=",". I know that g: means that it’s a global variable, but I don’t clearly understand the difference. Which one should I use in my .vimrc file?

like image 405
Gradient Avatar asked Jun 24 '12 06:06

Gradient


People also ask

What is Vim Mapleader?

Vim calls this "prefix" key the "leader". You can set your leader key to whatever you like. Run this command: :let mapleader = "-" You can replace - with any key you like. I personally like , even though it shadows a useful function, because it's very easy to type.

What is the default leader key in NVIM?

The "Leader key" is a way of extending the power of VIM's shortcuts by using sequences of keys to perform a command. The default leader key is backslash.

How do I map the leader key in Vim?

Use the mapleader variable in your . Now use the following to set the leader key. In the above example, I mapped the leader to , . This is much easier to access than \ , but you can map the leader to whatever key you'd like! For this change to take effect, you'll have to re-launch Vim.


1 Answers

If the aforementioned statements are both located outside of function definitions, they have the identical effect of setting a global variable. However, if the first statement, without the g: prefix, is used in a function body, it defines a variable local to that function. See :help internal-variables and especially :helpg In a function:.

Hence, outside function definitions one can access the global map-leader variable simply as mapleader.

like image 195
ib. Avatar answered Oct 25 '22 21:10

ib.