Questions tagged [whitespace]
Question about how Vim handles non printable characters.
86 questions
3
votes
1
answer
211
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 ...
0
votes
1
answer
938
views
How to configure pylsp installed by Mason with lsp-zero for nvim?
I want to disable a specific error/warning - E203.
This is my lsp.lua where I tried to add ignore config according to this doc from lsp-zero git
local lsp = require("lsp-zero")
lsp.preset(&...
81
votes
3
answers
103k
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 ...
219
votes
7
answers
220k
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 ...
2
votes
1
answer
522
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 ...
0
votes
1
answer
72
views
Convert spaces to tabs on only one line
So I know that, in Vim, I can use the :retab command to convert an entire file from multiple-spaces to tabs or from tabs to spaces, depending on the value of :set expandtab.
But is there a way that I ...
2
votes
3
answers
230
views
Remove blank lines at end of file
How can I augment/modify my trailing whitespace logic to also remove any empty or all whitespace lines at the end of a file?
My current whitespace stripping logic in my .vimrc is:
"remove ...
4
votes
2
answers
772
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 ...
16
votes
3
answers
11k
views
How to remove Neovim trailing white space?
In Vim I used autocmd BufWritePre * :%s/\s\+$//e to delete trailing white space on save. Now, Neovim 0.7 has the new vim.api.nvim_create_autocmd.
What is the correct syntax to adapt this autocmd in ...
5
votes
1
answer
654
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 ...
70
votes
2
answers
148k
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, ...
215
votes
9
answers
277k
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?
6
votes
1
answer
587
views
What does breakat&vim mean?
I'm trying to understand this SO answer. The snippet reads:
:set nolist wrap linebreak breakat&vim
0
votes
0
answers
87
views
How to make `lead` override `trail` in listchars
I have the following lines in my .vimrc.
set list
set listchars=lead:·,trail:⎵
Whenever I have a line consisting of only spaces, the character shown is ⎵.
How can I make vim prefer · in this scenario?...
15
votes
4
answers
35k
views
How to split a line into multiple lines efficiently?
I've been receiving logged data in a text file that is just one long line with each value separated by a space. Is there a command or set of commands that will split one line into multiple lines?
13
votes
2
answers
8k
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 ...
0
votes
1
answer
776
views
How do I add spaces to a file path in vimrc?
I am trying to set the shell to git bash in my vimrc.
I have this:
The code says:
set shell=C:\Program Files\Git\git-bash.exe
But because there's a whitespace in Program Files, it acts as a separate ...
2
votes
1
answer
410
views
How Can I Use The Error Color for `guibg` and `ctermbg`
I have the following Vim code which highlights trailing whitespace in red:
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
But instead of making the color "red"...
0
votes
1
answer
1k
views
Vim search: how to factor in the white space during the search?
Doing a search with / can be useful, however, it becomes harder to find things if the term you are searching for is a part of other words. I have a large text document with notes i've made about the ...
0
votes
1
answer
341
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 ...
2
votes
1
answer
780
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 ...
1
vote
1
answer
240
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 ...
5
votes
2
answers
5k
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 ...
9
votes
3
answers
11k
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 ...
3
votes
3
answers
4k
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
votes
4
answers
112
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
38
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
547
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
137
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 * ...
8
votes
1
answer
1k
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
2
answers
4k
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 ...
-1
votes
1
answer
125
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 ...
0
votes
0
answers
28
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 ...
1
vote
0
answers
37
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 ...
2
votes
1
answer
550
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 ...
4
votes
1
answer
86
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
2
answers
289
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
342
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
479
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
339
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('.')
...
10
votes
3
answers
2k
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 "...
124
votes
5
answers
33k
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 ...
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 ...
2
votes
1
answer
328
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
181
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
1k
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 ...
3
votes
2
answers
1k
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
409
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
2
answers
2k
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 ...
3
votes
1
answer
353
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 ...