5

I have set autoindent in my .vimrc

Say I'm on an indented line in Vim in insert mode. If I make a bunch of new lines by pressing enter, it'll keep my cursor indented. However, lines between my current line and the original line lose their indents. This doesn't happen with Notepad++

| indicates the indent on the empty lines.

Vim:

function f()
{
    var x;
|
|
|
    |//cursor

Notepad++:

function f()
{
    var x;
    |
    |
    |
    |//cursor

How do I get Vim to behave like Notepad++?

Linny
  • 333
  • 1
  • 2
  • 10
  • Do you really want to have all those trailing white spaces? – romainl Jul 27 '15 at 05:26
  • possible duplicate of [stopping vim from removing indentation on empty lines](http://stackoverflow.com/questions/7413036/stopping-vim-from-removing-indentation-on-empty-lines) – ryuichiro Jul 27 '15 at 06:06

2 Answers2

1

Try this and let me know if it fixes your problem.

** In normal mode **

:set smartindent

** Or in your .vimrc file add this **

set smartindent
  • Nope. I didn't notice any difference. – Linny Jul 26 '15 at 23:55
  • Linny, what version vim are you using? – newbydewbydew Jul 26 '15 at 23:56
  • Interesting...I've got 7.3, tested your scenario, and smartindent worked for me. The only other command that might work is cindent. This guy seems to be having similar issues with that version...http://stackoverflow.com/questions/19323607/html-indenting-not-working-in-compiled-vim-7-4-any-ideas – newbydewbydew Jul 27 '15 at 12:31
0

I have these settings in my .vimrc to auto indent:

" Auto indent.
filetype indent on
filetype plugin indent on
set smartindent
autocmd BufRead,BufWritePre *.py normal gg=G
set expandtab
set tabstop=2
set shiftwidth=2
set autoindent

Please note that the "*.py" in "autocmd..." is for python file, you can change it to .sh or .cpp that fit you best.

Reyomi
  • 73
  • 6