Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [whitespace]

Question about how Vim handles non printable characters.

Filter by
Sorted by
Tagged with
211 votes
6 answers
206k views

What's the simplest way to strip trailing whitespace from all lines in a file?

It's pretty common when programming or opening text files to encounter files with trailing whitespace at the end of a line. vim has a way to show this by setting the trail option in the listchars ...
Andrew Ferrier's user avatar
9 votes
3 answers
10k views

Vim doesn't use the correct indentation in Python files

I have encountered something that I have never seen before in Vim. While I was tentatively modifying some of the source code for software I've been planning to work on, I noticed vim was displaying ...
BenB's user avatar
  • 193
209 votes
9 answers
267k views

How can I display tabs as characters?

When I work on files in python, I sometimes mistake tabs for spaces and vice versa. Is there a way I can get Vim to display a character for a tab instead of a tab?
Dom's user avatar
  • 3,314
18 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 ...
Matteo Italia's user avatar
4 votes
2 answers
646 views

How can I make zz not center cursor when approaching end of file?

When I press zz at the end of file, the line is displayed at the center of screen by having many empty lines having empty lines beyond end of file is great, but this is too much. Is there a way to ...
zyy's user avatar
  • 239
119 votes
5 answers
31k views

How to join lines without producing a space?

The standard J command for joining lines replaces the newline character(s) with a space. It's useful when editing 'literature' but can be troublesome if I, say, edit a hex dump by hand if I forget to ...
SF.'s user avatar
  • 2,109
3 votes
1 answer
307 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 ...
Codemonkey's user avatar
79 votes
2 answers
97k views

How to indent as spaces instead of tab?

I am coding some html templates in JADE files. I want to auto indent code with spaces instead of tab. I tried shiftwidth=2, tabstop=2, but no matter what, it's still indents using tabs instead of ...
learningtech's user avatar
21 votes
3 answers
3k views

How can I make Vim position the cursor at the start of a tab character instead of the end?

Open an empty buffer and insert a tab character then exit to normal mode. When you place the cursor (normal mode) on the tab it will be at the right side of the whitespace. I'm looking for a way so ...
Chad Paradis's user avatar
12 votes
2 answers
6k views

How to differentiate visually the white spaces in Vim? [duplicate]

My goal were to somehow make visible, if a whitespace is space, tab, or even newline (and, ideally, in case of newline I would be happy to see \r\n and \n differently). I am thinking to a similar ...
peterh's user avatar
  • 1,161
7 votes
1 answer
1k 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 ...
user1685095's user avatar
  • 1,141
6 votes
4 answers
5k 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 ...
eudoxos's user avatar
  • 173
5 votes
3 answers
1k views

Avoid spaces getting converted to tabs automatically during shift(>>)

I use 2 spaces as indentation. So I set shiftwidth using :set sw=2. However when I do the shift operator(>>) on a line twice, the indentation converts the 4 spaces automatically to a tab. So to ...
toddlermenot's user avatar
5 votes
3 answers
4k 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 ...
Patrick B.'s user avatar
4 votes
1 answer
543 views

How to center a cursor on the screen, even at the start of the file?

I like always knowing where my cursor is. I do this by having it in the center line of the screen. However if I am working at the top of the file the cursor stops centering because there is no more ...
Jason Basanese's user avatar
2 votes
1 answer
488 views

Stop vim from removing whitespace on save for diff files

I am currently trying to edit a git hunk file (a diff: .git/addp-hunk-edit.diff), and to say to git that a line containing whitespace is unchanged it needs to have (a line with a single space) as its ...
oligofren's user avatar
  • 1,103