On 11/14/2010 04:42 AM, rameo wrote:
I would like to do this with a map (let say CTRL-K) and cycle through
a number of filetypes settings, p.e.:

1st CTRL-K -->  set filetype=vim
2nd CTRL-K -->  set filetype=html
3rd CTRL-K -->  set filetype=txt
4th CTRL-K -->  set filetype=    (empty)

I know that I need an array to do this but I do not know how to cycle
through the array using a map.

Not too hard.  First, set up the array of various filetypes you want:

  :let types=['vim', 'html', 'txt', '']

Then create a mapping to update the value of 'filetype' to the next item in the list with wraparound:

:nnoremap <f4> :let &ft=types[(index(types, &ft) + 1) % len(types)]<cr>:set ft?<cr>

That uses the index() function to look up the current type. If it exists, an index of 0 to len(types)-1 is returned. Add 1 to that. The "% len(types)" performs modulo arithmetic so that when you hit the end (the blank value in this case) the index+1 rolls back to 0.

I also include reporting of the new value to make it clearer...if you don't want that, you can remove the trailing ":set ft?<cr>" bit of the mapping.

Hope this helps,

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to