[vim/vim] Don't undo indents added by autoindent, perhaps add a new cpoptions character (#7941)

14 views
Skip to first unread message

reportaman

unread,
Mar 9, 2021, 6:04:05 AM3/9/21
to vim/vim, Subscribed

At times I like to create a few blank lines at the right indent level, and then fill them all together later. Currently autoindent, even with cpoptions+=I enabled, deletes the just added indent after hitting <CR>. This way at any given point, only one blank line has the right indent level.

Example, after entering <CR> 3 times at the end of line containing let hello=world, there should be 3 indented lines below it. Then, as I move the cursor with <Up>/<Down>, it should move to the position where dots . are in the following code block.

if foo==bar
    let hello=world
    .
    .
    .   
endif


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

Bram Moolenaar

unread,
Mar 9, 2021, 3:47:03 PM3/9/21
to vim/vim, Subscribed

I don't think there are more than a few users who would want to use this, adding "yet another option" is not really desired.
You can probably make it work like this:
:inoremap .

Bram Moolenaar

unread,
Mar 9, 2021, 3:47:54 PM3/9/21
to vim/vim, Subscribed

Hmm, github eats the angle brackets. Another try:

:inormap <CR> .<BS><CR>

reportaman

unread,
Mar 9, 2021, 3:54:46 PM3/9/21
to vim/vim, Subscribed

@brammool I believe you got be wrong, the full stops . are only to indicate where cursor lands if one were to press <Up>/<Down> after entering 3 <CR>'s. Currently if I press <CR> thrice this is how it looks, and do <Up> the cursor moves to left column 0, and I need to hit tab again to get to reindent it.

if foo==bar
    let hello=world
..
..
    .   
endif

reportaman

unread,
Mar 9, 2021, 4:05:34 PM3/9/21
to vim/vim, Subscribed

@brammool This still doesn't fully work... Let's say after pressing <CR> three times, I hit <Up> arrow key, it deletes indent from the last line that was indented.

Gary Johnson

unread,
Mar 9, 2021, 4:16:39 PM3/9/21
to reply+ACY5DGDJKBM635MKXO...@reply.github.com, vim...@googlegroups.com
On 2021-03-09, reportaman wrote:
> @brammool This still doesn't fully work... Let's say after pressing <CR> three
> times, I hit <Up> arrow key, it deletes indent from the last line that was
> indented.
>
> if foo==bar
> let hello=world
> .
> .
> .
> endif

:inormap <Up> .<BS><Up>

HTH,
Gary

vim-dev ML

unread,
Mar 9, 2021, 4:17:02 PM3/9/21
to vim/vim, vim-dev ML, Your activity

On 2021-03-09, reportaman wrote:
> @brammool This still doesn't fully work... Let's say after pressing <CR> three
> times, I hit <Up> arrow key, it deletes indent from the last line that was
> indented.
>
> if foo==bar
> let hello=world
> .
> .
> .
> endif

:inormap <Up> .<BS><Up>

HTH,
Gary

reportaman

unread,
Mar 9, 2021, 4:21:54 PM3/9/21
to vim/vim, vim-dev ML, Mention

@vim-ml That doesn't work either. This worked: inoremap <CR> .<BS><CR><Left><Right>, quite interesting business...


You are receiving this because you were mentioned.

reportaman

unread,
Mar 9, 2021, 4:40:29 PM3/9/21
to vim/vim, vim-dev ML, Mention

Closed #7941.


You are receiving this because you were mentioned.

Bram Moolenaar

unread,
Mar 9, 2021, 4:43:57 PM3/9/21
to vim/vim, vim-dev ML, Mention

You can use any character instead of the dot, it just means that something was inserted and the won't remove the auto-indent. The auto-indent is removed because it looks like the user wants an empty line, and trailing white space is undesired in 99% of the cases.


You are receiving this because you were mentioned.

reportaman

unread,
Mar 9, 2021, 4:57:07 PM3/9/21
to vim/vim, vim-dev ML, Mention

@brammool Thanks! As a side-note regarding predicting user intent, someone is already generating vim commands using OpenAI GPT3 model:

https://jameslu.substack.com/p/using-gpt-3-to-generate-vim-commands


You are receiving this because you were mentioned.

Orestes Kassian

unread,
Apr 22, 2025, 6:59:32 PM4/22/25
to vim/vim, vim-dev ML, Mention

Depending on how you're creating the new line (ex. I mainly use 'o'), add a simple keymap
vim.keymap.set('n', 'o', 'o<Left><Right>', { noremap = true, silent = true })


Reply to this email directly, view it on GitHub.
You are receiving this because you were mentioned.Message ID: <vim/vim/issues/7941/2822649785@github.com>

OrestesK left a comment (vim/vim#7941)

Depending on how you're creating the new line (ex. I mainly use 'o'), add a simple keymap
vim.keymap.set('n', 'o', 'o<Left><Right>', { noremap = true, silent = true })


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you were mentioned.Message ID: <vim/vim/issues/7941/2822649785@github.com>

journaljemmy

unread,
Sep 2, 2026, 12:00:39 AM (yesterday) Sep 2
to vim/vim, vim-dev ML, Mention
journaljemmy left a comment (vim/vim#7941)

I'd like to add that the autoindent is also removed if you use the up or down arrow key after creating the new line. So it's not just ‘move and it doesn't happen’ it's ‘move left or right and it doesn't happen’. That's is an insane amount of mental overhead when all I want to do is a normal mode operation on my new autoindented line.

I think that undoing an autoindent in the first place is a terrible feature. If you want to be picky with lines that consist of spaces, they should be removed when saving the file not when I'm trying to do something in normal mode on my autoindented line. 100% of the time that an autoindent is undone, I find myself indenting as my next operation. Surely that's a massive red flag.


Reply to this email directly, view it on GitHub, or unsubscribe.

Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you were mentioned.Message ID: <vim/vim/issues/7941/5504159563@github.com>

Reply all
Reply to author
Forward
0 new messages