golden hour
/usr/share/vim/vim82/doc
⬆️ Go Up
Upload
File/Folder
Size
Actions
arabic.txt
11.62 KB
Del
OK
autocmd.txt
70.53 KB
Del
OK
change.txt
76.22 KB
Del
OK
channel.txt
49.13 KB
Del
OK
cmdline.txt
48.19 KB
Del
OK
debug.txt
6.73 KB
Del
OK
debugger.txt
5.32 KB
Del
OK
develop.txt
22.33 KB
Del
OK
diff.txt
16.63 KB
Del
OK
digraph.txt
60.53 KB
Del
OK
editing.txt
72.42 KB
Del
OK
eval.txt
528.52 KB
Del
OK
farsi.txt
523 B
Del
OK
filetype.txt
26.95 KB
Del
OK
fold.txt
23.13 KB
Del
OK
ft_ada.txt
17.82 KB
Del
OK
ft_rust.txt
9.37 KB
Del
OK
ft_sql.txt
29.98 KB
Del
OK
gui.txt
51.5 KB
Del
OK
gui_w32.txt
19 KB
Del
OK
gui_x11.txt
29.21 KB
Del
OK
hangulin.txt
598 B
Del
OK
hebrew.txt
5.53 KB
Del
OK
help.txt
8.69 KB
Del
OK
helphelp.txt
15.36 KB
Del
OK
howto.txt
2.85 KB
Del
OK
if_cscop.txt
18.87 KB
Del
OK
if_lua.txt
16.36 KB
Del
OK
if_mzsch.txt
11.66 KB
Del
OK
if_ole.txt
7.19 KB
Del
OK
if_perl.txt
11.02 KB
Del
OK
if_pyth.txt
37.53 KB
Del
OK
if_ruby.txt
8.32 KB
Del
OK
if_sniff.txt
271 B
Del
OK
if_tcl.txt
22.41 KB
Del
OK
indent.txt
41.29 KB
Del
OK
index.txt
78.75 KB
Del
OK
insert.txt
83.29 KB
Del
OK
intro.txt
38.06 KB
Del
OK
map.txt
69.14 KB
Del
OK
mbyte.txt
58.24 KB
Del
OK
message.txt
30.69 KB
Del
OK
mlang.txt
8 KB
Del
OK
motion.txt
50.14 KB
Del
OK
netbeans.txt
37.09 KB
Del
OK
options.txt
382.14 KB
Del
OK
os_390.txt
4.64 KB
Del
OK
os_amiga.txt
5.34 KB
Del
OK
os_beos.txt
293 B
Del
OK
os_dos.txt
12.09 KB
Del
OK
os_haiku.txt
8.39 KB
Del
OK
os_mac.txt
6.7 KB
Del
OK
os_mint.txt
391 B
Del
OK
os_msdos.txt
523 B
Del
OK
os_os2.txt
299 B
Del
OK
os_qnx.txt
3.98 KB
Del
OK
os_risc.txt
328 B
Del
OK
os_unix.txt
2.54 KB
Del
OK
os_vms.txt
32.13 KB
Del
OK
os_win32.txt
13.04 KB
Del
OK
pattern.txt
58.73 KB
Del
OK
pi_getscript.txt
20.59 KB
Del
OK
pi_gzip.txt
1.26 KB
Del
OK
pi_logipat.txt
4.1 KB
Del
OK
pi_netrw.txt
175.08 KB
Del
OK
pi_paren.txt
2.22 KB
Del
OK
pi_spec.txt
4.03 KB
Del
OK
pi_tar.txt
6.65 KB
Del
OK
pi_vimball.txt
11.58 KB
Del
OK
pi_zip.txt
7.12 KB
Del
OK
popup.txt
38.55 KB
Del
OK
print.txt
30.3 KB
Del
OK
quickfix.txt
80.98 KB
Del
OK
quickref.txt
70.45 KB
Del
OK
quotes.txt
12.45 KB
Del
OK
recover.txt
10.47 KB
Del
OK
remote.txt
8.22 KB
Del
OK
repeat.txt
41.2 KB
Del
OK
rileft.txt
4.82 KB
Del
OK
russian.txt
2.95 KB
Del
OK
scroll.txt
13.46 KB
Del
OK
sign.txt
25.25 KB
Del
OK
spell.txt
62.6 KB
Del
OK
sponsor.txt
7.03 KB
Del
OK
starting.txt
71.87 KB
Del
OK
syntax.txt
220.57 KB
Del
OK
tabpage.txt
16.84 KB
Del
OK
tags
346.5 KB
Del
OK
tagsrch.txt
39.33 KB
Del
OK
term.txt
46.38 KB
Del
OK
terminal.txt
54.79 KB
Del
OK
testing.txt
14.6 KB
Del
OK
textprop.txt
13.09 KB
Del
OK
tips.txt
20.57 KB
Del
OK
todo.txt
302.17 KB
Del
OK
uganda.txt
13.7 KB
Del
OK
undo.txt
16.2 KB
Del
OK
usr_01.txt
6.92 KB
Del
OK
usr_02.txt
23.66 KB
Del
OK
usr_03.txt
23.31 KB
Del
OK
usr_04.txt
18.68 KB
Del
OK
usr_05.txt
26.39 KB
Del
OK
usr_06.txt
9.39 KB
Del
OK
usr_07.txt
15.62 KB
Del
OK
usr_08.txt
18.92 KB
Del
OK
usr_09.txt
11.23 KB
Del
OK
usr_10.txt
28.52 KB
Del
OK
usr_11.txt
12.72 KB
Del
OK
usr_12.txt
13.11 KB
Del
OK
usr_20.txt
13.39 KB
Del
OK
usr_21.txt
18.02 KB
Del
OK
usr_22.txt
14.65 KB
Del
OK
usr_23.txt
12.45 KB
Del
OK
usr_24.txt
20.34 KB
Del
OK
usr_25.txt
18.73 KB
Del
OK
usr_26.txt
8.07 KB
Del
OK
usr_27.txt
17.29 KB
Del
OK
usr_28.txt
15.64 KB
Del
OK
usr_29.txt
19.65 KB
Del
OK
usr_30.txt
22.13 KB
Del
OK
usr_31.txt
10.16 KB
Del
OK
usr_32.txt
5.25 KB
Del
OK
usr_40.txt
22.65 KB
Del
OK
usr_41.txt
95.1 KB
Del
OK
usr_42.txt
13.53 KB
Del
OK
usr_43.txt
7.24 KB
Del
OK
usr_44.txt
28.27 KB
Del
OK
usr_45.txt
17.27 KB
Del
OK
usr_46.txt
6.93 KB
Del
OK
usr_90.txt
16.44 KB
Del
OK
usr_toc.txt
9.28 KB
Del
OK
various.txt
30.37 KB
Del
OK
version4.txt
13.58 KB
Del
OK
version5.txt
301.3 KB
Del
OK
version6.txt
563.42 KB
Del
OK
version7.txt
658.89 KB
Del
OK
version8.txt
1.85 MB
Del
OK
vi_diff.txt
56.08 KB
Del
OK
vim9.txt
55.82 KB
Del
OK
visual.txt
21.28 KB
Del
OK
windows.txt
54.43 KB
Del
OK
workshop.txt
371 B
Del
OK
Edit: usr_43.txt
*usr_43.txt* For Vim version 8.2. 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:noet:ft=help:norl:
Save