Hi,
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? I know it does syntax highlighting, so, I suppose it may
be able to format the code.
Thanks,
Maurício
Hi,
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? I know it does syntax highlighting, so, I suppose it may
be able to format the code.
Thanks,
Maurício
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? I know it does syntax highlighting, so, I suppose it may
be able to format the code.
The best way is to include the following in your .vimrc:
filetype plugin on "Turn ftplugins on
filetype indent on "Turn ftindent on
That will work for languages other than ruby, too.
-Michael
P.S. Note that you type those two lines verbatim. You can put them on
one line, like “filetype indent plugin on”. Happy vimming! ![]()
Michael Brailsford wrote:
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? (…)
The best way is to include the following in your .vimrc:
filetype plugin on "Turn ftplugins on
filetype indent on "Turn ftindent on
I’m really new to vim. After I insert those lines and restart vim,
how can I select a region of text and ask vim to indent it (I don’t like
it to do it automatically)?
Maurício
My VIM won’t eat those commands (version 6.1.213) …
ftplugins are incredibly nice. read ‘:help ftplugin’.
My $VIM/ftplugin/ruby.vim:
==== cut ====
setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal tabstop=2
setlocal indentexpr=GetRubyIndent()
setlocal tw=0
setlocal foldmethod=marker
" when writing a buffer chmod it executable
autocmd BufWritePost,FileWritePost * :silent !chmod 755
==== cut ====
Just read VIMs on-line help on those commands, it’s very good. ![]()
Happy VIMing, Have a nice day
Morten
On 2002-11-19 00:36:25 +0900, Michael Brailsford wrote:
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? I know it does syntax highlighting, so, I suppose it may
be able to format the code.The best way is to include the following in your .vimrc:
filetype plugin on "Turn ftplugins on
filetype indent on "Turn ftindent on
–
OpenPGP: 0xF1360CA9 – 8CF5 32EE A5EC 36B2 4E3F ACDF 6D86 BEB3 F136 0CA9
Morten Liebach m@mongers.org – http://m.mongers.org/
Maurício wrote:
Michael Brailsford wrote:
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? (…)The best way is to include the following in your .vimrc:
filetype plugin on "Turn ftplugins on
filetype indent on "Turn ftindent onI’m really new to vim. After I insert those lines and restart vim,
how can I select a region of text and ask vim to indent it (I don’t like
it to do it automatically)?
Move your cursor to the beginning of the block you want to indent, then press
‘v’ (visual mode) and move the cursor to the end of the block.
Now press ‘=’ to indent the selected block (of course you could have selected the
block with another command).
Regards,
Michael
I’m new to ruby and vim. Is it possible to ask vim to ident a piece
of ruby code? I know it does syntax highlighting, so, I suppose it may
be able to format the code.The best way is to include the following in your .vimrc:
filetype plugin on "Turn ftplugins on
filetype indent on "Turn ftindent onMy VIM won’t eat those commands (version 6.1.213) …
Huh? Do you mean that vim isn’t responding to those commands? It
clearly is, if ftplugins are working for you.
ftplugins are incredibly nice. read ‘:help ftplugin’.
My $VIM/ftplugin/ruby.vim:
==== cut ====
setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal tabstop=2
setlocal indentexpr=GetRubyIndent()
setlocal tw=0
setlocal foldmethod=marker" when writing a buffer chmod it executable
autocmd BufWritePost,FileWritePost * :silent !chmod 755
==== cut ====
Those are basically what gets set when you enable filetype indenting
with ruby. The exceptions being expandtab and foldmethod, which should
be set in your .vimrc.
I am currently running vim 6.1.213, the same as you, and I am not having
any problems with those two filetype commands. Perhaps I am just
misunderstanding you and it works just fine for you.
-Michael
On Wed, Nov 20, 2002 at 12:07:25AM +0900, Morten Liebach wrote:
On 2002-11-19 00:36:25 +0900, Michael Brailsford wrote:
awesome, I’d given up, finally these instructions worked ![]()
db
On Tue, Nov 19, 2002 at 01:45:29AM +0900, Michael Neumann wrote:
Maur?cio wrote:
The best way is to include the following in your .vimrc:
filetype plugin on "Turn ftplugins on
filetype indent on "Turn ftindent on
My $VIM/ftplugin/ruby.vim:
==== cut ====
setlocal expandtab
setlocal shiftwidth=2
setlocal softtabstop=2
setlocal tabstop=2
setlocal indentexpr=GetRubyIndent()
setlocal tw=0
setlocal foldmethod=marker" when writing a buffer chmod it executable
autocmd BufWritePost,FileWritePost * :silent !chmod 755
==== cut ====Those are basically what gets set when you enable filetype indenting
with ruby. The exceptions being expandtab and foldmethod, which should
be set in your .vimrc.
Setting expandtab and foldmethod in a filetype plugin is indeed appropriate,
since it then applies to files of that type (in this case, Ruby). However, I
would use the user’s ftplugin directory, not the system one (small matter,
I’m sure). i.e. ~/.vim/ftplugin/ruby.vim
Gavin
From: “Michael Brailsford” brailsmt@yahoo.com
Wed, 20 Nov 2002 08:19:11 +0900: Gavin Sinclair (“Gavin Sinclair”
gsinclair@soyabean.com.au):
From: “Michael Brailsford” brailsmt@yahoo.com
Setting expandtab and foldmethod in a filetype plugin is indeed
appropriate, since it then applies to files of that type (in this
case, Ruby). However, I would use the user’s ftplugin directory,
not the system one (small matter, I’m sure). i.e.
~/.vim/ftplugin/ruby.vim
Many VIM filetype plugins use vim variables to control whether folding
takes place and how to fold for that language.
unfortunately, the “official” ruby one distributed with VIM does not. It
also seems to use a hardcoded two-spaces for indentation where the
proper procedure would be to use tabs and let the user’s
tabstop/shiftwidth handle the rest. (If you do like indentation
automatically done as spaces, that’s easy to set up in vim independant
of the filetype plugin, too) Maybe sometime soon i’ll try to fix
those parts of it and see if i can get it accepted to the vim tree.
You can see perl/php examples with these lines in your ~/.vimrc:
filetype plugin indent on
set foldmethod=syntax
let perl_fold = 1 " allow folding
let php_folding = 1 " allow folding
–
< There is a light that shines on the frontier >
< And maybe someday, We’re gonna be there. >
< Rando Christensen / rando@babblica.net >
Actually, the VIM filetype plugin probably shouldn’t set the
indentation at all. While I’ve shifted to 2-space indentation
(because tabs are evil, and 4-space just gets too wide), it really
doesn’t belong in the “global” VIM filetype (more in a personal VIM
filetype). I may post my (slightly modified) Ruby VIM filetype/
syntax/etc. files to my website in the near future, along with
instructions on how to use them and set them up.
I also get folding and a bunch of other nice macros for doing Ruby.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.21 at 09.54.50
On Thu, 21 Nov 2002 22:27:25 +0900, Rando Christensen wrote:
Wed, 20 Nov 2002 08:19:11 +0900: Gavin Sinclair (“Gavin Sinclair”
gsinclair@soyabean.com.au ):From: “Michael Brailsford” brailsmt@yahoo.com
Setting expandtab and foldmethod in a filetype plugin is indeed
appropriate, since it then applies to files of that type (in this
case, Ruby). However, I would use the user’s ftplugin directory,
not the system one (small matter, I’m sure). i.e.
~/.vim/ftplugin/ruby.vim
Many VIM filetype plugins use vim variables to control whether
folding takes place and how to fold for that language.
unfortunately, the “official” ruby one distributed with VIM does
not. It also seems to use a hardcoded two-spaces for indentation
where the proper procedure would be to use tabs and let the user’s
tabstop/shiftwidth handle the rest.
Actually, the VIM filetype plugin probably shouldn’t set the
indentation at all.
Correct. The official one doesn’t, but most people don’t have that ![]()
While I’ve shifted to 2-space indentation
(because tabs are evil, and 4-space just gets too wide)
Careful! I’ve noticed that most of the code posted to the list uses tabs (it
renders badly in Outlook Express - reminding one of exactly why tabs are
evil - oops). Worse, a lot of it mixes tabs and spaces, the only thing nearly
everybody agrees one should not do.
, it really
doesn’t belong in the “global” VIM filetype (more in a personal VIM
filetype). I may post my (slightly modified) Ruby VIM filetype/
syntax/etc. files to my website in the near future, along with
instructions on how to use them and set them up.I also get folding and a bunch of other nice macros for doing Ruby.
It would be nice to see these - I’ll probably shamelessly steal some of them
for the official files.
There’s a page on the Wiki for VimExtensions, too.
Gavin
From: “Austin Ziegler” austin@halostatue.ca
Thu, 21 Nov 2002 23:59:04 +0900: Austin Ziegler (Austin Ziegler
austin@halostatue.ca):
Actually, the VIM filetype plugin probably shouldn’t set the
indentation at all. While I’ve shifted to 2-space indentation
Properly done, the indent file (located in indent/.vim) should
only tell /when/ to indent, not /how/. this is handled by the same vim
mechanisms that make < and > change your indentation, and you can set
your vim up to use two spaces, a tab that’d displayed as 2 spaces, a set
of eight spaces that works like tabs (as in, you hit tab to go 8 spaces,
it treats it like a tab, but it’s really 8 spaces in the file), etc etc
etc.
If a user doesn’t like that, they’d turn of the indentation part of the
filetyping. For example, I use:
filetype plugin indent on
To only use the filetyping, it would be:
filetype plugin on
I don’t know how off the top of my head, but it’s also fairly easy to
set the filetyping options on a per-filetype basis- you can have
perl/php/c/xml use the filetyping with indentation, and ruby only the
basic filetyping.
–
< There is a light that shines on the frontier >
< And maybe someday, We’re gonna be there. >
< Rando Christensen / rando@babblica.net >
Thu, 21 Nov 2002 23:59:04 +0900: Austin Ziegler (Austin Ziegler
austin@halostatue.ca):Actually, the VIM filetype plugin probably shouldn’t set the
indentation at all. While I’ve shifted to 2-space indentationProperly done, the indent file (located in indent/.vim) should
only tell /when/ to indent, not /how/.
Rest assured, that’s the way it is now.
Gavin
From: “Rando Christensen” rando@babblica.net
You should look for Ruby on Vim.org; I think that’s where I got a
couple of these. The rest I think I got from the Wiki.
-austin
– Austin Ziegler, austin@halostatue.ca on 2002.11.21 at 11.55.54
On Fri, 22 Nov 2002 00:33:36 +0900, Gavin Sinclair wrote:
I may post my (slightly modified) Ruby VIM filetype/ syntax/etc.
files to my website in the near future, along with instructions
on how to use them and set them up.I also get folding and a bunch of other nice macros for doing
Ruby.
It would be nice to see these - I’ll probably shamelessly steal
some of them for the official files.There’s a page on the Wiki for VimExtensions, too.