1

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

- 2018-2019 ICPC Southwestern European Regional Programming Contest (SWERC 2018)

it becomes

- 2018-2019 ICPC Northwestern European Regional Programming Contest (NWERC 2018)

    - 2020 ICPC Universidad Nacional de Colombia Programming Contest

- 2018-2019 ICPC Southwestern European Regional Programming Contest (SWERC 2018)

I have executed vim with no configuration files (vim -u NONE) and this still happens.

4
  • What does :verbose setlocal filetype? indentexpr? autoindent? cindent? softtabstop? tabstop? shiftwidth? expandtab? say?
    – D. Ben Knoble
    Oct 18 at 14:10
  • @D.BenKnoble I have executed vanilla vim without configurations, so it says filetype= indentexpr= noautoindent nocindent softtabstop=0 tabstop=8 shiftwidth=8 noexpandtab Oct 18 at 18:53
  • I'm guessing it's the parens in the first line. Probably being confused for a function or other code construct since Vim has a code-centric indentation scheme by default, I believe.
    – B Layer
    Oct 18 at 20:40
  • I missed :verbose setl equalprg?
    – D. Ben Knoble
    Oct 22 at 11:32
2
+100

This is a misuse of = operator.

Actually, Vim has two builtin "formatting" operators, i.e. = and gq (there's also gw that is simply the same as "internal" gq-formatter).

= is supposed for use with programming languages. Of course, it could be set up to do anything you like, but it defaults to C. Does it come as surprise? I don't think so.

So I suggest simply to stop using = for plain text formatting and switch to gq / gw instead.

If you still like doing it with =, you have to provide non-default values for indentexpr or equalprg, whichever you choose.

0

One way to do it is to use "fake" indentexpr value:

set indentexpr=-1

Having this applied to a filetype (or a buffer without filetype) will make == and friends (gg=G, =ip, etc) never change existing indentation.

I had similar problem with a mappings that move lines/selection up and down reindenting after each move (like if a line ends up in an if block, it is reindented properly). It worked OK for most of the filetypes but for some it didn't. Those were the ones with default indentation method -- and yes it was list like items too :).

upd

mappings were

" Move line up/down
nnoremap <silent> <C-j> :<C-u>silent! move+1<CR>==
nnoremap <silent> <C-k> :<C-u>silent! move-2<CR>==
" Move selected lines up/down
xnoremap <silent> <C-j> :move'>+<CR>gv=gv
xnoremap <silent> <C-k> :move-2<CR>gv=gv
2
  • Hey, would mind sharing that mapping somehow? It sounds great!
    – Biggybi
    Oct 22 at 18:11
  • 1
    @Biggybi, updated
    – Maxim Kim
    Oct 22 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.