Line 23: | Line 23: | ||
==Comments== |
==Comments== |
||
− | <SMALL>I have not verified these, but I only tried to clean up |
+ | <SMALL>I have not verified these, but I only tried to clean up [[User:DG12|DG12]] 19:06, 29 January 2008 (UTC) </small> |
⚫ | |||
− | |||
− | + | Adding the following lines to your .vimrc will turn off ALL indenting for the given file types: |
|
autocmd BufEnter *.html setlocal indentexpr= |
autocmd BufEnter *.html setlocal indentexpr= |
||
autocmd BufEnter *.htm setlocal indentexpr= |
autocmd BufEnter *.htm setlocal indentexpr= |
||
Line 31: | Line 31: | ||
autocmd BufEnter *.xsd setlocal indentexpr= |
autocmd BufEnter *.xsd setlocal indentexpr= |
||
− | + | Change the above to the file type (extension) necessary. |
|
⚫ | |||
− | |||
− | + | Put the following line in the file .vimrc in your home directory: |
|
filetype off |
filetype off |
||
⚫ | |||
− | |||
− | + | modify $VIMRUNTIME/filetype.vim, find the section for the file type in question and start commenting or deleting sections. |
|
− | |||
---- |
---- |
||
:set pastetoggle=<F11> |
:set pastetoggle=<F11> |
||
− | |||
---- |
---- |
||
:set noai |
:set noai |
||
:set noautoindent |
:set noautoindent |
||
− | + | renamed the html.vim file in the indent directory to html_vim. |
|
Syntax highlighting still works but the indenting is disabled |
Syntax highlighting still works but the indenting is disabled |
||
− | |||
---- |
---- |
||
Add in your vimrc: |
Add in your vimrc: |
||
Line 69: | Line 66: | ||
</pre> |
</pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | --- |
||
+ | With set mouse=a option (which allows using the mouse for visual select, scrolling etc) |
||
⚫ | |||
+ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | |||
⚫ | |||
---- |
---- |
||
⚫ | |||
⚫ | |||
+ | ---- |
||
⚫ | |||
:set nocindent<CR> |
:set nocindent<CR> |
||
:set cinoptions=<CR> |
:set cinoptions=<CR> |
||
− | |||
---- |
---- |
||
− | + | Add all these options at the bottom of your vimrc file. |
|
If you want the settings in the default vimrc file that comes with the official distribution of vim but want autoindening turned off, place these options at the bottom of the vimrc file. |
If you want the settings in the default vimrc file that comes with the official distribution of vim but want autoindening turned off, place these options at the bottom of the vimrc file. |
||
Line 87: | Line 105: | ||
filetype indent off |
filetype indent off |
||
filetype plugin indent off |
filetype plugin indent off |
||
− | |||
---- |
---- |
||
− | + | force vim to use my ~/.vimrc file by aliasing vim to 'vim -u ~/.vimrc'. |
|
⚫ | |||
− | |||
⚫ | |||
this doesn't seem to be the case for vim. |
this doesn't seem to be the case for vim. |
||
− | |||
---- |
---- |
||
− | |||
filetype off |
filetype off |
||
− | |||
---- |
---- |
||
rename "[program files]/vim/vim63/indent" to "indent_" |
rename "[program files]/vim/vim63/indent" to "indent_" |
||
− | |||
---- |
---- |
||
− | + | renaming /usr/share/vim/indent directory to indent_ |
|
.vimrc isn't the last resource file to be handled settings are being overwritten by resource files for the different languages later |
.vimrc isn't the last resource file to be handled settings are being overwritten by resource files for the different languages later |
||
− | |||
---- |
---- |
||
for copy-paste'ing formatted text have a look at [[VimTip21]] |
for copy-paste'ing formatted text have a look at [[VimTip21]] |
||
− | |||
---- |
---- |
||
"set paste" in ~/.vimrc |
"set paste" in ~/.vimrc |
||
− | |||
---- |
---- |
||
− | |||
⚫ | |||
− | " Paste Mode On/Off |
||
− | map <F11> :call Paste_on_off()<CR> |
||
− | set pastetoggle=<F11> |
||
− | let paste_mode = 0 " 0 = normal, 1 = paste |
||
− | func! Paste_on_off() |
||
− | if g:paste_mode == 0 |
||
− | set paste |
||
− | let g:paste_mode = 1 |
||
⚫ | |||
− | set nopaste |
||
− | let g:paste_mode = 0 |
||
⚫ | |||
− | return |
||
− | endfunc |
||
⚫ | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
⚫ | |||
− | |||
filetype indent off |
filetype indent off |
||
set smartindent |
set smartindent |
||
for editing PHP or any programming language that is embedded in HTML without having the indenting on the HTML. |
for editing PHP or any programming language that is embedded in HTML without having the indenting on the HTML. |
||
− | |||
---- |
---- |
||
If you are editing PHP code containing HTML and don't want HTML to be indented you may use my PHP indent script (that only indents PHP and javascript code, non-PHP code remain as it is): |
If you are editing PHP code containing HTML and don't want HTML to be indented you may use my PHP indent script (that only indents PHP and javascript code, non-PHP code remain as it is): |
||
Line 149: | Line 131: | ||
You can find a detail description of what it can do there: {{script|id=1120}} |
You can find a detail description of what it can do there: {{script|id=1120}} |
||
or http://www.2072productions.com/?to=phpindent.txt |
or http://www.2072productions.com/?to=phpindent.txt |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | A function that does the toggling of both: |
||
− | |||
− | <pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
− | else |
||
⚫ | |||
⚫ | |||
− | endif |
||
⚫ | |||
− | </pre> |
||
− | |||
⚫ | |||
---- |
---- |
||
Line 181: | Line 142: | ||
:r !pbpaste | perl -pe 'tr/\r/\n/' |
:r !pbpaste | perl -pe 'tr/\r/\n/' |
||
− | |||
---- |
---- |
||
:set pastetoggle=<F11> to vimrc |
:set pastetoggle=<F11> to vimrc |
||
− | |||
---- |
---- |
||
− | |||
filetype plugin indent off |
filetype plugin indent off |
||
with this line alone, vi will use the indentation of current line |
with this line alone, vi will use the indentation of current line |
||
if current indentation level is 2 (=8 columns using "set tabstop=4"), the next line inserted will also be at indentation 2 (i.e o, O, and <CR>). |
if current indentation level is 2 (=8 columns using "set tabstop=4"), the next line inserted will also be at indentation 2 (i.e o, O, and <CR>). |
||
− | |||
---- |
---- |
||
:set noai |
:set noai |
||
− | + | doesn't work for pasting |
|
The shortest solution is above: |
The shortest solution is above: |
||
Line 202: | Line 159: | ||
and use F11 shift-insert F11 for a 3-keypress insertion on Linux. |
and use F11 shift-insert F11 for a 3-keypress insertion on Linux. |
||
− | |||
---- |
---- |
||
⚫ | |||
− | <pre> |
||
+ | set nocindent |
||
⚫ | |||
− | set |
+ | set nosmartindent |
− | set |
+ | set autoindent |
− | set |
+ | set indentexpr= |
⚫ | |||
− | set indentexpr= |
||
− | filetype indent off |
+ | filetype plugin indent off |
⚫ | |||
− | </pre> |
||
which allows the simple and useful "make the next line the same indent level as the previous line" sort of autoindent, but disables all the annoying so-called 'smart' indentation which is confusing and makes wrong assumptions about my preferred style. |
which allows the simple and useful "make the next line the same indent level as the previous line" sort of autoindent, but disables all the annoying so-called 'smart' indentation which is confusing and makes wrong assumptions about my preferred style. |
||
− | |||
---- |
---- |
||
(vim 6.4, Windows installer, default everything) |
(vim 6.4, Windows installer, default everything) |
||
Line 221: | Line 174: | ||
Default behaviour in edit mode (PHP file type) is for the first, and only the first, press of the ">" key to indent the current line by several spaces. Subsequent key presses just insert the ">" symbol. |
Default behaviour in edit mode (PHP file type) is for the first, and only the first, press of the ">" key to indent the current line by several spaces. Subsequent key presses just insert the ">" symbol. |
||
Leaving and then re-entering edit mode, again causes the first ">" key press to further indent the line. |
Leaving and then re-entering edit mode, again causes the first ">" key press to further indent the line. |
||
+ | ---- |
||
− | |||
− | revise C:\Program Files\Vim\vim64\indent\php.vim |
+ | revise C:\Program Files\Vim\vim64\indent\php.vim so that the line: |
− | |||
− | so that the line: |
||
setlocal indentkeys+=0=,0),=EO,=> |
setlocal indentkeys+=0=,0),=EO,=> |
||
is replaced by: |
is replaced by: |
||
setlocal indentkeys+=0=,0),=EO |
setlocal indentkeys+=0=,0),=EO |
||
− | |||
− | this second line may be there but commented out. |
||
− | |||
---- |
---- |
||
/indent/ then editing the file for the extension that i wanted to turn autoindent off. |
/indent/ then editing the file for the extension that i wanted to turn autoindent off. |
||
Line 237: | Line 185: | ||
commented out anything set using setlocal indentexpr, and setlocal indentkeys. |
commented out anything set using setlocal indentexpr, and setlocal indentkeys. |
||
− | + | html.vim file now looks like this: |
|
− | |||
− | <pre> |
||
... |
... |
||
− | setlocal indentexpr= "HtmlIndentGet(v:lnum) |
+ | setlocal indentexpr= "HtmlIndentGet(v:lnum) |
− | setlocal indentkeys= "o,O,*<Return>,<>>,<bs>,{,} |
+ | setlocal indentkeys= "o,O,*<Return>,<>>,<bs>,{,} |
... |
... |
||
− | </pre> |
||
− | |||
(note: the double qoute comments out the rest of the line) |
(note: the double qoute comments out the rest of the line) |
||
− | |||
---- |
---- |
||
− | + | placed in .vimrc, got rid of most of the autoindentation stuff: |
|
filetype plugin indent off |
filetype plugin indent off |
Revision as of 19:06, 29 January 2008
created September 20, 2002 · complexity intermediate · author Francis · version 6.0
Sometimes when pasting formated text (source code or HTML etc) into a buffer, Vim indents it again, so that lines will be padded with too much space.
See VimTip906 for the correct way to avoid this problem (the following paragraph from the original tip 330 is correct, but tip 906 shows the intended way to turn 'paste' off and on).
Setting nocindent, noautoindent, nosmartindent still cannot stop this. All you need to do is :set paste, then paste your stuff, and then :set nopaste again.
TODO Merge useful info from this tip into VimTip906. Need a better explanation that the problem is only seen on systems which emulate pasting by inserting text into the keyboard buffer, so Vim thinks the text has been typed by the user. If you use Vim commands to paste text, the problem does not occur.
References
Comments
I have not verified these, but I only tried to clean up DG12 19:06, 29 January 2008 (UTC)
Adding the following lines to your .vimrc will turn off ALL indenting for the given file types:
autocmd BufEnter *.html setlocal indentexpr= autocmd BufEnter *.htm setlocal indentexpr= autocmd BufEnter *.xml setlocal indentexpr= autocmd BufEnter *.xsd setlocal indentexpr=
Change the above to the file type (extension) necessary.
Put the following line in the file .vimrc in your home directory:
filetype off
modify $VIMRUNTIME/filetype.vim, find the section for the file type in question and start commenting or deleting sections.
:set pastetoggle=<F11>
:set noai :set noautoindent
renamed the html.vim file in the indent directory to html_vim.
Syntax highlighting still works but the indenting is disabled
Add in your vimrc:
" Paste Mode On/Off map <F11> :call Paste_on_off()<CR> set pastetoggle=<F11> let paste_mode = 0 " 0 = normal, 1 = paste func! Paste_on_off() if g:paste_mode == 0 set paste let g:paste_mode = 1 else set nopaste let g:paste_mode = 0 endif return endfunc
F11 will toggle 'paste' mode.
map <F11> :set invpaste<CR>
F11 - Shift-Insert - F11 to paste from the system clipboard (linux). --- With set mouse=a option (which allows using the mouse for visual select, scrolling etc)
things don't behave as well as before when pasting from the clipboard (middle click won't paste etc).
" toggle paste / mouse mode map <F11> :call InvertPasteAndMouse()<CR> fun! InvertPasteAndMouse() if &mouse == '' set mouse=a | set nopaste echo "mouse mode on, paste mode off" else set mouse= | set paste echo "mouse mode off, paste mode on" endif endfunction
F11 to toggle paste (& mouse) mode.
gvim for Windows, deleting all the contents of the "indent" folder
Windows :
:set nocindent<CR> :set cinoptions=<CR>
Add all these options at the bottom of your vimrc file. If you want the settings in the default vimrc file that comes with the official distribution of vim but want autoindening turned off, place these options at the bottom of the vimrc file.
set nocindent set nosmartindent set noautoindent set indenexpr= filetype indent off filetype plugin indent off
force vim to use my ~/.vimrc file by aliasing vim to 'vim -u ~/.vimrc'. .rc files in a user's home directory should be read last and should override other settings, this doesn't seem to be the case for vim.
filetype off
rename "[program files]/vim/vim63/indent" to "indent_"
renaming /usr/share/vim/indent directory to indent_
.vimrc isn't the last resource file to be handled settings are being overwritten by resource files for the different languages later
for copy-paste'ing formatted text have a look at VimTip21
"set paste" in ~/.vimrc
filetype indent off set smartindent
for editing PHP or any programming language that is embedded in HTML without having the indenting on the HTML.
If you are editing PHP code containing HTML and don't want HTML to be indented you may use my PHP indent script (that only indents PHP and javascript code, non-PHP code remain as it is):
You can find a detail description of what it can do there: script#1120 or http://www.2072productions.com/?to=phpindent.txt
set nosmartindent
Mac-only solution:
:r !pbpaste
fix the line-endings:
:r !pbpaste | perl -pe 'tr/\r/\n/'
:set pastetoggle=<F11> to vimrc
filetype plugin indent off
with this line alone, vi will use the indentation of current line if current indentation level is 2 (=8 columns using "set tabstop=4"), the next line inserted will also be at indentation 2 (i.e o, O, and <CR>).
:set noai
doesn't work for pasting
The shortest solution is above:
map <F11> :set invpaste<CR>
and use F11 shift-insert F11 for a 3-keypress insertion on Linux.
" disable 'smart' indent
set nocindent set nosmartindent set autoindent set indentexpr= filetype indent off filetype plugin indent off
which allows the simple and useful "make the next line the same indent level as the previous line" sort of autoindent, but disables all the annoying so-called 'smart' indentation which is confusing and makes wrong assumptions about my preferred style.
(vim 6.4, Windows installer, default everything)
Default behaviour in edit mode (PHP file type) is for the first, and only the first, press of the ">" key to indent the current line by several spaces. Subsequent key presses just insert the ">" symbol. Leaving and then re-entering edit mode, again causes the first ">" key press to further indent the line.
revise C:\Program Files\Vim\vim64\indent\php.vim so that the line:
setlocal indentkeys+=0=,0),=EO,=>
is replaced by:
setlocal indentkeys+=0=,0),=EO
/indent/ then editing the file for the extension that i wanted to turn autoindent off.
commented out anything set using setlocal indentexpr, and setlocal indentkeys.
html.vim file now looks like this: ...
setlocal indentexpr= "HtmlIndentGet(v:lnum) setlocal indentkeys= "o,O,*<Return>,<>>,<bs>,{,}
... (note: the double qoute comments out the rest of the line)
placed in .vimrc, got rid of most of the autoindentation stuff:
filetype plugin indent off
not when editing a .txt file, 'vim -u ~/.vimrc' shell alias did fix the problem, but it also broke other settings.
using Gentoo: rename /etc/vim