Wikia

Vim Tips Wiki

Changes: Restoring indent after typing hash

Edit

Back to page

(Adjust previous/next navigation)
(9 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Duplicate|1019}}
+
{{Duplicate|1019}} {{review}} {{TipImported
{{review}}
 
{{TipImported
 
 
|id=1327
 
|id=1327
 
|previous=1326
 
|previous=1326
Line 10: Line 10:
 
|category1=
 
|category1=
 
|category2=
 
|category2=
}}
+
}} The default behavior of the 'autoindent' option is as follow:
The default behavior of the 'autoindent' option is as follow:
 
   
:Copy indent from current line when starting a new line (typing <CR> in Insert mode or when using the "o" or "O" command). If you do not type anything on the new line except <BS> or CTRL-D and then type <Esc> or <CR>, the indent is deleted again.
+
:Copy indent from current line when starting a new line (typing &lt;CR&gt; in Insert mode or when using the "o" or "O" command). If you do not type anything on the new line except &lt;BS&gt; or CTRL-D and then type &lt;Esc&gt; or &lt;CR&gt;, the indent is deleted again.
   
 
I find that behavior quite annoying since the cursor jumps to the left when empty lines are inserted and 'escape' is pressed. Fortunately, it is possible to force Vim to keep the indentation with the following lines in your vimrc:
 
I find that behavior quite annoying since the cursor jumps to the left when empty lines are inserted and 'escape' is pressed. Fortunately, it is possible to force Vim to keep the indentation with the following lines in your vimrc:
Line 23: Line 23:
   
 
==Comments==
 
==Comments==
  +
Thank you. This tip is very helpful. I was getting very annoyed with Vim deleting the blank lines because it interferes with the way I type.
  +
  +
The way I type the following is: <code>class A extends B {<CR><CR>}<Up><Tab>A() {<CR><CR>}<Up><Tab>super();</code>
  +
<pre>
  +
class A extends B {
  +
A() {
  +
super();
  +
}
  +
}
  +
</pre>
  +
  +
I assume most other people do this: <code>class A extends B {<CR><Tab>A() {<CR><Tab>super();<CR><BS>}<CR><BS>}</code>. I wouldn't say either way of typing is better than the other, since they both require the same number of keystrokes.
  +
  +
----

Revision as of 07:52, August 15, 2009

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 1327 Printable Monobook Previous Next

created September 10, 2006 · complexity basic · author Decker · version 5.7


The default behavior of the 'autoindent' option is as follow:
Copy indent from current line when starting a new line (typing <CR> in Insert mode or when using the "o" or "O" command). If you do not type anything on the new line except <BS> or CTRL-D and then type <Esc> or <CR>, the indent is deleted again.

I find that behavior quite annoying since the cursor jumps to the left when empty lines are inserted and 'escape' is pressed. Fortunately, it is possible to force Vim to keep the indentation with the following lines in your vimrc:

inoremap <CR> <CR><Space><BS>
nnoremap o o<Space><BS>
nnoremap O O<Space><BS>

Comments

Thank you. This tip is very helpful. I was getting very annoyed with Vim deleting the blank lines because it interferes with the way I type.

The way I type the following is: class A extends B {<CR><CR>}<Up><Tab>A() {<CR><CR>}<Up><Tab>super();

class A extends B {
    A() {
        super();
    }
}

I assume most other people do this: class A extends B {<CR><Tab>A() {<CR><Tab>super();<CR><BS>}<CR><BS>}. I wouldn't say either way of typing is better than the other, since they both require the same number of keystrokes.


Around Wikia's network

Random Wiki