Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all. I've been using Vim for a while, and I love it with all my heart. At work, however, the terminal sucks (X-Win for remote login from a Windows ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252

    Vim Indentation [SOLVED]


    Hi all.

    I've been using Vim for a while, and I love it with all my heart. At work, however, the terminal sucks (X-Win for remote login from a Windows machine), so Vim looks horrible. Therefore, I've been using Emacs.

    In Emacs, lines will automatically indent themselves to the proper length, and a closing bracket will automatically fall back to where it should be.

    So basically, I'm curious if this can be done in Vim. I've checked Vim Tips and the FAQ and I see nothing. But when I was typing something at home this morning, I realized how much I miss this feature.

    So yeah...does anyone know if it's possible?


    Thanks.

  2. #2
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Location
    Lat: 39:03:51N Lon: 77:14:37W
    Posts
    2,396
    Hey, use

    :set autoindent
    :set smartindent

    should get you going

    :set all

    will list all the possible vim features (including some that can set or modify the window, might make VIM usable at work.

    The Vim Cookbook is a great reference for random vim tips and tricks.

    The smartindent might not meet your needs exactly, I just tried it on some C sytle formatting (with a .c file loaded) from scratch (ie, no .vim file specified) this might not work correctly. The easiest way to tell if Vim has properly identified you file is to turn syntax highlighting on

    :syntax on

    (if this turn up nothing, save the file and open it, also make sure you have installed the vim-rt package) this autodetection of filetype is done by filename extentions (not perfect, but they are all filetype/text-plain...) so be aware that custom extensions might throw it.

    Cheers

    EDIT: almost forgot, to make these changes perminent, add them to the
    ~/.vimrc

    file, everything in there is run when that user opens Vim, so should you discover any other nifty features or settings you like, just add them to that .
    Avoid the Gates of Hell. Use Linux
    A Penny for your Thoughts

    Formerly Known as qub333

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    Yeah, syntax highlighting works (not in the terminal, where all text is yellow, but in gvim), but I was really hoping for this feature.

    Of course, now that I also have autoindenting to where the last line was, I may not even need this...

    Either way, thanks a bunch.

  4. #4
    Linux Guru kkubasik's Avatar
    Join Date
    Mar 2004
    Location
    Lat: 39:03:51N Lon: 77:14:37W
    Posts
    2,396
    The 'smartindent' feature will return brackets to the same level for some coding styles. See:

    http://www.vim.org/htmldoc/options.html#'smartindent'

    note that you need to compile with +smartindent, I can't be 100% certain on what gentoo does, can't be positive if it complies it in (see the ebuild here:
    http://gentoo-portage.com/ebuild?e=a...ld&browse=true

    hope it helps ya
    Avoid the Gates of Hell. Use Linux
    A Penny for your Thoughts

    Formerly Known as qub333

  5. #5
    scm
    scm is offline
    Linux Engineer
    Join Date
    Feb 2005
    Posts
    1,044
    "set sw=4" (shiftwidth) is useful to avoid running out of screen width.
    Use Ctl-D to cancel one level of indent; there's also a way to cancel the indent just for a single line, but I can't recall the command at the moment. Anyone?

    And if you're writing a document, "set wm=8" (wrapmargin) will cause lines to autowrap before they hit the edge of the screen.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •