vim:一些命令和选项 filetype, autocmd, map,tabstop等

1.filetype

Filetypes *filetypes* *file-types*
Vim can detect the type of file that is edited. This is done by checking the file name and sometimes by inspecting the contents of the file for specific
text.
*:filetype* *:filet*
To enable file type detection, use this command in your vimrc: >
:filetype on
Each time a new or existing file is edited, Vim will try to recognize the type of the file and set the 'filetype' option. This will trigger the FileType
event, which can be used to set the syntax highlighting, set options, etc.
Detail: The ":filetype on" command will load one of these files:
Amiga $VIMRUNTIME/filetype.vim
Mac $VIMRUNTIME:filetype.vim
MS-DOS $VIMRUNTIME\filetype.vim
RiscOS Vim:Filetype
Unix $VIMRUNTIME/filetype.vim
VMS $VIMRUNTIME/filetype.vim
This file is a Vim script that defines autocommands for the BufNewFile and BufRead events . If the file type is not found by the
name, the file $VIMRUNTIME/scripts.vim is used to detect it from the contents of the file.

You can enable loading the plugin files for specific file types with: >
:filetype plugin on
If filetype detection was not switched on yet, it will be as well.This actually loads the file "ftplugin.vim" in 'runtimepath'. The result is that when a file is edited its plugin file is loaded (if there is one for the detected filetype). |filetype-plugin|
*:filetype-plugin-off*
You can disable it again with: >
:filetype plugin off
The filetype detection is not switched off then. But if you do switch off filetype detection, the plugins will not be loaded either.This actually loads the file "ftplugof.vim" in 'runtimepath'.

You can enable loading the indent file for specific file types with: >
:filetype indent on
If filetype detection was not switched on yet, it will be as well.This actually loads the file "indent.vim" in 'runtimepath'. The result is that when a file is edited its indent file is loaded (if there is one for the detected filetype). |indent-expression|
*:filetype-indent-off*
You can disable it again with: >
:filetype indent off
The filetype detection is not switched off then. But if you do switch off filetype detection, the indent files will not be loaded either.This actually loads the file "indoff.vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.

filetype plugin on那也会 打开filetype,如果filetype都off了, plugin on 有意义么,上面也说不会load

To see the current status, type: >
:filetype
The output looks something like this: >
filetype detection:ON plugin:ON indent:OFF
'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.

The file types are also used for syntax highlighting. If the ":syntax on" command is used, the file type detection is installed too. There is no need
to do ":filetype on" after ":syntax on".



使用filetype 需要 set nocompatible


2. map相关命令

转自https://www.douban.com/group/topic/10866937/

我主要讲解一下“n(普通模式)”下的两个绑定命令,等看完之后就对应的明白别的模式下的命令了。 
适用于普通模式的映射命令主要有: 
1. :map 
[语法] :map {lhs} {rhs} |mapmode-nvo| *:map* 
1.1 作用模式: n、v、o (普通、可视和选择、操作符等待) 
1.2 命令格式: 
:map {lhs} {rhs} 
含义: 在:map作用的模式中把键系列 {lhs} 映射为 {rhs},{rhs}可进行映射扫描,也就是可递归映射。 
1.3 举例: 
:map td :tabnew . 
含义:在其作用模式(普通、可视、操作符)下,输入td等价于输入 :tabnew . 。而普通模式下输入:tabnew . 就是打开当前目录 
如果再定义绑定 :map ts td,就是指在其作用模式下输入ts等价于td,也就是打开当前目录。不过如果没有特殊需要,一般不建议递归映射。 

2. :noremap 
:moremap和:map命令相对,作用模式和命令格式都相同,只不过不允许再对{rhs}进行映射扫描,也就是{lhs}定义后的映射就是{rhs}的键序列,不会再对{rhs}键序列重新解释扫描。它一般用于重定义一个命令,当然如果:map不需要递归映射的话,建议试用:noremap 
比如: 
:noremap ts td 
它的意思是在其作用模式下,输入ts就是输入td,但是和:map不同的是,此时td再不会做进一步扫描解释。虽然之前已经定义了td,但是不会对td再做扫描 

5. :nmap 
:nmap是:map的普通模式板,也就是说其绑定的键只作用于普通模式。 
例如: 
:nmap td :tabnew . 和 :map td :tabnew . 在普通模式下等效 
6. :nnoremap 
:nnorempa和:nmap的关系和:noremap和:map的关系一样,只是:nmap的非递归版 

另外: 
{rhs} 之前可能显示一个特殊字符: 
* 表示它不可重映射 
& 表示仅脚本的局部映射可以被重映射 
@ 表示缓冲区的局部映射 

特殊参数: 

1.  
2.  
3.  
4.

你可能感兴趣的:(vim)