Want to try living in vim

March 8th, 2007

I’ve been an Emacs user for many years, though of course I know some vi and vim commands out of necessity.

I want to try taking the plunge by spending a month using vim only, no Emacs.

Sadly the vim documentation isn’t very helpful for me in a number of areas. I’m hoping someone can point me to some resources or recipes that will help with:

  • Turning off that stupid “hide most of the Debian changelog” thing. I have no idea why it does that or how to make it stop.
  • Turn on or off autoindent, syntax highlighting, etc. in various languages (really, I want to set global defaults for all of them)
  • Be able to edit another file without closing or saving the first (:e doesn’t seem to do what I want)
  • Integrate it with Mercurial and Darcs

Categories: Programming

Leave a comment

Comments Feed17 Comments

  1. Helmut Grohne

    :set nofoldenable ” will expand your chanelog

    Do you want :new instead of :e?

    Hope that helps

    Helmut

    Reply

  2. Christian Hergert

    > Turn on or off autoindent, syntax highlighting, etc. in various languages (really, I want to set global defaults for all of them)

    Generically, :set syntax and :set syntax=off. You can set specific languages such as :set syntax=python. You probably know this though, and I’m afraid I cannot be of much help on how to do a set of actions based on filetype.

    To turn off auto indent, just :set noai. Again, not sure on how to have preset contexts based on filetypes.

    > Be able to edit another file without closing or saving the first (:e doesn’t seem to do what I want)

    :split file.c will split the screen horizontally so you can look and edit multiple files at once. Use CTRL+W W to switch between buffers. You can also do a vertical split with :vert split otherfile.c.

    > Integrate it with Mercurial and Darcs

    I set my merge to vimdiff in .hgrc. As for ChangeLog’s, I usually just add a new date line and :r! hg st to enter the status of my mercurial branch.

    Cheers, and good luck!

    Reply

  3. Risto Saarelma

    Using :new or :split will halve the screen space available, which might not be what you want if you have a small screen. If you have Vim version 7 or above, you can also use tabs. Say “:tabe [newfile]” to open the new file in a new tab. See “:h tabpage” for more info on tabs.

    Reply

  4. romain

    Why?!

    Reply

  5. i5513

    why don’t you try:
    :help folding
    :help autoindent
    :help syntax
    :help tabs
    :help split
    :help window

    And not sure for mercurial see at:
    http://www.vim.org/scripts/script.php?script_id=1293

    Reply

    tonfa Reply:

    For mercurial just set $EDITOR to vim, the hgmerge script will launch vimdiff on merge automatically.

    For the syntax highlight for example for python, put the following in hgrc:
    au FileType python set syntax=off

    Reply

    tonfa Reply:

    Hum I meant put it in vimrc off course :)

    Reply

  6. Ivan Tarasov

    # Turn on or off autoindent, syntax highlighting, etc. in various languages (really, I want to set global defaults for all of them)

    :set noai
    :set nocin
    :set nosi

    and be sure to read
    :help ai
    :help cin
    :help ‘si’

    # Be able to edit another file without closing or saving the first (:e doesn’t seem to do what I want)

    If you mean that you want to forfeit all your changes and start editing another file, try

    :e!

    If you want to split the window and edit the files in parallel, try

    :sp
    or
    :vert sp

    When you start feeling comfortable, you might want to look at this page: < http://www.rayninfo.co.uk/vimtips.html>, these tips are great, even for hardcore vimmers.

    (and be sure to take a look at the corresponding help pages, there are lots of useful things you might want to know)

    Reply

  7. Jonas

    Being able to edit another file and not saving the buffer you are currently in put an ! after the command you use to change buffer. This works for me:
    vim three different files
    [write something]
    :b! different
    [write something else]
    :b! three
    and the stuff i wrote in file three is still there.

    Reply

  8. Eddy Petrisor

    John, many of your questions are answered in the (what I like to call) best dive-into-vim tutorial:

    [url]http://www.vi-improved.org/tutorial.php[/url]

    Reply

  9. i5513

    Take a look at
    /usr/share/doc/mercurial/examples/vim/

    Reply

  10. Anonymous

    set hidden
    help hidden

    Reply

  11. Igor Stirbu

    After reading the vim tutorial suggested by Eddy Petrisor, you could take a look at some .vimrc posted on the web to see what you would most likely want to have in your .vimrc. Here is a nice one: http://www.hermann-uwe.de/files/vimrc but read the help for commands before adding them. Happy vimming!

    Reply

  12. petekaz

    You can make a set of configurations only applicable to a particular language by using a filetype plugin. You can load plugins, indentation, and syntax rules based on file type. See :help filetype for more details.

    In summary though, this command enables filetype detection of indentation and plugins:

    filetype plugin indent on

    Then, you can create the following directory structure in your $HOME:

    .vim/indent/
    .vim/ftplugin/

    Then say you wanted to tweak the indentation rules used for shell scripting, you would drop a file called ‘sh.vim’ in the indentation directory. Likewise, if you had some specific feature of vim you wanted enable only when editing sh files, you could add ‘sh.vim’ to the ftplugin directory.

    Pete

    Reply

  13. Michael Ekstrand

    Debian changelog: as others have said, “set nofoldenable”. Put “setlocal nofoldenable” in ~/.vim/ftplugin/debchangelog.vim to apply that setting only to Debian changelogs.

    Editing other files: do “:help buffers”, there’s an option to keep old buffers around at which point “:e” will be what you want. Add the BufferExplorer plugin from vim.org, and you’ll have a lean, mean editing machine (BufferExplorer gives you a list of open buffers when you hit \be).

    Reply

  14. ricardo

    for setting flags based on filetype i have this in my .vimrc:
    autocmd FileType c set autoindent cindent shiftwidth=8 ts=8 foldmethod=indent
    autocmd FileType python set nocindent shiftwidth=4 ts=4 foldmethod=indent

    and so on. you’ll probably need to have
    filetype on
    filetype indent on
    filetype plugin on

    for this to work. btw, you can also have settings based on filename:
    autocmd BufRead admin.log* set expandtab

    for having multiple open files, tabs are really useful (:tabnew file). you can try this:
    https://wiki.ncl.cs.columbia.edu/wiki/index.php/Vim_awesomeness#using_tabs
    for a way to make them look nice (there may be a better way now, i haven’t checked in a while)

    Reply

  15. Karl

    Probably you will find my cheatsheet helpful:
    http://karl-voit.at/vim-emacs-cheatsheet_of_freezing_hell.txt

    I also learned with the emacs and switched over to vim a year ago.

    Short summary: emacs is the best for LaTeX editing (using AUCTeX and RefTeX) but everywhere else, I do prefer vim – not at least because I hate LISP :-)

    Reply

Leave a comment

 

Feed

http://changelog.complete.org / Want to try living in vim