Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM :set list! as a toggle in .vimrc

Tags:

vim

Is there any way in my .vimrc file to use the command set list! with a keybind like F3 so it functions like this paste toggle set pastetoggle=<F2>.

like image 777
Max Rahm Avatar asked Sep 21 '12 16:09

Max Rahm


People also ask

What is vimrc in Linux?

Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.

What is silent in vimrc?

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

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.


2 Answers

You can put this in your .vimrc file:

" F3: Toggle list (display unprintable characters).
nnoremap <F3> :set list!<CR>
like image 106
Stephane Rouberol Avatar answered Sep 30 '22 16:09

Stephane Rouberol


I found an answer about how to toggle set number in vim, https://stackoverflow.com/a/762633/1086911

So can try the same way by putting following line into your vimrc file

map <F3> :set list! list? <CR>
like image 26
Derrick Zhang Avatar answered Sep 30 '22 18:09

Derrick Zhang