shin
shin

Reputation: 32721

What autocmd FileType is in .vimrc?

I started using twitvim and found this code code for .vimrc.

But I am not sure what the last part of code is trying to do.

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

And this is the original code. I deleted all of <C-u>, <C-w> and 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

Upvotes: 7

Views: 14291

Answers (2)

krystah
krystah

Reputation: 3733

While Kent's answer is correct and very detailed, I thought I'd submit a visual version.

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

Upvotes: 23

Kent
Kent

Reputation: 195269

I don't use the plugin, but I could try to explain what the meaning of those lines:

"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

Upvotes: 10

Related Questions