$39 GRAYBYTE WORDPRESS FILE MANAGER $50

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/usr/share/vim/vim80/doc/

HOME
Current File : /usr/share/vim/vim80/doc//usr_43.txt
*usr_43.txt*	For Vim version 8.0.  Last change: 2015 Oct 23

		     VIM USER MANUAL - by Bram Moolenaar

			       Using filetypes


When you are editing a file of a certain type, for example a C program or a
shell script, you often use the same option settings and mappings.  You
quickly get tired of manually setting these each time.  This chapter explains
how to do it automatically.

|43.1|	Plugins for a filetype
|43.2|	Adding a filetype

     Next chapter: |usr_44.txt|  Your own syntax highlighted
 Previous chapter: |usr_42.txt|  Add new menus
Table of contents: |usr_toc.txt|

==============================================================================
*43.1*	Plugins for a filetype				*filetype-plugin*

How to start using filetype plugins has already been discussed here:
|add-filetype-plugin|.  But you probably are not satisfied with the default
settings, because they have been kept minimal.  Suppose that for C files you
want to set the 'softtabstop' option to 4 and define a mapping to insert a
three-line comment.  You do this with only two steps:

							*your-runtime-dir*
1. Create your own runtime directory.  On Unix this usually is "~/.vim".  In
   this directory create the "ftplugin" directory: >

	mkdir ~/.vim
	mkdir ~/.vim/ftplugin
<
   When you are not on Unix, check the value of the 'runtimepath' option to
   see where Vim will look for the "ftplugin" directory: >

	set runtimepath

<  You would normally use the first directory name (before the first comma).
   You might want to prepend a directory name to the 'runtimepath' option in
   your |vimrc| file if you don't like the default value.

2. Create the file "~/.vim/ftplugin/c.vim", with the contents: >

	setlocal softtabstop=4
	noremap <buffer> <LocalLeader>c o/**************<CR><CR>/<Esc>
	let b:undo_ftplugin = "setl softtabstop< | unmap <buffer> <LocalLeader>c"

Try editing a C file.  You should notice that the 'softtabstop' option is set
to 4.  But when you edit another file it's reset to the default zero.  That is
because the ":setlocal" command was used.  This sets the 'softtabstop' option
only locally to the buffer.  As soon as you edit another buffer, it will be
set to the value set for that buffer.  For a new buffer it will get the
default value or the value from the last ":set" command.

Likewise, the mapping for "\c" will disappear when editing another buffer.
The ":map <buffer>" command creates a mapping that is local to the current
buffer.  This works with any mapping command: ":map!", ":vmap", etc.  The
|<LocalLeader>| in the mapping is replaced with the value of the
"maplocalleader" variable.

The line to set b:undo_ftplugin is for when the filetype is set to another
value.  In that case you will want to undo your preferences.  The
b:undo_ftplugin variable is executed as a command. Watch out for characters
with a special meaning inside a string, such as a backslash.

You can find examples for filetype plugins in this directory: >

	$VIMRUNTIME/ftplugin/

More details about writing a filetype plugin can be found here:
|write-plugin|.

==============================================================================
*43.2*	Adding a filetype

If you are using a type of file that is not recognized by Vim, this is how to
get it recognized.  You need a runtime directory of your own.  See
|your-runtime-dir| above.

Create a file "filetype.vim" which contains an autocommand for your filetype.
(Autocommands were explained in section |40.3|.)  Example: >

	augroup filetypedetect
	au BufNewFile,BufRead *.xyz	setf xyz
	augroup END

This will recognize all files that end in ".xyz" as the "xyz" filetype.  The
":augroup" commands put this autocommand in the "filetypedetect" group.  This
allows removing all autocommands for filetype detection when doing ":filetype
off".  The "setf" command will set the 'filetype' option to its argument,
unless it was set already.  This will make sure that 'filetype' isn't set
twice.

You can use many different patterns to match the name of your file.  Directory
names can also be included.  See |autocmd-patterns|.  For example, the files
under "/usr/share/scripts/" are all "ruby" files, but don't have the expected
file name extension.  Adding this to the example above: >

	augroup filetypedetect
	au BufNewFile,BufRead *.xyz			setf xyz
	au BufNewFile,BufRead /usr/share/scripts/*	setf ruby
	augroup END

However, if you now edit a file /usr/share/scripts/README.txt, this is not a
ruby file.  The danger of a pattern ending in "*" is that it quickly matches
too many files.  To avoid trouble with this, put the filetype.vim file in
another directory, one that is at the end of 'runtimepath'.  For Unix for
example, you could use "~/.vim/after/filetype.vim".
   You now put the detection of text files in ~/.vim/filetype.vim: >

	augroup filetypedetect
	au BufNewFile,BufRead *.txt			setf text
	augroup END

That file is found in 'runtimepath' first.  Then use this in
~/.vim/after/filetype.vim, which is found last: >

	augroup filetypedetect
	au BufNewFile,BufRead /usr/share/scripts/*	setf ruby
	augroup END

What will happen now is that Vim searches for "filetype.vim" files in each
directory in 'runtimepath'.  First ~/.vim/filetype.vim is found.  The
autocommand to catch *.txt files is defined there.  Then Vim finds the
filetype.vim file in $VIMRUNTIME, which is halfway 'runtimepath'.  Finally
~/.vim/after/filetype.vim is found and the autocommand for detecting ruby
files in /usr/share/scripts is added.
   When you now edit /usr/share/scripts/README.txt, the autocommands are
checked in the order in which they were defined.  The *.txt pattern matches,
thus "setf text" is executed to set the filetype to "text".  The pattern for
ruby matches too, and the "setf ruby" is executed.  But since 'filetype' was
already set to "text", nothing happens here.
   When you edit the file /usr/share/scripts/foobar the same autocommands are
checked.  Only the one for ruby matches and "setf ruby" sets 'filetype' to
ruby.


RECOGNIZING BY CONTENTS

If your file cannot be recognized by its file name, you might be able to
recognize it by its contents.  For example, many script files start with a
line like:

	#!/bin/xyz ~

To recognize this script create a file "scripts.vim" in your runtime directory
(same place where filetype.vim goes).  It might look like this: >

	if did_filetype()
	  finish
	endif
	if getline(1) =~ '^#!.*[/\\]xyz\>'
	  setf xyz
	endif

The first check with did_filetype() is to avoid that you will check the
contents of files for which the filetype was already detected by the file
name.  That avoids wasting time on checking the file when the "setf" command
won't do anything.
   The scripts.vim file is sourced by an autocommand in the default
filetype.vim file.  Therefore, the order of checks is:

	1. filetype.vim files before $VIMRUNTIME in 'runtimepath'
	2. first part of $VIMRUNTIME/filetype.vim
	3. all scripts.vim files in 'runtimepath'
	4. remainder of $VIMRUNTIME/filetype.vim
	5. filetype.vim files after $VIMRUNTIME in 'runtimepath'

If this is not sufficient for you, add an autocommand that matches all files
and sources a script or executes a function to check the contents of the file.

==============================================================================

Next chapter: |usr_44.txt|  Your own syntax highlighted

Copyright: see |manual-copyright|  vim:tw=78:ts=8:ft=help:norl:

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
16 Dec 2025 9.30 PM
root / root
0755
arabic.txt
11.656 KB
12 Oct 2025 7.23 AM
root / root
0644
autocmd.txt
63.869 KB
12 Oct 2025 7.23 AM
root / root
0644
change.txt
73.122 KB
12 Oct 2025 7.23 AM
root / root
0644
channel.txt
30.097 KB
12 Oct 2025 7.23 AM
root / root
0644
cmdline.txt
46.175 KB
12 Oct 2025 7.23 AM
root / root
0644
debug.txt
7.014 KB
12 Oct 2025 7.23 AM
root / root
0644
debugger.txt
5.609 KB
12 Oct 2025 7.23 AM
root / root
0644
develop.txt
21.82 KB
12 Oct 2025 7.23 AM
root / root
0644
diff.txt
16.138 KB
12 Oct 2025 7.23 AM
root / root
0644
digraph.txt
60.667 KB
12 Oct 2025 7.23 AM
root / root
0644
editing.txt
71.461 KB
12 Oct 2025 7.23 AM
root / root
0644
eval.txt
434.045 KB
12 Oct 2025 7.23 AM
root / root
0644
farsi.txt
9.476 KB
12 Oct 2025 7.23 AM
root / root
0644
filetype.txt
25.325 KB
12 Oct 2025 7.23 AM
root / root
0644
fold.txt
23.139 KB
12 Oct 2025 7.23 AM
root / root
0644
ft_ada.txt
17.819 KB
12 Oct 2025 7.23 AM
root / root
0644
ft_rust.txt
9.303 KB
12 Oct 2025 7.23 AM
root / root
0644
ft_sql.txt
29.975 KB
12 Oct 2025 7.23 AM
root / root
0644
gui.txt
44.523 KB
12 Oct 2025 7.23 AM
root / root
0644
gui_w32.txt
18.473 KB
12 Oct 2025 7.23 AM
root / root
0644
gui_x11.txt
28.789 KB
12 Oct 2025 7.23 AM
root / root
0644
hangulin.txt
3.214 KB
12 Oct 2025 7.23 AM
root / root
0644
hebrew.txt
5.58 KB
12 Oct 2025 7.23 AM
root / root
0644
help.txt
8.377 KB
12 Oct 2025 7.23 AM
root / root
0644
helphelp.txt
14.002 KB
12 Oct 2025 7.23 AM
root / root
0644
howto.txt
2.843 KB
12 Oct 2025 7.23 AM
root / root
0644
if_cscop.txt
18.907 KB
12 Oct 2025 7.23 AM
root / root
0644
if_lua.txt
14.299 KB
12 Oct 2025 7.23 AM
root / root
0644
if_mzsch.txt
11.546 KB
12 Oct 2025 7.23 AM
root / root
0644
if_ole.txt
7.231 KB
12 Oct 2025 7.23 AM
root / root
0644
if_perl.txt
10.888 KB
12 Oct 2025 7.23 AM
root / root
0644
if_pyth.txt
37.055 KB
12 Oct 2025 7.23 AM
root / root
0644
if_ruby.txt
7.826 KB
12 Oct 2025 7.23 AM
root / root
0644
if_sniff.txt
0.26 KB
12 Oct 2025 7.23 AM
root / root
0644
if_tcl.txt
22.486 KB
12 Oct 2025 7.23 AM
root / root
0644
indent.txt
38.503 KB
12 Oct 2025 7.23 AM
root / root
0644
index.txt
74.651 KB
12 Oct 2025 7.23 AM
root / root
0644
insert.txt
81.207 KB
12 Oct 2025 7.23 AM
root / root
0644
intro.txt
38.307 KB
12 Oct 2025 7.23 AM
root / root
0644
map.txt
63.152 KB
12 Oct 2025 7.23 AM
root / root
0644
mbyte.txt
57.916 KB
12 Oct 2025 7.23 AM
root / root
0644
message.txt
30.498 KB
12 Oct 2025 7.23 AM
root / root
0644
mlang.txt
7.666 KB
12 Oct 2025 7.23 AM
root / root
0644
motion.txt
50.393 KB
12 Oct 2025 7.23 AM
root / root
0644
netbeans.txt
36.131 KB
12 Oct 2025 7.23 AM
root / root
0644
options.txt
378.018 KB
12 Oct 2025 7.23 AM
root / root
0644
os_390.txt
4.642 KB
12 Oct 2025 7.23 AM
root / root
0644
os_amiga.txt
5.333 KB
12 Oct 2025 7.23 AM
root / root
0644
os_beos.txt
10.726 KB
12 Oct 2025 7.23 AM
root / root
0644
os_dos.txt
11.739 KB
12 Oct 2025 7.23 AM
root / root
0644
os_mac.txt
6.69 KB
12 Oct 2025 7.23 AM
root / root
0644
os_mint.txt
1.369 KB
12 Oct 2025 7.23 AM
root / root
0644
os_msdos.txt
0.506 KB
12 Oct 2025 7.23 AM
root / root
0644
os_os2.txt
0.287 KB
12 Oct 2025 7.23 AM
root / root
0644
os_qnx.txt
3.976 KB
12 Oct 2025 7.23 AM
root / root
0644
os_risc.txt
0.315 KB
12 Oct 2025 7.23 AM
root / root
0644
os_unix.txt
2.534 KB
12 Oct 2025 7.23 AM
root / root
0644
os_vms.txt
31.348 KB
12 Oct 2025 7.23 AM
root / root
0644
os_win32.txt
13.035 KB
12 Oct 2025 7.23 AM
root / root
0644
pattern.txt
57.931 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_getscript.txt
20.584 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_gzip.txt
1.29 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_logipat.txt
4.088 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_netrw.txt
171.436 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_paren.txt
2.216 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_spec.txt
4.025 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_tar.txt
6.077 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_vimball.txt
11.575 KB
12 Oct 2025 7.23 AM
root / root
0644
pi_zip.txt
6.87 KB
12 Oct 2025 7.23 AM
root / root
0644
print.txt
30.428 KB
12 Oct 2025 7.23 AM
root / root
0644
quickfix.txt
67.403 KB
12 Oct 2025 7.23 AM
root / root
0644
quickref.txt
69.586 KB
12 Oct 2025 7.23 AM
root / root
0644
quotes.txt
12.444 KB
12 Oct 2025 7.23 AM
root / root
0644
recover.txt
10.443 KB
12 Oct 2025 7.23 AM
root / root
0644
remote.txt
8.223 KB
12 Oct 2025 7.23 AM
root / root
0644
repeat.txt
38.646 KB
12 Oct 2025 7.23 AM
root / root
0644
rileft.txt
4.859 KB
12 Oct 2025 7.23 AM
root / root
0644
russian.txt
3.018 KB
12 Oct 2025 7.23 AM
root / root
0644
scroll.txt
13.741 KB
12 Oct 2025 7.23 AM
root / root
0644
sign.txt
6.729 KB
12 Oct 2025 7.23 AM
root / root
0644
spell.txt
61.31 KB
12 Oct 2025 7.23 AM
root / root
0644
sponsor.txt
7.029 KB
12 Oct 2025 7.23 AM
root / root
0644
starting.txt
71.896 KB
12 Oct 2025 7.23 AM
root / root
0644
syntax.txt
212.374 KB
12 Oct 2025 7.23 AM
root / root
0644
tabpage.txt
16.328 KB
12 Oct 2025 7.23 AM
root / root
0644
tags
320.952 KB
12 Oct 2025 7.23 AM
root / root
0644
tagsrch.txt
35.777 KB
12 Oct 2025 7.23 AM
root / root
0644
term.txt
44.352 KB
12 Oct 2025 7.23 AM
root / root
0644
terminal.txt
32.78 KB
12 Oct 2025 7.23 AM
root / root
0644
tips.txt
20.074 KB
12 Oct 2025 7.23 AM
root / root
0644
todo.txt
289.324 KB
12 Oct 2025 7.23 AM
root / root
0644
uganda.txt
13.695 KB
12 Oct 2025 7.23 AM
root / root
0644
undo.txt
16.151 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_01.txt
6.924 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_02.txt
23.769 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_03.txt
23.052 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_04.txt
18.635 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_05.txt
23.266 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_06.txt
9.362 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_07.txt
15.609 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_08.txt
18.92 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_09.txt
11.182 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_10.txt
28.496 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_11.txt
12.315 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_12.txt
13.109 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_20.txt
13.382 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_21.txt
17.942 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_22.txt
13.962 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_23.txt
12.293 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_24.txt
20.38 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_25.txt
18.666 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_26.txt
8.061 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_27.txt
17.308 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_28.txt
15.64 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_29.txt
19.645 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_30.txt
22.125 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_31.txt
10.15 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_32.txt
5.247 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_40.txt
22.641 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_41.txt
87.208 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_42.txt
13.475 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_43.txt
7.23 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_44.txt
28.526 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_45.txt
17.492 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_90.txt
17.247 KB
12 Oct 2025 7.23 AM
root / root
0644
usr_toc.txt
9.002 KB
12 Oct 2025 7.23 AM
root / root
0644
various.txt
28.176 KB
12 Oct 2025 7.23 AM
root / root
0644
version4.txt
13.58 KB
12 Oct 2025 7.23 AM
root / root
0644
version5.txt
301.312 KB
12 Oct 2025 7.23 AM
root / root
0644
version6.txt
563.527 KB
12 Oct 2025 7.23 AM
root / root
0644
version7.txt
658.951 KB
12 Oct 2025 7.23 AM
root / root
0644
version8.txt
668.215 KB
12 Oct 2025 7.23 AM
root / root
0644
vi_diff.txt
41.809 KB
12 Oct 2025 7.23 AM
root / root
0644
visual.txt
21.331 KB
12 Oct 2025 7.23 AM
root / root
0644
windows.txt
51.787 KB
12 Oct 2025 7.23 AM
root / root
0644
workshop.txt
4.522 KB
12 Oct 2025 7.23 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF