Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leader mapping to toggle a vim setting

Tags:

There are several Vim settings I love, but are too annoying to always enable. For example:

  • set relativenumber - annoying when scrolling
  • set list - distracting when you don't need it

What is a concise leader mapping to toggle a generic Vim setting?

like image 256
Natan Yellin Avatar asked Aug 26 '11 14:08

Natan Yellin


People also ask

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.

How do I toggle in 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.

What is a leader vim?

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 , .

What is vim silent?

<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.


1 Answers

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.

like image 157
sidyll Avatar answered Sep 30 '22 20:09

sidyll