No edit summary |
No edit summary |
||
Line 25: | Line 25: | ||
<SMALL>I have not verified these, but I only cleaned up [[User:DG12|DG12]] 19:06, 29 January 2008 (UTC) </small> |
<SMALL>I have not verified these, but I only cleaned up [[User:DG12|DG12]] 19:06, 29 January 2008 (UTC) </small> |
||
The original focus of this tip was related to pasting. |
The original focus of this tip was related to pasting. |
||
+ | |||
Most of the information (and the title) deal with various methods to stop auto indenting |
Most of the information (and the title) deal with various methods to stop auto indenting |
||
---- |
---- |
Revision as of 19:12, 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 cleaned up DG12 19:06, 29 January 2008 (UTC) The original focus of this tip was related to pasting.
Most of the information (and the title) deal with various methods to stop auto indenting
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