show illegal whitespace (such as unbreakable space) in source code
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
I sometimes type (by accident) shift-space, inserting unbreakable space into code. With c++, I get this:
error: stray ‘302’ in program
error: stray ‘240’ in program
while in other formats (like RestructuredText), I am hunting mysterious errors of syntax without any visible cause.
Is there a way to
- always highlight unbreakable spaces (and perhaps other type of "illegal" whitespace, i.e. any whitespace besides space and tab)
- map shift-space to space, so that these characters are not inserted in the first place?
Thanks!
key-bindings highlight unicode
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
I sometimes type (by accident) shift-space, inserting unbreakable space into code. With c++, I get this:
error: stray ‘302’ in program
error: stray ‘240’ in program
while in other formats (like RestructuredText), I am hunting mysterious errors of syntax without any visible cause.
Is there a way to
- always highlight unbreakable spaces (and perhaps other type of "illegal" whitespace, i.e. any whitespace besides space and tab)
- map shift-space to space, so that these characters are not inserted in the first place?
Thanks!
key-bindings highlight unicode
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I sometimes type (by accident) shift-space, inserting unbreakable space into code. With c++, I get this:
error: stray ‘302’ in program
error: stray ‘240’ in program
while in other formats (like RestructuredText), I am hunting mysterious errors of syntax without any visible cause.
Is there a way to
- always highlight unbreakable spaces (and perhaps other type of "illegal" whitespace, i.e. any whitespace besides space and tab)
- map shift-space to space, so that these characters are not inserted in the first place?
Thanks!
key-bindings highlight unicode
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I sometimes type (by accident) shift-space, inserting unbreakable space into code. With c++, I get this:
error: stray ‘302’ in program
error: stray ‘240’ in program
while in other formats (like RestructuredText), I am hunting mysterious errors of syntax without any visible cause.
Is there a way to
- always highlight unbreakable spaces (and perhaps other type of "illegal" whitespace, i.e. any whitespace besides space and tab)
- map shift-space to space, so that these characters are not inserted in the first place?
Thanks!
key-bindings highlight unicode
key-bindings highlight unicode
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 3 hours ago
eudoxos
1083
1083
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
eudoxos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
2
down vote
accepted
I do have this in my custom vimrc file, which highlights git conflict markers as well as special whitespace characters.
" highlight VCS conflict markers
" highlight strange Whitespace
aug CustomHighlighting
au!
au WinEnter * if !exists("w:custom_hi1") | let w:custom_hi1 = matchadd('ErrorMsg', '^(<|=|>)7([^=].+)?$') | endif
au WinEnter * if !exists("w:custom_hi2") | let w:custom_hi2 = matchadd('ErrorMsg', '[x0bx0cu00a0u1680u180eu2000-u200au2028u202fu205fu3000ufeff]') | endif
aug END
kudos to Benjamin Haskell via the vim_use mailinglist
add a comment |Â
up vote
2
down vote
You can use
:syntax match ErrorMsg " "
while inserting an unbreakable space between the "
's.
To automatically load the rule, you can simply add
au VimEnter,BufWinEnter * syn match ErrorMsg " "
to your .vimrc
.
If you want to customize the highlighting, create a custom rule before the syn match
, i.e.
highlight UnbreakableSpace ctermbg=red guibg=red
au VimEnter,BufWinEnter * syn match UnbreakableSpace " "
add a comment |Â
up vote
2
down vote
I don't think you can use the <S-Space>
notation in a mapping* but I think you should be able to map it by pressing Shift+Space when typing in the mapping where I've written [lhs]
below:
:inoremap [lhs] <Space>
Of course, when reading your .vimrc
, this will be a bit confusing, so you might be better off using an :execute
command and Vim's notation for adding Unicode characters to a string:
execute "inoremap u00A0 <Space>"
(N.B. I'm not entirely sure which character you are inserting when you press Shift+Space: you may need to adjust the Unicode value accordingly.)
* I think that the keystrokes are probably converted in your terminal and never make it to Vim. So Vim only sees the unbreakable space: it doesn't know you pressed Shift+Space
.
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
I do have this in my custom vimrc file, which highlights git conflict markers as well as special whitespace characters.
" highlight VCS conflict markers
" highlight strange Whitespace
aug CustomHighlighting
au!
au WinEnter * if !exists("w:custom_hi1") | let w:custom_hi1 = matchadd('ErrorMsg', '^(<|=|>)7([^=].+)?$') | endif
au WinEnter * if !exists("w:custom_hi2") | let w:custom_hi2 = matchadd('ErrorMsg', '[x0bx0cu00a0u1680u180eu2000-u200au2028u202fu205fu3000ufeff]') | endif
aug END
kudos to Benjamin Haskell via the vim_use mailinglist
add a comment |Â
up vote
2
down vote
accepted
I do have this in my custom vimrc file, which highlights git conflict markers as well as special whitespace characters.
" highlight VCS conflict markers
" highlight strange Whitespace
aug CustomHighlighting
au!
au WinEnter * if !exists("w:custom_hi1") | let w:custom_hi1 = matchadd('ErrorMsg', '^(<|=|>)7([^=].+)?$') | endif
au WinEnter * if !exists("w:custom_hi2") | let w:custom_hi2 = matchadd('ErrorMsg', '[x0bx0cu00a0u1680u180eu2000-u200au2028u202fu205fu3000ufeff]') | endif
aug END
kudos to Benjamin Haskell via the vim_use mailinglist
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
I do have this in my custom vimrc file, which highlights git conflict markers as well as special whitespace characters.
" highlight VCS conflict markers
" highlight strange Whitespace
aug CustomHighlighting
au!
au WinEnter * if !exists("w:custom_hi1") | let w:custom_hi1 = matchadd('ErrorMsg', '^(<|=|>)7([^=].+)?$') | endif
au WinEnter * if !exists("w:custom_hi2") | let w:custom_hi2 = matchadd('ErrorMsg', '[x0bx0cu00a0u1680u180eu2000-u200au2028u202fu205fu3000ufeff]') | endif
aug END
kudos to Benjamin Haskell via the vim_use mailinglist
I do have this in my custom vimrc file, which highlights git conflict markers as well as special whitespace characters.
" highlight VCS conflict markers
" highlight strange Whitespace
aug CustomHighlighting
au!
au WinEnter * if !exists("w:custom_hi1") | let w:custom_hi1 = matchadd('ErrorMsg', '^(<|=|>)7([^=].+)?$') | endif
au WinEnter * if !exists("w:custom_hi2") | let w:custom_hi2 = matchadd('ErrorMsg', '[x0bx0cu00a0u1680u180eu2000-u200au2028u202fu205fu3000ufeff]') | endif
aug END
kudos to Benjamin Haskell via the vim_use mailinglist
answered 3 hours ago


Christian Brabandt
14.5k2443
14.5k2443
add a comment |Â
add a comment |Â
up vote
2
down vote
You can use
:syntax match ErrorMsg " "
while inserting an unbreakable space between the "
's.
To automatically load the rule, you can simply add
au VimEnter,BufWinEnter * syn match ErrorMsg " "
to your .vimrc
.
If you want to customize the highlighting, create a custom rule before the syn match
, i.e.
highlight UnbreakableSpace ctermbg=red guibg=red
au VimEnter,BufWinEnter * syn match UnbreakableSpace " "
add a comment |Â
up vote
2
down vote
You can use
:syntax match ErrorMsg " "
while inserting an unbreakable space between the "
's.
To automatically load the rule, you can simply add
au VimEnter,BufWinEnter * syn match ErrorMsg " "
to your .vimrc
.
If you want to customize the highlighting, create a custom rule before the syn match
, i.e.
highlight UnbreakableSpace ctermbg=red guibg=red
au VimEnter,BufWinEnter * syn match UnbreakableSpace " "
add a comment |Â
up vote
2
down vote
up vote
2
down vote
You can use
:syntax match ErrorMsg " "
while inserting an unbreakable space between the "
's.
To automatically load the rule, you can simply add
au VimEnter,BufWinEnter * syn match ErrorMsg " "
to your .vimrc
.
If you want to customize the highlighting, create a custom rule before the syn match
, i.e.
highlight UnbreakableSpace ctermbg=red guibg=red
au VimEnter,BufWinEnter * syn match UnbreakableSpace " "
You can use
:syntax match ErrorMsg " "
while inserting an unbreakable space between the "
's.
To automatically load the rule, you can simply add
au VimEnter,BufWinEnter * syn match ErrorMsg " "
to your .vimrc
.
If you want to customize the highlighting, create a custom rule before the syn match
, i.e.
highlight UnbreakableSpace ctermbg=red guibg=red
au VimEnter,BufWinEnter * syn match UnbreakableSpace " "
answered 3 hours ago
Mr Shunz
1862
1862
add a comment |Â
add a comment |Â
up vote
2
down vote
I don't think you can use the <S-Space>
notation in a mapping* but I think you should be able to map it by pressing Shift+Space when typing in the mapping where I've written [lhs]
below:
:inoremap [lhs] <Space>
Of course, when reading your .vimrc
, this will be a bit confusing, so you might be better off using an :execute
command and Vim's notation for adding Unicode characters to a string:
execute "inoremap u00A0 <Space>"
(N.B. I'm not entirely sure which character you are inserting when you press Shift+Space: you may need to adjust the Unicode value accordingly.)
* I think that the keystrokes are probably converted in your terminal and never make it to Vim. So Vim only sees the unbreakable space: it doesn't know you pressed Shift+Space
.
add a comment |Â
up vote
2
down vote
I don't think you can use the <S-Space>
notation in a mapping* but I think you should be able to map it by pressing Shift+Space when typing in the mapping where I've written [lhs]
below:
:inoremap [lhs] <Space>
Of course, when reading your .vimrc
, this will be a bit confusing, so you might be better off using an :execute
command and Vim's notation for adding Unicode characters to a string:
execute "inoremap u00A0 <Space>"
(N.B. I'm not entirely sure which character you are inserting when you press Shift+Space: you may need to adjust the Unicode value accordingly.)
* I think that the keystrokes are probably converted in your terminal and never make it to Vim. So Vim only sees the unbreakable space: it doesn't know you pressed Shift+Space
.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
I don't think you can use the <S-Space>
notation in a mapping* but I think you should be able to map it by pressing Shift+Space when typing in the mapping where I've written [lhs]
below:
:inoremap [lhs] <Space>
Of course, when reading your .vimrc
, this will be a bit confusing, so you might be better off using an :execute
command and Vim's notation for adding Unicode characters to a string:
execute "inoremap u00A0 <Space>"
(N.B. I'm not entirely sure which character you are inserting when you press Shift+Space: you may need to adjust the Unicode value accordingly.)
* I think that the keystrokes are probably converted in your terminal and never make it to Vim. So Vim only sees the unbreakable space: it doesn't know you pressed Shift+Space
.
I don't think you can use the <S-Space>
notation in a mapping* but I think you should be able to map it by pressing Shift+Space when typing in the mapping where I've written [lhs]
below:
:inoremap [lhs] <Space>
Of course, when reading your .vimrc
, this will be a bit confusing, so you might be better off using an :execute
command and Vim's notation for adding Unicode characters to a string:
execute "inoremap u00A0 <Space>"
(N.B. I'm not entirely sure which character you are inserting when you press Shift+Space: you may need to adjust the Unicode value accordingly.)
* I think that the keystrokes are probably converted in your terminal and never make it to Vim. So Vim only sees the unbreakable space: it doesn't know you pressed Shift+Space
.
edited 3 hours ago
answered 3 hours ago
Rich
13.8k11763
13.8k11763
add a comment |Â
add a comment |Â
eudoxos is a new contributor. Be nice, and check out our Code of Conduct.
eudoxos is a new contributor. Be nice, and check out our Code of Conduct.
eudoxos is a new contributor. Be nice, and check out our Code of Conduct.
eudoxos is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f17694%2fshow-illegal-whitespace-such-as-unbreakable-space-in-source-code%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password