There are several Vim settings I love, but are too annoying to always enable. For example:
set relativenumber
- annoying when scrollingset list
- distracting when you don't need itWhat is a concise leader mapping to toggle a generic Vim setting?
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.
Try it out by pressing <leader>N in normal mode. Vim will toggle the line numbers for the current window off and on. Creating a "toggle" mapping like this is really handy, because we don't need to have two separate keys to turn something off and on. Unfortunately this only works for boolean options.
The leader key provides a facility for creating customized shortcuts that can be further restricted to apply only in certain modes, such as normal, insert, visual, terminal (neovim-specific), etc. The leader key is normally defined by the mapleader variable as \ . Many people like to redefine it to , .
<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.
You have two ways, as described in the help:
:set-! :set-inv :se[t] {option}! or :se[t] inv{option} Toggle option: Invert value. {not in Vi}
Either
:set list!
Or
:set invlist
Will do the same.
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