Questions tagged [indentation]
For questions about prefixing lines with whitespace to aid in readability.
386
questions
0
votes
0
answers
14
views
How can I move the cursor to column 0 without using virtualedit=all
I am encountering the same issue as described in this question: when pressing 0 in Neovim, the cursor moves to the first non-whitespace character, but it doesn't actually move to column 0 (the true ...
2
votes
0
answers
24
views
Incorrect indentation after a do-while loop with a double-line function call and an array parameter in C++
This can be reproduced using vim --clean.
Here's a simplified example of my code:
{
do {
a(b[i],
c);
} while (d);
e;
}
However, Vim indents the line with e; by two ...
0
votes
1
answer
67
views
indent python files with only 2 chars on linux
I have this project where python files are indented with 2 chars, not 4.
On my mac, I use macvim (VIM - Vi IMproved 9.1 (2024 Jan 02, compilé Jan 4 2024 03:08:50)). When I edit a file like this:
#!/...
1
vote
1
answer
24
views
Can I change indentation when type and name are on different lines?
When I write:
{
my_type my_name;
}
in C/C++, putting a new line between the type and name is formatted by the = action as follows:
{
my_type
my_name;
}
I would prefer if it was ...
0
votes
0
answers
36
views
Force vim to use 4 spaces in reStructuredText
I am trying to write some rst files for documenting a Python package, but it is a nightmare to work on it.
When I press Enter I get 3 spaces:
This is text
text after Enter
When I press Tab after ...
0
votes
0
answers
13
views
How can I put a bullet point above or below the current line and have the same indent level automatically? [duplicate]
Let's say I have these bullet points
- First Line
- Second Line
- Third Line
On the second line I do dd, move down to the third line and do p, the second line gets pasted below with no indent, ...
0
votes
1
answer
78
views
Why are my Markdown files being auto-formatted with extra spaces?
I edited a markdown file as
a.md
# Title
## Sub Title
- a
- b
- c
After saving the file, it became:
# Title
## Sub Title
- a
- b
- c
How do I fix it?
It seems that Prettier is ...
0
votes
1
answer
49
views
automatically indenting code in two column based style
What kind of plugin, cindent options, or alike, can I use to indent the code in two column, the first column indented based on block-depth, and the second based on the column of the assignators of the ...
0
votes
1
answer
20
views
Setting guard variables does not prevent default ftplugin/syntax/indent files from running
I want to prevent the default ftplugin/syntax/indent files from running for tex files.
I have a tex.vim in the $XDG_CONFIG_HOME/nvim/ftplugin directory, i confirmed it runs before the default ftplugin/...
0
votes
1
answer
43
views
Is there a setting for maximum indent level?
After setting manual fold by indent with set foldmethod=indent, I found that seems the max indent level is around 20, i.e. more than 20 levels will collapse together.
May I know if there is a setting ...
3
votes
3
answers
101
views
Preventing cursor from indenting after a previously indented line
I'm using neovim and a init.lua file.
In what follows ▮ will indicate the cursor:
for i in range(1,5):
print(i▮
Then I press o:
for i in range(1,5):
print(i)
▮
Then I press backspace:
...
-3
votes
1
answer
52
views
Why four spaces turn into two when copying lines from gVim into LibreOffice? [closed]
I want to paste some codes in gVim:
You see that there are 4 blank spaces at the beginning of line 2 till line 4.
Issue %y+ in gVim, copy all the lines into register, then paste it in LibreOffice:
...
1
vote
1
answer
131
views
How to have different indentation styles depending on the file?
The way the code needs to be indented depends on the filetype.
How can I configure Vim to use the correct value of tabstop, shiftwidth and expandtab depending on the file?
1
vote
3
answers
2k
views
Why is indentation on Github different from indentation in my Neovim?
After committing I realised that indents on GitHub show differently from what I see in Neovim.
I also noticed that all formatting (including indentation) is reset when an error occurs when loading the ...
0
votes
0
answers
34
views
Strange auto indent in Javascript in HTML
When writing Javascript in HTML, vim insists on autoindenting like this:
if( dur.match(/:/) ) {
let xs = dur.split(":")
if( xs.length > 3 ) ...
2
votes
1
answer
99
views
Wrong indentation in brackets
How can I change the automatic indentation inside brackets? Without any configuration, {vim,nvim} does the following:
test = [| # Press enter
test = [
| # Cursor ends up here, at the same ...
2
votes
1
answer
180
views
How do I tell (*Neovim*) that `.ipynb` files have 1 space indents, so indent guides are correctly shown?
I'm using the Indent Blankline plugin to show indent guides.
My Jupyter Notebook/.ipynb files have 1 space indents. Vim identifies them as JSON files.
One way to tell Neovim that Jupyter Notebook ...
1
vote
1
answer
91
views
Indentkeys Tab behavior
I want to have something similar to EMACS tab behavior (described in help indentkeys-format) but I still want to be able to input more tabs if I want.
I thought that adding !0<Tab> to indentkeys/...
0
votes
0
answers
48
views
Why does <esc> on empty, indented line, jump to beginning?
I'm trying to do something very simple, enter normal mode and ALWAYS be able to somehow put the normal mode cursor where it was in insert mode, whether through a mark, or otherwise.
I'm doing this ...
1
vote
0
answers
37
views
How to allow manual folds with indent folds defined?
I want to be allowed to create any folds at all, but I also want Vim to generate all the indent-based folds for me so that I can still use indent-based folding.
Is there some way to mix indent-based ...
1
vote
1
answer
629
views
How to fix indentation for *.nix files?
How can I tell Neovim not to ignore characters after // as well as treat (space) in lists as separator when it comes to indentation?
Closing }; below users.root should be two characters to the ...
3
votes
1
answer
4k
views
How can I make (Neo)Vim wrap lines in respect to indentation?
Currently, indented lines will wrap all the way to the left of the text area. This is what they look like:
This is a long line of text that is indented wi
th tabs. In order for it to properly fit ...
1
vote
0
answers
41
views
What could be causing this indent behavior?
In Typescript files, when I create enums I have a comma at the end of each line.
enum thing {
first = 'first',
| // <--- when I press enter the cursor goes here
}
When I :set shiftwidth=...
4
votes
1
answer
293
views
Trouble in overriding `indentexpr` in neovim
Say I do not quite like the shipped Lua indentexpr (GetLuaIndent(), defined in $VIMRUNTIME/indent/lua.vim). With vim, I can disable or change it using this minimal configuration:
~ % cat .vimrc
...
4
votes
1
answer
326
views
How to turn off auto indenting while editing a LaTeX file?
I edit a LaTeX file, and for some commands Vim does auto indenting.
I would like to switch it off.
Consulting:
https://www.serverwatch.com/guides/automatic-indenting-vim/
I tried:
:filetype indent off
...
1
vote
1
answer
76
views
change behaviour of > / < and >> / << to insert / remove only leading tabs
i want > / < and >> / << to simply insert and remove tab characters at the beginning of the line.
variant: i would even prefer to have> / < and >>/ << insert / ...
0
votes
1
answer
41
views
Manually indenting lines with tabs
Lines can be indented with tab characters. And it is quite obvious the there are better ways to do that than manually adding a tab character to the beginning of each line.
But how to discover these ...
1
vote
0
answers
44
views
Expand all non-leading tabs but keep leading tabs [duplicate]
I want to use tabs for indentation and spaces for alignment in the following way:
keep tab characters (like noexpandtab) for all leading tabs of a file, but
expand tabs (like expandtab) that occur ...
1
vote
1
answer
158
views
What's the Vim option to make indentation matches source file?
I just started at a new company where apparently there is no standardization on tab/space setting at all. Everything goes.
That culture is not going to change. What I want to do is make Vim matches ...
0
votes
0
answers
33
views
Indenting C with brace macros
I use a bunch of weird C macros which basically should behave like braces as far as formatting is concerned. My equalprg is empty, so I'm using vim's indenting function for = formatting. Is there any ...
1
vote
1
answer
34
views
move (motion or visual selection) to own line and indent
Suppose I have the following text
\[
X = (a, b)
\]
I want to easily convert it to the following, including indentation:
\[
X = (
a, b
)
\]
Suppose my cursor is on a. How can I do ...
1
vote
1
answer
276
views
How to stop Vim from indent template in C/C++?
I have piece of sample code (copied from stack overflow)
//some lines of code
template <typename ... Args>
std::string string_format (
const std::string& format,
Args ......
1
vote
1
answer
110
views
Multiple "1 line >ed" messages
When I perform multiple shift :> operations, vim shows me a notification for each line that's shifted. Is there a way to avoid these multiple notifications?
For example, I'm currently editing a ...
0
votes
0
answers
347
views
block comments not automatically indented in Neovim
When inserting a block comment in a (TypeScript) buffer in Neovim, the line after the /**<Return> is not automatically indented. How can I achieve the expected behavior described below?
Neovim
...
0
votes
0
answers
83
views
Vim doesn't keep keep the same indentation as the line above it only in one situation
fn main {
scores.entry(team_1_name)
.and_modify(|&mut team| {
team.goals_scored += team_1_score;
team.goals_conceded += team_2_score;
})
}
When I press ...
2
votes
2
answers
262
views
How to get the right indent size in python lists?
In my vimrc I have filetype indent plugin on
When I write python code, the indentation mostly looks good, but in lists it is too big:
def fun():
return 'indent looks good'
my_list = [
'...
0
votes
1
answer
23
views
Place cursor on opening brace, press "=%", why does the closing brace get indented (in addition to desired indentation of lines between the braces)?
I am following along in the book Vi IMproved by Steve Oualline.
In Chapter 7, "Commands for Programmers", there is a discussion about indentation and the = command.
Here is what I wrote in ...
1
vote
2
answers
2k
views
Neovim keep html tags indented in react/jsx files
When I edit a .html file I get this when pressing enter key:
<div>|</div>
<div>
|
</div>
and while I edit a react file, the behavior is not what I was expecting:
<div>...
0
votes
1
answer
52
views
How do I override indent/html.vim's attribute indent behavior
Stated Purpose
I'm trying to override Vim's HTML attribute indent behavior. This question is specific to ft=html.
Vim has always inserted too many spaces when indenting HTML:
<div>
<div ...
1
vote
0
answers
35
views
Is there a way to map remap 0<C-d> in insert mode
I'm doing a plugin which modify how shift works and remap <C-d> in insert mode. Every thing works well but I have a problem with 0<C-d>. It is a built-in mapping which reset the ...
0
votes
1
answer
92
views
How do I determine the indentlevel to customize showbreak?
I want wrapped lines to look like this:
some really long line that |
... reached the end of the |
... window. |
const indented = () => { |
// a really, really, |
... really ...
0
votes
0
answers
201
views
How to set background color of lines in IndentLine?
I'm trying to configure Yggdroot/indentLine to use the same background color as used in whatever color scheme I'm using, that is I'd like the gray parts to have the same color as the background. From ...
2
votes
0
answers
253
views
JavaScript HTML Template Literal Indenting
I have https://github.com/Quramy/vim-js-pretty-template installed to handle syntax highlighting for template strings marked with /*html*/
But indenting does not work correctly - I end up with ...
0
votes
1
answer
86
views
Autoindent uses tabs after paste mode
My .vimrc:
:set tabstop=2
:set shiftwidth=2
:set ai
:set expandtab
My workflow:
vi filename
type space spacetextenter, cursor is now under 't', indented with 2 spaces. As expected.
:set paste
paste ...
3
votes
2
answers
365
views
Make Vim _really_ work with both spaces and tabs
Here is what I use for indentation:
set autoindent
set breakindent
set expandtab
set smarttab
set shiftround
set shiftwidth=2 softtabstop=-1 " or maybe shiftwidth=2 softtabstop=8
" https://...
0
votes
1
answer
846
views
Indent changes when using CoC, how do I stop this?
I have set up my init.vim file to always use tabs as indentation by adding this to it:
set tabstop=4
set shiftwidth=4
set noexpandtab
Ever since I installed CoC to use Rust's language server, it ...
3
votes
1
answer
124
views
How to indent C function parameters like curly braces and not with cino-(
From :h cino-(, I see that we can only indent the parameters for the function calls with respect to the opening bracket. This is problematic for functions with long names or within multiple namespaces....
0
votes
1
answer
281
views
Indentation is messed up when pasting code
I find that the default indentation support for pasting is lacking.
For example ,
If I use ]p for the following(copied using V) :
try:
l=None
if 1:
df = ...
2
votes
2
answers
265
views
How can I make Tab insert tabs at the start of the line only, and spaces after text?
What I want to achieve
I would like to setup vim such that tabs are inserted on lines until another character is inserted, after which, further tabulation results in spaces (similarly to expantab).
...
2
votes
1
answer
451
views
Force convert spaces to tab in all file type [duplicate]
So today I'm having some problems with vim. I wanted to use tab when I press the tab key, and a tab is equal to 8 spaces. This is what I added to my /etc/vimrc file:
:set noexpandtab
:set tabstop=8
...