Want to try living in vim

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

17 thoughts on “Want to try living in vim

  1. :set nofoldenable ” will expand your chanelog

    Do you want :new instead of :e?

    Hope that helps

    Helmut

  2. > 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!

  3. 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.

    1. 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

  4. # 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)

  5. 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.

  6. 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]

  7. 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!

  8. 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

  9. 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).

  10. 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)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.