在 .vimrc 文件中,autocmd FileType 是什么?

6

我开始使用twitvim,并找到了这篇.vimrc配置文件的代码

但是我不确定代码的最后一部分是在尝试做什么。

autocmd FileType twitvim call s:twitvim_my_settings()
function! s:twitvim_my_settings()
  set nowrap
endfunction

这是原始代码。我删除了所有的<C-u><C-w>j

""" twitvim
let twitvim_count = 40
nnoremap ,tp :<C-u>PosttoTwitter<CR>
nnoremap ,tf :<C-u>FriendsTwitter<CR><C-w>j
nnoremap ,tu :<C-u>UserTwitter<CR><C-w>j
nnoremap ,tr :<C-u>RepliesTwitter<CR><C-w>j
nnoremap ,tn :<C-u>NextTwitter<CR>
autocmd FileType twitvim call s:twitvim_my_settings()
function! s:twitvim_my_settings()
  set nowrap
endfunction
2个回答

22

虽然Kent的答案是正确和详细的,但我想提交一个可视化版本。

autocmd FileType twitvim call s:twitvim_my_settings()
|______________________| |__| | |___________________|
           |               |  |          |
           1               2  3          4   

1. Automatically do something when the FileType (the file extension) matches .twitvim
2. call (Vim's way to run a function)
3. Refers to a function local to the current script file
4. The function to be ran

9

我虽然不使用这个插件,但我可以尝试解释这些行的含义:

"this just assigning a variable, may be used by the plugin
let twitvim_count = 40  

" create a normal mode mapping, to execute Posttotwitter command.
" The leading ctrl-u just for removing the range information of the 
"command line. if you removed it, range info will be kept
" all following commands have the same meaning for <c-u>
nnoremap ,tp :<C-u>PosttoTwitter<CR>
" the next 4 commands are same as above, but executing different cmd. the ctrl-w j will move cursor
" to  a "belower" window, the cmd may open a new window/split.
nnoremap ,tf :<C-u>FriendsTwitter<CR><C-w>j
nnoremap ,tu :<C-u>UserTwitter<CR><C-w>j
nnoremap ,tr :<C-u>RepliesTwitter<CR><C-w>j
nnoremap ,tn :<C-u>NextTwitter<CR>

"create autocmd, if the filetype is twitvim, call a function
autocmd FileType twitvim call s:twitvim_my_settings()

"here a function was defined
function! s:twitvim_my_settings()
  "this function just do one thing, set nowrap option. (text is gonna be displayed without wrap.)
  set nowrap
endfunction

感谢您的帮助。Q1:范围信息是什么意思?Q2:“belower”窗口是什么意思?Q3:文件类型是指myfile.twitvim吗?它有扩展名吗?Q4:所以我应该保留<C-u>,<C-w>等吗? - shin
1
@shin A1: :%s/foo/bar/' 是一个命令,% 是范围,C-u 将删除该部分,这意味着自定义命令将自行处理范围。A2: 我猜测你的插件命令会创建一个窗口分割,并在执行后将光标移动到该窗口下方,分割线将位于当前的:h Ctrl-w_j下方。A3: 是的。A4: 是的,如果你不知道自己在做什么,以及可能产生的后果,我建议将其保持原样。我建议你阅读一些帮助文档,以便更好地理解这些内容。Vim 有很棒的帮助文档! - Kent

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接