Questions tagged [whitespace]
Question about how Vim handles non printable characters.
77
questions
0
votes
1
answer
26
views
zf add fold marker comments with preceding spaces
Setting foldmethod=marker, I can highlight a few lines, press zf to fold them. By default vi will add {{{ and }}} at the ends of the beginning and ending lines. I am working on shell scripts with ...
1
vote
1
answer
22
views
Only highlight trailing whitespace in normal mode
I have some code in my ~/.vimrc to highlight trailing whitespace.
" Highlight trailing whitespace
hi TrailingWhitespace ctermbg=red guibg=red
matchadd("TrailingWhitespace", '\v\s+$')
I ...
0
votes
1
answer
70
views
How to remove vim trailing white space?
In Vim I used autocmd BufWritePre * :%s/\s\+$//e to delete trailing white space. Now, Neovim 0.7 has the new vim.api.nvim_create_autocmd.
What is the correct syntax to update this autocmd in Lua?
vim....
1
vote
1
answer
72
views
Next paragraph - don't skip lines with white spaces
When using { and } to skip to the next paragraph, the behavior is unpredictable since I can't see white spaces. I have tried to show line endings to see which lines have spaces, but I don't like the ...
-1
votes
4
answers
75
views
Remove blank lines appearing between non-blank lines without a regex?
What is the quickest way to un-doublespace in Vim, without using a regex?
I.e., convert
line one
<emptyline>
line two
<emptyline>
line three
to
line one
line two
line three
There's gotta ...
1
vote
0
answers
37
views
What is the empty space in this document and how do I. get rid of them
Here is my document:
What is the thing that my cursor is on? It is definitely not a whitspace as all white space should be marked with ␣.
And more importantly, how do I get rid of it?
I have tried
:g/...
3
votes
2
answers
430
views
How do I replace single whitespaces without affecting multi-whitespace such as indentation in Vim?
I have textfiles with paths that have lost underscores between words inline in an OCR process. I want to keep the indentation and put back the underscores in the paths.
I have a path like this:
/...
2
votes
1
answer
62
views
Option to prevent outer yank (ya') from yanking leading whitespace?
If i have something like
foo(
'parameter'
)
and I press ya' with the cursor somewhere inside the parameter string then the indentation space gets yanked too and I end up with 'parameter' in my * ...
-1
votes
1
answer
32
views
Avoid colours of white space
Added a lot of stuff to my vimrc lately and I am not sure what is causing vim to colour the whitespaces. The colour disappears when I save the file. However I would like to disable this feature. Is ...
6
votes
1
answer
238
views
Matching any Unicode whitespace
I'd like to match in Vim any whitespace character, not only normal space (U+0020) and tab (U+0009) with \s, and the other ASCII ones like form feed (U+000C) with [[:space:]], but any Unicode ...
0
votes
0
answers
27
views
Keep whitespace from indent even on empty line [duplicate]
I am working with python files with filetype indent on. I like a lot of the default indenting features for python, but I would like vim to keep the tabs, even on empty lines.
For example, using set ...
0
votes
2
answers
204
views
How to convert spaces on a line to tabs?
I know there's a way because it happened by accident. I was frenetically moving in a short region of text and at some point, with some wrong keystroke, the leading spaces on the line became a tab (and ...
0
votes
0
answers
33
views
What is the shortkey for adding a space before a word in normal mode?
I have the following text:
#Text
My cursor is on character T; I want to obtain
# Text
i.e., to put a space between # and T, without "pressing i and then space". Instead, I want to do so in ...
1
vote
1
answer
75
views
How to use different rules for highlighting trailing whitespace inside a gitcommit diff
In my ~/.vimrc, I have:
highlight TrailingWhitespace ctermbg=blue
autocmd BufReadPost * syn match TrailingWhitespace /\s\+\%#\@<!$/
This highlights trailing spaces, except when I am still typing ...
4
votes
1
answer
74
views
Why do some Ex commands not need a white space before a path argument?
For example, why does this work:
edit/home/foo/bar.txt
(I had to enter visual to see the changes)
I was expecting a whitespace after edit, like:
edit /home/foo/bar.txt
I couldn't find a reference in ...
1
vote
1
answer
104
views
Stop vim from deleting expanded tab as a block of spaces
I am on CentOS 8.1 and using vim 8.0.1763. When I open a python file, e.g. vim tmp.py, I type tab and it inserts 4 spaces (see .vimrc below). When I type delete, it deletes all 4 spaces. I want it ...
1
vote
2
answers
146
views
<Space> doesn't insert a space within a function
So I'm trying to have a function type out a space which goes as follows:
function! UnderlineHeading(level)
if a:level == 1
normal! yypVr=
elseif a:level == 2
normal! yypVr-
else
...
1
vote
1
answer
79
views
Turning the `match` command on and off
I found this useful setting form this post, which highlights trailing whitespaces :
highlight ExtraWhitespace ctermbg=grey guibg=grey
noremap <F10> :match ExtraWhitespace /\s\+$/<CR>
This ...
0
votes
1
answer
85
views
How to delete and replace a block of text with spaces?
What I want to do
I want to select a block of text in Vim, delete it, and replace the selected block with spaces.
Example
Suppose I have the following text:
Lorem ipsum dolor sit amet, ...
1
vote
2
answers
228
views
Function to remove all trailing whitespace
I have the following function to remove every trailing white space from the document, without changing my cursor position
function! StripTrailingWhitespaces()
let l = line('.')
let c = col('.')
...
2
votes
1
answer
73
views
What option controls how much space is added after a new line?
When I set tw vim will auto wrap lines at tw. When breaking that line vim usually places some spaces to keep the indentation of the previous line. Example
foo
bar<suppose that a wrap happens ...
2
votes
1
answer
119
views
Leading blank line with execute function()
When I run :echo execute('echo "oh"') I get a leading blank line before the "oh" message. This happens with when I use no vimrc as well. Why is this?
1
vote
1
answer
703
views
Disable automatic whitespace marking in red
I am experiencing a behavior as depicted in the picture below: vim marks the redundant spacing in red.
I would like to completely remove this behavior. At the moment my .vimrc file reads as:
set ...
2
votes
2
answers
388
views
Visual indicator for a file that doesn't end in newline
Inside of my editor (almost fresh install of neovim) there is no visual way to distinguish between a file that ends in a newline and a file that doesn't.
In my command line (zsh default?) there is a ...
2
votes
1
answer
248
views
Listchar for Preceding Indentation Space
At the moment, I'm trying to highlight the spaces/tabs used for indentation and the end-of-line with special characters.
Although I prefer tabs over spaces I also need the spaces highlighted in order ...
2
votes
1
answer
164
views
Moved from vim to neovim and now <BS> deletes 4 spaces at a time, instead of 1 as I'm used to. How to fix?
I've used vim for ages and am really used to inserting four spaces by hitting tab, but then being deleting them one by one. Now that I've switched to neovim this has changed to it inserting four ...
3
votes
3
answers
3k
views
Moving to the end of the last word on a line
There are commands to distinguish between the beginning of a line (0) and the beginning of the first word of the line (^), basically ignoring leading whitespace. But I can only find one way to move ...
1
vote
2
answers
253
views
Delete whitespace before and after word
I have some text with two dashes:
This is some text -- with two dashes.
I want to delete the space before and after the dashes:
This is some text--with two dashes.
Is there a way this can be done ...
4
votes
2
answers
1k
views
Stop Vim from deleting trailing whitespace [closed]
Vim automatically strips trailing whitespace from my files on save, which is extremely annoying in various contexts. How do I disable this behaviour?
This question is not a duplicate of this one, ...
0
votes
2
answers
542
views
Replace tabs with appropriate number of spaces
I have this texts
drwxr-xr-x enan enan Jan 15 16:10 Desktop/
drwxr-xr-x enan enan Jan 16 20:09 Documents/
drwxr-xr-x enan enan Jan 20 19:52 Downloads/
drwxr-xr-x enan ...
0
votes
1
answer
149
views
Expandtab converts spaces to newline character?
When I enabled expandtab in vim by putting these in .vimrc:
set tw=4
set expandtab
Vim comverted every space typed by me to a newline character.
Like with the above settings whenever I type a new ...
2
votes
1
answer
40
views
On the length of tabs after an initial character
Length of tabs after initial char
Start gvim with the --clean option, to get a clean slate, and then do:
:set noet ts=5 sts=3 sw=2
Then enter the following
1234567890
and on the next line, press ...
5
votes
4
answers
3k
views
How to show illegal whitespace (such as unbreakable space) in source code?
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 ...
1
vote
1
answer
184
views
Preventing the join() command from adding extra space
I am trying to use the join command to join multiple strings. The join command seems to add one character of space in between each of the strings. But I don't want any space added.
As an example, I'm ...
1
vote
1
answer
156
views
Tab multiple lines [duplicate]
I have my tab set to 4 spaces with :set tabstop=4.
Now I want to highlight multiple lines and tab them, or indent all them 4 spaces. If I highlight the lines and do >, it seems to indent them more ...
4
votes
3
answers
2k
views
How to remove trailing white-spaces automatically while typing?
I'm often editing code where others didn't care about trailing white-spaces. I'm using the TrimWhiteSpace()-function from this answer to remove white-spaces when saving the file.
However that leaves ...
53
votes
1
answer
107k
views
Setting TAB to 2 spaces
I've looked through various answers which imply that setting the following in .vimrc would be appropriate to force tab insertions to become spaces.
filetype plugin indent on
" On pressing tab, ...
0
votes
1
answer
258
views
Removing trailing spaces with the substitute command changes the cursor position
From http://vim.wikia.com/wiki/Remove_unwanted_spaces
function TrimWhiteSpace()
%s/\s\+$//e
endfunction
autocmd FileWritePre * call TrimWhiteSpace()
autocmd FileAppendPre * call TrimWhiteSpace()
...
5
votes
2
answers
4k
views
Expand <TAB> into 2 spaces when and only when editing HTML
My current configuration makes vim automatically expand TAB to 4 spaces for me:
" Define tab as 4 spaces
" Taken from http://stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
set tabstop=4 ...
2
votes
1
answer
187
views
Dangerous trailing space
In remove unwanted spaces page in vim wikia, it says:
However, this is a very dangerous autocmd to have as it will always strip trailing whitespace from every file a user saves. Sometimes, trailing ...
2
votes
2
answers
1k
views
Removing redundant whitespaces on save/write
I want all redundant whitespaces to be removed on write/save. How can I do that?
By redundant I mean ones that exists after the last character or if there's an empty line and it contains a few ...
3
votes
1
answer
1k
views
vim search for arbitrary combination of spaces and tabs
I'd like to construct a mapping that would replace a b with c where the gap between a and b could be zero or more spaces or zero or more tabs, but not zero of both. There have been several ...
5
votes
2
answers
568
views
Is there a way to strip the contents of register before pasting
There are times I know I just want to paste the content of the register inline where my cursor is, so the initial and trailing whitespace (newline, tab, etc) is not wanted.
Because selecting contents ...
2
votes
0
answers
338
views
Custom highlights not working in visual splits
I'm a tabs kind of guy, so I highlight leading and trailing white spaces with the following commands in my .vimrc:
highlight whiteSpace_trailing ctermbg=red guibg=red
highlight whiteSpace_leading ...
7
votes
1
answer
972
views
How to show trailing spaces, while leaving tabs as they are?
I like the ability to show trailing whitespaces, so I have this setting.
set list listchars=tab:\ \ ,trail:·
I never use tabs (although I don't think tabs are bad, it's just a convention), but ...
2
votes
2
answers
1k
views
Show leading whitespaces, but not including tabs
I am a tabs kind of guy, I do not like when my code contains leading whitespaces instead of leading tabs. I often exchange codes with colleagues and I first have to convert the leading whitespaces to ...
10
votes
3
answers
1k
views
Shift left or right (with `noet`) without converting existing spaces to tabs
Foreword
I'm using the "indent with tabs, align with spaces" ideology for indentation. This means that each line in a file can be prefixed with an arbitrary amount of tabs and spaces (as opposed to "...
2
votes
1
answer
670
views
Disable vim-better-whitespace highlighting for nvim-ipy buffer
I am using the vim-better-whitespace plugin to highlight trailing whitespaces. For some buffers, I don't want this behavior and vim-better-whitespace usually provides an option to list the filetypes ...
17
votes
4
answers
2k
views
What is the rationale for \r and \n meaning different things in s command?
We all know that, when searching, \n is newline and \r is carriage return (^M), but when replacing \r is newline while \n is a null byte (^@).
What is the origin of this asymmetry? Given that this ...
0
votes
1
answer
73
views
How to operate on all of a word without its surrounding space?
In vim you can do daw to delete the entire word, but it also removes the space after the word, (caw too).
Is there a way to operate on the entire word without effecting the space around it?
For ...