什么autocmd FileType在.vimrc中?

时间:2013-12-30 13:25:13

标签: vim

我开始使用twitvim并找到this code code for .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 个答案:

答案 0 :(得分:5)

虽然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

答案 1 :(得分:3)

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

"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
相关问题