Questions tagged [indentation]
For questions about prefixing lines with whitespace to aid in readability.
356
questions
0
votes
0
answers
19
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 ...
0
votes
1
answer
16
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
42
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
45
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
38
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
27
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 ...
1
vote
2
answers
25
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
19
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 ...
0
votes
2
answers
209
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
19
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
24
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
36
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
60
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
108
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
21
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
168
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
0
answers
40
views
Do I need the contents of the indent and ftplugin directories in my configuration?
While I have been using nvim (on Linux) for some time, I have only recently started using gvim (on Linux and Windows).
I have noticed that on the Windows version of gvim there are directories amongst ...
0
votes
1
answer
402
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
40
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
52
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
1
answer
65
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
311
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
...
1
vote
0
answers
27
views
False indentation after line continuation in if-else clause for `sh` filetype
I have shell script file (filetype=sh) like
if [ -f filename ]; then
echo "file exit" | \
cat -
else
echo "file not exist"
fi
When I select the block and apply ...
3
votes
1
answer
75
views
Java Code Conventions: How to set up autoindent
As recommended by Oracle's Java Code Conventions, I try to avoid lines longer than 80 characters. For this it's of course often necessary to break lines, and the document contains some general ...
0
votes
0
answers
103
views
Empty line indentation for Python
Whenever I press o or O, VIM starts the line with the desired indentation. At work, people have decided that they want empty lines to be indented as if it contained code, such that code can be copied ...
0
votes
1
answer
78
views
vimtex: configure to indent '[ ... ]' and '\[ ... \]' blocks
When setting indentation using vimtex, I meet some problem.
I set the option g:vimtex_indent_delims to indent [...] blocks.
let g:vimtex_indent_delims = {
\ 'open' : ['{','(','['],
\ '...
1
vote
1
answer
120
views
vimtex: fully indent a '{ ... }' block
Concerning indent in vimtex, it has some settings controlling indenting of delimiters, the option seems to be g:vimtex_indent_delims. However, I would like to not only indent the text between opening ...
2
votes
4
answers
377
views
How to move cursor up to nearest upward smaller level of indentation
Imagine my cursor is where the ^ is in this document:
{
"first": [
{
"second": {
"third": [
"fourth"
]
}
},
{...
1
vote
1
answer
235
views
`:call append!` -- how vim insert line (append or setline) while respecting indentation
I want to put a string function output in my vim when press xx. My current working example is:
nnoremap <silent> xx :call append('.', 'string_output')<CR>
However, this put a line without ...
7
votes
4
answers
715
views
Vim plugin where the first lines in the editor show the first line(s) with less indendation that are not visible
I would like to either find or write a plugin that does the following:
Assume I have this python code:
def foo(a,b,c):
# comment
[100 lines that do stuff]
for i in range(N):
[100 ...
0
votes
1
answer
33
views
Vim treats paths with wildcards( /*) as C-style block comments and applies weird indentation
Vim 8.1 from Ubuntu 20.04 thinks /* in include /etc/nginx/conf.d/*.conf; is a start of a C-style block comment and gives wrong indentation in default nginx.conf file when using '=':
http {
...
1
vote
0
answers
148
views
vim doesnt recognize html in string in filetype php. same thing with php code in filetype html
Ive had no luck solving these issues for quite a while now.
Problem1
When writing HTML inside a string in a file with filetype=php, the HTML is not recognized (i.e., it has no highlighting or indent).
...
2
votes
2
answers
121
views
How to remove this weird default indentation?
If I do gg=G on a file with the following text
- 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)
- 2020 ICPC Universidad Nacional de Colombia Programming Contest
- ...
0
votes
0
answers
72
views
How can i get visualize line indent every time i use tab or go to new line
I set
set listchars=tab:\│\
set list
to my vimrc and it shows like below
But when I go to another file it doesn't have a vertical line indent. It just affected 1 file, I have no idea about this. ...
4
votes
1
answer
6k
views
How does smarttab actually works?
Yes, I'm aware of what :h smarttab says, but I still cannot figure it out.
" My vimrc
set backspace=indent,eol,start
set tabstop=8 " I always keep this 8
set shiftwidth=4
set softtabstop=-1 &...
1
vote
1
answer
34
views
How to totally close all the auto indent
In my case, I was writing a tex file. After Closing some auto indent settings
set noai noci nosi
filetype indent off
filetype plugin indent off
But vim still gave me 2 tab indent when I type { or [ ...
0
votes
2
answers
97
views
Delete until the start of next visible line?
I'm using MacOS.
As title, for example before the command:
$('h1#title')
.css({'font-size': '80px', 'text-align': 'center'}_)_
.text()
.testing()
.tset()
(Notice that the blank line ...
3
votes
1
answer
131
views
LaTeX: turn off text wrap and auto indent in maths environments
I use vim with vim-latex for editing latex files. I always have hard wrapping enabled using set tw=80. I also have the default vim-latex auto indent settings enabled.
I wonder if there is a way to ...
0
votes
0
answers
106
views
Reindent html with xmllint
I'm trying to reindent current HTML file with this command from inside vim :
:!xmllint --html --format % 2>/dev/null
But, all it does it displays the output to stdout without actually modifying ...
0
votes
0
answers
30
views
Custom indent minified file
At work I'm forced to work on custom mapping-files which map relations between objects of different systems.
These mappings, which are basically Jinja templates, are unfortunately stored in single ...
2
votes
1
answer
116
views
Inserting abbreviation from file
First, I apologize if this is a trivial question.
I have the following file (main.ab) defining a Python snippet:
def main(args):
...
if __name__ == '__main__':
args = ...
main(args)
And ...
0
votes
0
answers
25
views
How to configure what happens after hitting enter inside parentheses [duplicate]
| - cursor position
when I edit JavaScript file:
function(|)
pressing "Enter" gives
function(
|
)
Which is good for me. But when I edit R file it gives:
function(
|
)
How can I ...
1
vote
1
answer
32
views
vimscript to insert function result is not inserting with proper formatting
I have a function that I want returning pre-indented xml:
function! InsertStep()
let stepTemplate = "<step index=\"\">\n
\ <description></description>\n
\ ...
0
votes
0
answers
123
views
How to apply existing indenting rules to new file type?
I've been happily using vim for years for C and C++ projects. My code formatting/indentation rules have been cobbled together over the years based on solutions to at-the-time needs...which is to say, ...
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 ...
0
votes
2
answers
103
views
Space indent disappear when `o`/`O` follows by <Esc>
In short, I want to keep the indentation created by o after pressing <Esc>. To make it clear, I will try to describe my problem with an example.
Given the position of my cursor at:
function Test(...
1
vote
1
answer
166
views
Replace two space indentation with tabs
I'd like to replace all two-space indents with tabs
I can't do :%s/ /^I/g bc this replaces within lines too.
I can't do :%s/^ /^I/g bc this replaces only the first two spaces of each line, not each ...
1
vote
1
answer
99
views
Re-indent for eruby files does not work
I am trying to re-indent a foo.html.erb file, however when I do gg=G everything gets aligned to the beginning of the line. I couldn't figure out why that happens. I've tried installing polyglot or ...
0
votes
1
answer
13
views
Move the caret to proper indentation inside insert mode in C files when using arrow keys
In insert mode, scope indentation is not taken into account if I navigate rows during insert mode. Example:
In such a case, if I would press the up arrow key, Vim would place my caret at the start of ...
1
vote
1
answer
44
views
Loading C file overwrites indentation settings in .vimrc [duplicate]
When I open a C file in vim, it seems to think I want 8 spaces worth of indentation, even though I specify my indentation preferences in .vimrc with the below:
set expandtab
set softtabstop=4
set ...