Contents
- 1 How to indent a whole file in Vim?
- 2 How to get the start of a file in Vim?
- 3 How to format and return the same line in Vim?
- 4 What’s the best way to indent a HTML file?
- 5 Can you set shiftwidth to 2 in Vim?
- 6 How to indent test with HTML vimrc Thomas?
- 7 When to use s instead of I in Vim?
- 8 Can a file be added to a.vim file?
- 9 How to stop Vim automatically inserting a…?
How to indent a whole file in Vim?
This one will auto indent the whole file and still keep your cursor in the position you are: Just go to visual mode in vim , and select from up to down lines after selecting just press = , All the selected line will be indented. For vi Editor, use :insert.
How to set up autoindentation in Vim on Windows?
Especially if you are using windows, where the file could be named _vimrc instead of .vimrc as on other platforms. Make sure you are only using one file. If you want to split your configuration into smaller chunks you can source other files from inside your _vimrc file.
How to get the start of a file in Vim?
So, gg to get the start of the file, = to indent, G to the end of the file, gg=G. Before pasting into the terminal, try :set paste and then :set nopaste after you’re done.
Which is the correct configuration file for Vim?
A simpler option: just uncomment the following part of the configuration (which is originally commented out) in the /etc/vim/vimrc file: Ensure you are editing the correct configuration file for VIM. Especially if you are using windows, where the file could be named _vimrc instead of .vimrc as on other platforms.
How to format and return the same line in Vim?
To format and return the same line where you were, just add this mapping to your vimrc : Now, just press whenever you want to format your file. Note, the = operator works using whatever automatic indentation settings you have turned on. If you don’t have this set up, see indenting source code before using.
When to use P instead of P in Vim?
First, if the code in the buffer is formatted, but at a different level of indentation, I use ]p instead of p, which pastes the code as is, but with the indentation shifted such that the first line pasted is the same depth as the line I’m on. vim puts the while at the same indentation level as int i.
What’s the best way to indent a HTML file?
You can use tidy application/utility to indent HTML & XML files and it works pretty well in indenting those files. 1G=G. That should indent all the lines in the file. 1G takes you the first line, = will start the auto-indent and the final G will take you the last line in the file.
How can I change the indent size?
As a bonus see :h ‘smartindent’ and :h ‘autoindent’ which are pretty useful. In fact, aside from other answers, it was also possible to use autoindent (to automatically indent newlines) and smartindent (wich reacts to the synthax of the code).
Can you set shiftwidth to 2 in Vim?
Yes. You can set shiftwidth to any number of spaces. This works both in vi and vim. Now, the width shifted for each >> and << will be 2. Shorthand for J.Chomel’s answer. Next, append tabstop and shiftwidth with your preferences to the .vimrc file.
How to disable gg-g in HTML Vim?
Use /searchstring/I to disable temporarily. set ignorecase ” Need this for some plugins to work.
How to indent test with HTML vimrc Thomas?
Indent test “.vimrc ” Thomas ” ” This file contains tips and ideas from a wide variety of sources.
What does gg = g do in Vim?
In normal mode, typing gg=G will reindent the entire file. This is a special case; = is an operator. Just like d or y, it will act on any text that you move over with a cursor motion command. In this case, gg positions the cursor on the first line, then =G re-indents from the current cursor position to the end of the buffer.
When to use s instead of I in Vim?
Vim will automatically kill any whitespace to the right of the cursor if you break a line in two while autoindent (or any other indentation aid) is enabled. If you do not want to use any of those settings, use s instead of i in order to s ubstitute your new text for the blank rather than just inserting.
How to insert a newline before the cursor in Vim?
[Ctrl+V] means “quote the following character” — it allows you to embed the newline and escape characters in the command. So you’re mapping the ‘g’ key to the sequence: This is vim for insert a newline before the cursor, then exit insert mode.
Can a file be added to a.vim file?
You can add .vim files to be executed whenever vim switches to a particular filetype. For example, I have a file ~/.vim/after/ftplugin/html.vim with this contents:
What causes Vim to use tabs with 2 characters?
Which causes vim to use tabs with a width of 2 characters for indenting (the noexpandtab option is set globally elsewhere in my configuration). This is described here: http://vimdoc.sourceforge.net/htmldoc/usr_05.html#05.4, scroll down to the section on filetype plugins.
How to stop Vim automatically inserting a…?
If you simply want to disable auto-indent system wise, for every file type (basically, disable the auto-indent feature completely), you can do the following: IMPORTANT NOTE: Modifying system files is not recommended. It can have unexpected side effect. Also, the modification is likely to be overwritten on the next vim update.