vim smart-indenting for filetypes other than C

This is a discussion on vim smart-indenting for filetypes other than C within the Tech Board forums, part of the Community Boards category; Hello to all (this is my first post) I am currently learning C and a little bit of Fortran programming. ...

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    55

    vim smart-indenting for filetypes other than C

    Hello to all (this is my first post)

    I am currently learning C and a little bit of Fortran programming. I am mainly using vim and I have seen that smart-indenting is an excellent help for writing c programs, but cannot figure out how to emable this when writing fortran code. (even when I open a .f,... file and not starting from scratch)

    Q1. I have read from the manuals that autocmd has to be enabled at compile time for the smart indenting of the different filetypes. I am using fedora core 3 and I am not sure if vim was compiled with autocmd or not. How do I check this?

    Q2. If autocmd is enabled as default, then how do I import eg. fortran.vim indenting file to vim, so that it could smart indent fortran code

    Thanks in advance

    Spiros

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    You need to find and edit the fortran.vim file. This is the file that tells vim what to do when it comes to color formatting (aka syntax highlighting) and indention.

    Mine was located in:
    /usr/share/vim/vim61/indent/

    You can look at the c.vim for an example.

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    55
    Thanks for the reply Thantos,

    I do know that there is a file for each language with specific indenting settings and I have already lokked at these. My problem is how to load these to vim. Furthermore, from the vim help files, I read that autocmd has to be enabled during compilation in order for these files to work. Problem is that I don't know how to check if autocmd was enabled (and also on the level of feaures from the feature.h file)

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Does it work when you use a c file?

    edit: type "vim --version" and it will give you a list of the build options.
    Last edited by Thantos; 11-24-2004 at 09:25 AM.

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    55
    Thanks! :version shows that autocmd has been included (also in help->version, ...stupid of me)

    as for c files, smart-indenting works. I don't need to do anyting because support for c is built in vim (as the c.vim file says).
    When i load up a fortran file, highlighting works fine, but not the smart-indenting (if that helps...)

    cheers for your time on this!

  6. #6
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    ok I didn't look at the c.vim before saying to use it as an example

    if you have it look at perl.vim it has some code for indenting perl code.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Posts
    55
    ok, I did that, but I can't see anything that helps me

    Code:
    " Only load this indent file when no other was loaded.
    if exists("b:did_indent")
      finish
    endif
    let b:did_indent = 1
    this is at the start of each indent file, the problem is how to load a specific indent file...

    EDIT: just saw your avatar! Al Pitrelli rocks!, heard of savatage, skolnick,....? savatage is one of my favourite bands,... but back to geeky stuff now...
    Last edited by s_siouris; 11-24-2004 at 10:26 AM.

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    So you didn't notice the
    Code:
    setlocal indentexpr=GetPerlIndent()
    setlocal indentkeys+=0=,0),0=or,0=and
    if !b:indent_use_syntax
      setlocal indentkeys+=0=EO
    endif
    
    " Only define the function once.
    if exists("*GetPerlIndent")
      finish
    endif
    
    function GetPerlIndent()
    
      " Get the line to be indented
      let cline = getline(v:lnum)
    
      " Indent POD markers to column 0
      if cline =~ '^\s*=\L\@!'
        return 0
      endif
    
      " Don't reindent coments on first column
      if cline =~ '^#.'
        return 0
      endif
    etc

    In the perl.vim file? fortran.vim is being loaded when you start vim if the fortran syntax highlighting is working like you said.

    Edit:
    just saw your avatar! Al Pitrelli rocks!
    pssst click the link in my sig about my avatar.

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    55
    sorry but to be honest, that doesn't say much to me. I am just starting to learn how to program in c (been studying couple of months) the most complicated thing i've done is pointers to pointers (not done linked lists yet) and very little in fortran.
    when I load a fortran file, (supposing that the indenting file is loaded) I expect for example that in a FOR loop, when I am at the end of the line where FOR is written, and press enter, the cursor will indent a bit more that the previous line, but it doesn't. This is ok in c programs. Autoindenting works ok, highlighting ok as well, but no smart-indent for filetypes other than c.

    when you load up a file, do you get smart-indenting without doing anything? (eg such as in perl that you mentioned?)

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Well the perl one was already written. So to do what you want you'll have to modify the fortran.vim file to take care of those cases. Or find someone that already has done it.

  11. #11
    Registered User
    Join Date
    Nov 2004
    Posts
    55
    ok I'll try to sort it out, although I do think that this smart-indenting example is pretty basic hence should have been the first thing to be impplemented in the fortran.vim indenting file.

    thanks for your help

    Spiros

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. VIM: The (un)official thread
    By MK27 in forum Programming Book and Product Reviews
    Replies: 32
    Last Post: 04-20-2011, 07:43 PM
  2. Which smart pointer to use?
    By leeor_net in forum C++ Programming
    Replies: 4
    Last Post: 04-13-2009, 05:29 AM
  3. vim question - linux
    By Stonehambey in forum Tech Board
    Replies: 9
    Last Post: 10-18-2008, 05:05 AM
  4. smart pointer release
    By George2 in forum C++ Programming
    Replies: 24
    Last Post: 02-13-2008, 08:51 AM
  5. Intelligent vs Smart
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 07-18-2004, 02:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21