Questions tagged [indentation]
Prefixing lines with whitespace to aid in readability.
309
questions
2
votes
2answers
55 views
Fix indentation in a file while keeping cursor on the same line
I'd like to use vim's builtin indent fix feature on an entire file. I have looked up answers, but all I found were suggestions to type gg=G, the only problem being that it brings your cursor to the ...
0
votes
1answer
74 views
Keep indentation after multiple newlines
I've got a problem where in insert mode, if I type something like { that will cause indentation, then press enter twice, then match that bracket (such that there is a line in between the opening and ...
0
votes
1answer
78 views
insert new bullet point in autoindent mode
with autoindent mode on, when writing a short bullet point on restructuredtext file:
- item one
~
Then I press Enter, and I get:
- item one
~
but I whould like to quickly by here:
- ...
1
vote
0answers
213 views
Smart and auto indent not indenting as expected for JSX
I'm trying to figure out how to get vim to correctly indent the next line in a JSX block.
Currently when I press enter, the cursor goes slightly behind where it should be. In the example below, my ...
1
vote
1answer
62 views
Why is the commit message inside parentheses wrapped so strangely?
I sometimes need to do some remarks in parentheses in my commit message's detailed part. But when the parenthesized text comes to the rightmost column and is line-broken, the next line for some reason ...
5
votes
1answer
59 views
gq in visual mode indents just first two lines of enumeration
Some markdown as an example. I select the following paragraph in visual mode and press gq. The result is:
- Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor ...
1
vote
1answer
120 views
Override indentation settings with autocmd
When editing Typescript neovim automatically sets indentexpr=GetTypescriptIndent(). I don't like the way it aligns to
an open brace instead of inserting a (soft) tab or two, but it doesn't seem to be ...
1
vote
1answer
43 views
What setting causes my autoindent to add indent on a new line?
I have this go code snippet that I am working on in vim with vim-go enabled. | is where my cursor is at.
// PlayerServer is a HTTP interface for player information
type PlayerServer struct {
...
0
votes
2answers
58 views
Find and replace only between searched patterns
Editing large HTML file. Would like to do something like:
:/<blockquote>/,/<\/blockquote>/s/^\(\s\s\+\)\(<[^>].\{-}>\)/\1 \2/g
So basically just trying to indent all between ...
0
votes
1answer
40 views
How to have the cursor at the right indentation when editing PHP/HTML
When I'm working with HTML in a PHP file and I press enter while in INSERT mode, my cursor goes to the start of the next line instead of going at the right positive therefore I have to press tab to ...
1
vote
0answers
38 views
Where can I find good indentation file for lex filetype?
I checked and found only a syntax file for lex filetypes in /usr/share/nvim/runtime/syntax, but found no indent file in /usr/share/nvim/runtime/indent
I want my lex files to be properly indented; one ...
2
votes
2answers
235 views
Format / Indent c++ as you type inside expressions
In visual studio, that code :
for(int x=0;x<10;x++)
{}
becomes that code :
for (int x = 0; x < 10; x++)
{
}
as soon as you hit enter.
I was wondering, is it possible, and if so, how can I ...
3
votes
1answer
683 views
Why does vim still auto-indent LaTeX after I set noai noci nosi?
I want to disable autoindent and smartindent for LaTeX so I did
:set noai noci nosi
When I open a brand new mwe.tex, filetype=plaintex and there is no auto indent magic.
When I then enter some code,...
1
vote
2answers
115 views
How to move a cursor to the last line with auto indent?
Assume autoindent is set, and you have the buffer below. Note the cursor is represented as I.
for i in range(1, 6):
print(i)I
When you hit Enter key, you get this.
for i in range(1, 6):
...
1
vote
0answers
25 views
How to get the right indentation and new line when adding a new line between brackets? [duplicate]
So I am curious about one thing:
when I am between two brackets ({) in vim (or nvim), and I press Enter I go from this (where the pipe sign is the cursor):
getUsers(){|}
to this:
getUsers(){
|}
...
2
votes
3answers
2k views
How to indent or unindent lines in a block of text?
I use two spaces in my indentation of codes. What are the possible ways to indent or unindent a block of code?
2
votes
3answers
121 views
Plugin to show enclosing indentation levels
I'm looking for functionality which may or may not exist. Basically, I'd like to have a location list split at the top of each writable buffer which shows the last line of each enclosing indentation ...
0
votes
0answers
43 views
vim disable behavior special tags (eg script)
When editing html, vim applies different rules when inside certain tags (like script/pre/style). I want to have the normal html rules when inside a script tag (using handlebars, and I don't write any ...
0
votes
1answer
71 views
'filetype plugin indent on' breaks indention [closed]
Using vim 8.*, I am using these plugins:
html5.vim
polymer-ide.vim
supertab
vim-javascript
In my vimrc.local file if I enable filetype plugin indent on it breaks my javaScript indention but makes the ...
4
votes
1answer
979 views
How to make a newline without autoindent
Is there a command to make a newline without the autoindent? In other words, I want o and O to normally autoindent, but is there another command that will not autoindent for just the duration of that ...
1
vote
0answers
50 views
How to indent HTML5 with omitted closing tags properly?
I try writing some HTML5 with omitted closing tags in NVIM v0.3.4, and get this:
<ol>
<li>3
<li>4
<li>8
<li>9
</ol>
This ...
1
vote
1answer
80 views
Match indentation upon newline without replacing spaces with tabs or vice versa
When I create a new line or hit o I have Vim configured to match the previous indentation.
However, since I use hard tabs in most places, vim will replace any spaces that are greater than or equal to ...
0
votes
1answer
38 views
Indent text to beginning of line
Sometimes I'll have some text with an arbitrary indentation.
Sample text.
If I want to bring this text back to the beginning of the line, I'll visually select the line and then ...
1
vote
1answer
113 views
Multi-line array variable in bash with filetype sh does not indent correctly
I have the following bash array after automatic indentation, both on pressing carriage return when was editing in :h Insert mode and doing =ip on the block in :h Normal-mode
DOTFILES=(
".bashrc"
"....
0
votes
1answer
58 views
How can I reindent/prettyify blocks of HTML code?
I've got a lot of HTML files, some of them with garbage indentation.
How can I select a block, and then prettify/reindent the HTML within, adding in newlines where appropriate? I can install any ...
0
votes
0answers
81 views
How do I get Vim (with TComment) to do proper block comments in OCaml?
(I have TComment installed, and I'm on NeoVim 0.4.0.)
Given this code, for example:
let mem key st =
let is_matching_key = function
| Positional _ -> false
| Flag f -> f.name == key
...
0
votes
3answers
176 views
Substitute tabs for equivalent number of spaces
N.B I use the word blank here due to lack of a better word. By blank I mean the remaining part of a tab that is visualized after the starting part. Please feel free to edit this question.
I know ...
0
votes
0answers
83 views
In PHP files, how can I auto close HTML tag pairs and indent the new line?
I have been a Vim user for several years now and I haven't been able to find a solution to this issue. There have been a lot of questions on the internet that try to address it, but none of the ...
7
votes
1answer
410 views
How to visually select based on indentation?
If someone is editing the following javascript file:
let foo = true
if (foo) {
let bar = 42
// moooooore code...
}
You can use vi{ anywhere on the line with let bar to select let bar = 42 and ...
0
votes
1answer
97 views
inoremap inserts unwanted tabs
I recently made myself custom insert mode keybindings to type faster in LaTeX. However, When I use them, Vim adds tabs that weren't part of the original keybinding.
Example:
Here is my inoremap:
...
1
vote
2answers
656 views
What is valid use case for `smartindent`?
I might not have discovered everything about it, but the smartindent option has given me much more trouble than usefulness. For example, it indents a line beginning with for or if, and won't shift a ...
1
vote
1answer
89 views
Indenting a c file adds spaces before function's type?
Open a c file and then type:
int
main
and then hit:
gg=G
It becomes
int
main
Is this an intended behavior? Is there a way to change this? I prefer it to be retained as is because most ...
1
vote
1answer
69 views
How to stop auto indent for some file with particular suffix
In my .vimrc file, I add few lines to it so that some file could have nice auto indent, such as .f90 and .c file, but it also cause autoindent for .plt file. Is there some way like if statement that ...
0
votes
1answer
66 views
LaTeX indent for \iff error in vim
With the minimal vimrc (with vimtex plugin):
set nocp
filetype plugin indent on
syntax on
set st=2
set acd
set wildmenu
set wildmode=longest,list,full
let $USRPLUGD=$HOME.'\vimfiles\myvim\plugged'
...
1
vote
1answer
405 views
How to show 2 spaces as tabs in listchar?
I like to see my indentation level with listchars=tab:\|\
But one project uses two spaces instead. Is there any way to show indentation level lines then?
This question seems to the opposite of Show ...
2
votes
1answer
260 views
Keep relative cursor position after indenting with >>
Can I setup >> to keep the relative cursor position?
For example, assuming the line is
def fun(<cursor>):
can I make >> result in
def fun(<cursor>):
?
Obviously, with ...
0
votes
1answer
136 views
Copy and paste with breakindent set
I'm using breakindent to make long lines wraparound to the same indentation level as the start of the line. Unfortunately, with this setting on system copy and paste (in this case, out of the macOS ...
3
votes
6answers
894 views
Indent on New Line between HTML/XML Tags
I'm currently using
imap <silent> <C-c> </<C-X><C-O><C-X><Esc>F<i
as per this post and this page to close <></> tags of any kind with <C-c&...
0
votes
1answer
91 views
Automatically reindent lines filtered through formatprg
I have following xml file:
<?xml version="1.0" encoding="UTF-8"?>
<graph id="G" edgedefault="undirected">
<edge id="e6" source="n5" target="n4"> <data key="d1">1.1</...
1
vote
0answers
38 views
expandtab tab as 2 spaces show visually as 6 columns
How can 2-space indenting be shown as 6 column tab-style indents when editing, while remaining as 2-spaces?
Background:
a team uses a convention of 2 spaces for indenting code
I prefer indenting of ...
1
vote
1answer
410 views
Incorrect auto-indent bash
Result of auto-indent in vim (filetype indent on)
main() {
case $1 in
--ssh)
echo "sshing into ${aws_ips[$1]}"
ssh -i VPN_NODE_1.pem ${aws_ips[$1]}
;;
--scp)
...
1
vote
1answer
144 views
How to stop “tab” key indenting whole line
In one version of VIM that I run, when I hit the "tab" key in insert mode, it indents the whole line, regardless of the cursors position in the line.
Here is what I believe to be the only modified ...
0
votes
1answer
244 views
Indentation command `gg=G` for 'compressed' HTML doesn't unfold tags
Sometimes I copy 'compressed' HTML from TEXTAREA an I get code for ex. like this:
<html><body><h1>header1</h1><p></p>
<p></p>
<div><p></...
1
vote
1answer
108 views
C++: different auto-indentation for function protoypes versus continuation lines
I have the following options setup for C++ and Python development in vim:
autocmd BufEnter *.cpp setlocal tabstop=4 shiftwidth=4 softtabstop=4 textwidth=80 noexpandtab cindent cinoptions=:0,l1,t0,g0,(...
1
vote
0answers
167 views
How to get html tag auto completion?
I can't seem to figure out how to implement auto tag completion for html.
Is there a plug-in or something else you guys use that works? Is there just one thing I can download that will handle ...
2
votes
2answers
2k views
How do I make the yaml indent not indent lists?
OK so I would like to change the way that my yaml gets indented.
Right now my vim indents a yaml list like this:
list:
- this
- is
- a list
dict:
this: is a dict
I would like it to indent ...
2
votes
1answer
233 views
NeoVim indents each property:value in CSS
I have a style element in an HTML file. When I type, NeoVim continuously indents each successive line:
In my Vim, it works correctly:
My vimrc.
I would be grateful for any suggestion. Thanks!
4
votes
0answers
61 views
Make Vim ignore first character in line while indenting
Whenever I have to edit Perl Mason files, I always have problems indenting lines due to Perl code starting with %. For example:
<div>
<div>
% if( !$something ) {
<...
1
vote
2answers
782 views
Keep the full visual selection after indenting in easy mode vim
What is the best way to indent multiple lines in insert mode?
Here is what I have currently:
vmap <Tab> >
vmap <S-Tab> <
The problem is that it doesn't properly handle selection ...
2
votes
1answer
43 views
indentkey '}' triggers with delay?
I have several indentkeys (like end, elseif...), all of the works fine but typing } triggers the reindentation with a 1s delay. It behaves the same if I disabled my 'indentexpr' and use 'cindent'.