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?
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.
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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With