We’re rewarding the question askers & reputations are being recalculated! Read more.
4

I've used vim-indent-object for a while with some success. It provides text objects like ii, ai, iI, and aI, each with slightly different semantics. For your sample code def some_method if @foo @bar = 42 # moooooore code... end end If the cursor is anywhere inside the if block, you could use vii to select the the bar and more lines. Or, use =...


4

I don't think there is an normal mode command to start a new line without indent. You can, however, remove the indent while in insert mode with the keystrokes 0Ctrl-D, and so it's easy to set up new mappings to do so: nnoremap <leader>o o0<C-D> nnoremap <leader>O O0<C-D> Personally, though, I'd install an indent plugin to handle ...


3

You can fix this with the following command: :set autoindent This causes the indent of the second line also to be used for the rest of the list item. Vim's included filetype plugin for Markdown formats bulleted lists using the 'comments' and 'formatoptions' settings. With q included in the formatoptions setting, Vim will allow the formatting of "comments"...


3

To override settings, you need to use the after directory. In this case, we need to know whether to use after/indent or after/ftplugin—use :verbose set <options we care about>? to find where they were last set, and pay attention to whether it was in the ftplugin or indent directory. We expect it to be indent in this case, but sometimes people do ...


3

As diagnosed through comments, you were probably using some generic indentation (such as Vim's cindent, which is likely to expect semi-colons to end statements.) In order to enable language-specific plugins for indentation, enable filetype detection and filetype indentation plugins, with: filetype plugin indent on


3

'indentexpr' has the highest priority of how vim can automatically indent lines. :h 'indentexpr': When this option is not empty, it overrules the 'cindent' and 'smartindent' indenting. Your value is indentexpr=GetTeXIndent(). Customize GetTeXIndent() The behavior of GetTeXIndent() can be customized by a few variables (e.g. g:tex_indent_brace or ...


3

Use :left From :h left: :[range]le[ft] [indent] Left-align lines in [range]. Sets the indent in the lines to [indent] (default 0). Not available when |+ex_extra| feature was disabled at compile time. You can also use :h center and :h right to align the current line to center and right.


3

Okay, let me first explain, what is happening here. When indenting lines, Vim will indent the line, which means depending on the 'shiftwidth', 'tabstop', 'expandtab' and possibly also the 'vartabstop' options determine whether to insert leading tabs or blanks into the line. When the 'startofline' option is at its default value, the cursor will be moved to ...


2

Plugin indentwise by jeetsukumaran Movements by Relative Indent-Depth [- : Move to previous line of lesser indent than the current line. [+ : Move to previous line of greater indent than the current line. [= : Move to previous line of same indent as the current line that is separated from the current line by lines of different indents. ]- : Move ...


2

jeetsukumaran/vim-indentwise works well for relative, absolute, or block-scope movements across indented blocks.


2

gll indents item right. glh indents item left.


2

Clarification: I am copy and pasting by selecting with the mouse and hitting Cmd-C, in order to get text into a different application. Okay, so you are basically copying the visual representation on your terminal. Since there is whitespace added, it will be copied as well. There is no way around that (it will also copy e.g. line numbers, signs or concealed ...


2

Open a C file and have a look at cinoptions set cinoptions? Most likely this is empty. Now add t0. set cinoptions+=t0 Reformat your C code, and the type should not be indented anymore. See :help 'cinoptions' and :help cinoptions-values. There you find that indenting the type by one 'shiftwidth' is the default (when on line for it own). If cinoptions is ...


2

According to the comments, set copyindent should do it


2

ctrl w w (hold ctrl, don't release) Note that you need to set :h 'backspace' to indent,eol,start for this to work . You can also use <backspace> or <c-u> instead of <c-w> if you want. The behavior is described in :h i_backspacing .


2

You can combine the > and < operators with % to indent blocks of code. The % key will jump to the matching parenthesis, bracket or brace if your cursor is sitting on one of these characters: (, ), [, ], { or }. For an example, say you have a block of code like this and you want to indent it: { stuff here } To indent the code block, put the ...


2

As stated in your comment you have cindent and cinoptions set like: set cindent set cinoptions=N-s,g0,:0,(0 The options cindent should only be set for the file types you want to use it. It is set automatically for the C or CPP file types (assuming you have filetype indent on in your vimrc [or better: filetype plugin indent on]). Remove the line set ...


2

This works with the options formatoptions and comments. Create the file .vim/after/ftplugin/rst.vim and add the following lines: setlocal comments+=b:- setlocal formatoptions+=ro For comments, the b:- adds the the dash as a comment character that has to be followed by a blank. See :help 'comments' and :help format-comments For formatoptions, the r ...


2

The easiest way is to change the keystrokes you use to start editing an empty line from a to cc. This allows the built-in cindent indentation to correctly adjust the indent when you enter insert mode, which it doesn't do when you specify that you want to append to the existing (blank) line. Note that this will only work if cindent is actually switched on. ...


2

All "long" jump commands, such as gg, automatically save the bookmark for the previous poisition (note that G here is a "motion", so it does not overwrite the bookmark again), so all you have to do is to go back by that bookmark with two backticks: nnoremap <leader>= gg=G`` Or you can use CTRLO and CTRLI to navigate through the jumplist (:h jumplist) ...


2

The command ]p does almost what you want, except it is not guaranteed to be linewise. In tpope/vim-unimpaired plugin it's already remapped to work linewise only, so if you use it (which I suggest anyway), you get it for free. Otherwise, you can implement the same trick yourself: nnoremap <silent>]p :call <SID>putline("]p")<CR> function ...


1

If you want to indent html, use the indent operator = with the inner-tag text object it: Place your cursor on the tag whose contents need indenting Press =it


1

Is sed an option? sed -r '/<blockquote>/,/<\/blockquote>/{s/^(\s\s\+)(<[^>].\{-}>)/\1 \2/g}'


1

I use two spaces in my indentation of codes. First off, you should set the 'shiftwidth' option to 2, to match the number of spaces you want to use as indentation. You will probably also want to set 'expandtab' so that Vim will keep using spaces for indentation once you get to 8 spaces (or whatever the tab size is set to.) So: :set shiftwidth=2 expandtab ...


1

Expanding on Rich's answer, here is my ready-to-roll solution with keymap and ignoring blank lines. function! ShowContext() abort let items = [] let l = line('.') let indent = 1000 while l >= 0 " added test to ignore blank lines if indent(l) < indent && getline(l) != '' call add(items, getline(l)) let indent = ...


1

I was intending to write an answer explaining how you might go about doing this, but when I embarked on doing so I ended up with a prototype implementation instead. Writing code is often more fun than writing documentation, I'm afraid! function! ShowContext() abort let items = [] let l = line('.') let indent = 1000 while l >= 0 if indent(l) &...


1

What if you just enable the filetype plugin? filetype plugin on


1

Read :h 'equalprg'—you can set this to, e.g., prettify for html filetypes by placing a setlocal in ~/.vim/after/ftplugin/html.vim. Then, use the = operator over a motion, text object, or Visual selection to prettyify that code.


1

This seems to work: function! ReplaceMiddleTabs() abort let s:linenum = line('.') let s:current_line = getline(s:linenum) let s:temp = Format_tabs(s:current_line) call setline(s:linenum, s:temp) endfunction function! Format_tabs(line) abort let s:tablen = &ts let s:start = match(a:line, '^\s\+\zs.\ze') let s:temp = a:line ...


1

Here is an example typing the following into vim --clean, with each option set: hello { world foo; bar } smartindent only: hello { world foo; bar } cindent only: hello { world foo; bar } As you can see with cindent, vim tries to continue lines that are incomplete (i.e., without semicolon). If your language is c-like, this ...


Only top voted, non community-wiki answers of a minimum length are eligible