-1

Vim is exhibiting some configuration behaviors that confuse me.

  1. I have read that vim accepts $VIM/vimrc as its default configuration file. In my shell environment, $VIM is set to /etc/vim, but /etc/vim/vimrc is not used as the default config file. Rather, /usr/share/vim/vimrc is used.

  2. I have defined the following mapping in my vimrc file (which is now /usr/share/vim/vimrc), nnoremap ccom :normal I//< ESC>< CR>. This map is supposed to insert a c-style comment at the beginning of the current line. When I use this map, I get the text //<ESC><CR> put at the beginning of the current line. This is a malfunction. Similarly, if I start vim with -u /usr/share/vim/vimrc, the mapping exhibits the same undesirable behavior. If, however, I use the ex command source /usr/share/vim/vimrc, the mapping simply inserts // at the beginning of the line. How can this be?

  3. Why isn't showcmd set if :show cmd is in a configuration file that I know ran?

romainl
  • 186,200
  • 21
  • 280
  • 313
seewalker
  • 1,123
  • 10
  • 18
  • 1
    No, your vimrc is *not* `/usr/share/vim/vimrc`, it's `~/.vimrc`, which is accessible also from within Vim with `:e $MYVIMRC`. You need to create it yourself if it doesn't exist yet. – glts Jun 02 '13 at 18:40
  • **If you have more than one question, ask more than one question.** `:show cmd` does nothing whether you do it in Vim at runtime or in your `~/.vimrc`. Use `:set showcmd` at runtime or add `set showcmd` to your `~/.vimrc`. Oh! And read `:help showcmd`. – romainl Jun 02 '13 at 19:56

1 Answers1

1

NEVER do anything in $VIM.

All your configuration is supposed to happen in the ~/.vim directory and the ~/.vimrc file.

Put this line in ~/.vimrc and you are good to go:

nnoremap ccom :normal I//<CR>

edit

$VIM is Vim's default runtime. As such, it is setup in a way that guarantees a consistent user experience. Here are three good reasons, I'm sure I could dig up a few more:

  • Changing anything in that directory simply puts Vim in an inconsistent state that may lead to unexpected behaviors.

  • The content (or parts of the content) of that directory may be overwritten during the next upgrade (vim or system), essentially wiping out any customization you have done there.

  • Most script are designed around a bunch of conventions and generally require that some features are accessible at run time or source time or whatever. Installing those scripts anywhere else than their normal location (~/.vim) is going to lead to more unexpected behaviors.

romainl
  • 186,200
  • 21
  • 280
  • 313