Questions tagged [indentation]
For questions about prefixing lines with whitespace to aid in readability.
351
questions
0
votes
1
answer
16
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
40
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
103
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
25
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
31
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
15
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
36
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
59
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
342
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
69
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
664
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
32
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
85
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
107
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
35
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. ...
3
votes
1
answer
2k
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 &...
0
votes
0
answers
8
views
Javscript auto indentation with Django HTML Templates
When trying Javascript within tags in a Django template, the behaviour is absoutely terrible. Pressing enter may mess up the line above and below.
I spend more time fighting the crazy indentation ...
1
vote
1
answer
28
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
79
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
84
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
68
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
26
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 ...
1
vote
1
answer
64
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 ...
0
votes
0
answers
74
views
How to selectively indent Sphinx .rst (reStructuredText) files
As per indentation section of the Style guide for Sphinx-based documentations:
Indent with 2 spaces.
Except:
toctree directive requires a 3 spaces indentation.
So how to set Vim to auto-indent the ...
1
vote
1
answer
26
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
73
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
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
83
views
Space indent disappear when `o`/`O` follows by <Esc>
I will try to describe my problem with an example. Given the position of my cursor at:
function Test() {
return (
<div>█
</div>
)
}
NORMAL
When I press o:
function Test() {
...
0
votes
1
answer
50
views
How to use tab for indent in indent function while expand tab was set?
When expandtab is set, how to let the indent function defined in file vim/indent/xxx.vim use tabs, rather than spaces to indent lines?
Edit:
Here is the background. I have use vim's built-in CHANGELOG ...
1
vote
1
answer
78
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
64
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
43
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 ...
0
votes
1
answer
127
views
Preventing the colon from causing indentation to be deleted
When opening a C file, then even with the vanilla setup on my Linux Mint system, if I type identifier at the beginning of an indented line and then ':'
immediately after it, the indentation for that ...
2
votes
2
answers
183
views
How to re-indent nginx configuration based only on `{` and `}`?
I want to reindent an nginx configuration file with the following simple rudimentary rules:
a { increases indentation
a } decreases indentation
The idea is cindent is just enough to do it. I have ...
3
votes
1
answer
228
views
How can I make fmt return leading spaces instead of tabs?
When I use vim to write regular text (not source code), I often highlight a long line, or a paragraph, and do: !fmt to re-format the lines into proper length lines. I think they up up being 75 ...
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 ...
2
votes
1
answer
37
views
Indentation error on VHDL component instantiation
I'm finding some strange behaviour on indentation in VHDL, and have added a minimum example. It is very strange, as everything else seems to work perfectly with VHDL.
Does anybody know how to fix this?...
4
votes
0
answers
116
views
Can I get vim to indent correctly after a here document?
In an account with just an emtpy .vimrc, under Xubuntu 20.04 and vim 8.1, I get strange indentaion after my here document if I reindent with gg=G
I've boiled down an example from some pretty tangled ...
1
vote
2
answers
141
views
Where should I put filetype specific options for indentation?
At moment, mostly for random reasons, I have
$ cat ~/.vim/ftplugin/c.vim
set tabstop=2 softtabstop=2 expandtab shiftwidth=2 smarttab smartindent autoindent cinoptions=g2
and this
$ cat ~/.vim/...
2
votes
1
answer
25
views
text object for current indentation level? [duplicate]
Say I have an indented block like so
int main(int argc, char **argv){
printf ("odd numbers between 1 and 10:\n");
// level 1
for (int i = 1; i <= 10 ; i ++) {
// ...
1
vote
1
answer
332
views
How to get indentation lines for spaces without loosing chars like quotes in json files
rephrased my question based on Matt's answer and Christian's comment:
I really like the indentLine plugin that shows vertical lines to visualize indentation levels. However, when using it, it does not ...
0
votes
1
answer
52
views
How to make a filetype behave exactly like C++?
I want the filetype .my_cpp and .my_cc to behave exactly like C++ files in Vim. I have the following set:
autocmd BufNewFile,BufRead *.my_cc set syntax=cpp
autocmd BufNewFile,BufRead *.my_cpp set ...
0
votes
1
answer
24
views
Understanding interaction between visual, autoindent, and paste option
Let's start form this faulty C++ source file
#include <vector>
int main() {
std::vector<std::vector<int>> v{
1,2},
9,3},
4,2}
};
}
which ...
2
votes
1
answer
310
views
Understanding indenting rules for C++ files
Why is the following C++ source file indented like this,
#include <vector>
int main() {
std::vector<std::vector<int>> v{
{1,2},
{1,1},
{1,2}
};...
0
votes
1
answer
60
views
Vim indentation different on linux and macOS
I'm using vim to write in C for college. My .c files need to abide to specific formatting rules. While I'm writing my files on Linux, the .c files will be evaluated on macOS. I noticed that any tabs ...
0
votes
0
answers
72
views
`filetype plugin indent on` with `filetype=html` over-indents <script>
Since my last system update (I think), I have noticed this very annoying behavior.
# vim foo.html
# I go to insert mode, I type (no whitespace except newlines)
<html>
<head>
...
0
votes
1
answer
90
views
Unwanted cascading indentation [duplicate]
I am struggling to regain control of indentation for certain filetypes, particularly when pasting code. I end up with what I call "cascading indentation" which is nearly unreadable.
I've run ...
0
votes
0
answers
23
views
How to write a function to set nobreakindent when using the Pencil plugin?
I'm trying to get the Pencil plugin to run with the noautoindent and nobreakindent settings. This is what I've tried in my init.vim:
+ 201 function! s:pencil_enter()
+ 202 set nobreakindent
+ 203 ...