1

I'm using basic version vimrc from https://github.com/amix/vimrc. No problem if I put my vimrc at /home/{user}/.vimrc, but if I put it in /etc/vimrc (arch) or /etc/vim/vimrc (debian), it becomes a problem.

The problem is: I cannot use:

let mapleader = ","

And then make a mapping that uses <leader>:

map <leader>tf :tabnew **/*    "fuzzy search file and open in new tab
map <leader>tn :tabnew<cr>     "open a blank new tab

Or just mapping a <space>:

map <space> /
map <c-space> ?

At my arch workstation, I open vim from konsole. In my debian server, I ssh-ed to open it (so, a tty).

Edit (more information) with command :map with global vimrc (from @statox link):

   0             ^
   <Leader>m   * mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
v  <C-S-k>       :m'<-2<cr>`>my`<mzgv`yo`z
v  <C-S-j>       :m'>+<cr>`<my`>mzgv`yo`z
n  <C-S-k>       mz:m-2<cr>`z
n  <C-S-j>       mz:m+<cr>`z
   <leader>cd    :cd %:p:h<cr>:pwd<cr>
   <leader>te    :tabedit <c-r>=expand("%:p:h")<cr>/
   <leader>tf    :call fzf#run({'sink': 'tabedit'})<cr>
   <leader>tc    :tabclose<cr>
   <leader>tn    :tabnew<cr>
   <leader>tz    :tabnew **/*
n  <c-space>   * ?
n  <space>     * /

So, most of the keys are not mapped correctly except a few like map 0 ^

And this is :map command when I drop the vimrc to ~/.vim/vimrc

   0             ^
   ,m   * mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
v  <C-S-k>       :m'<-2<cr>`>my`<mzgv`yo`z
v  <C-S-j>       :m'>+<cr>`<my`>mzgv`yo`z
n  <C-S-k>       mz:m-2<cr>`z
n  <C-S-j>       mz:m+<cr>`z
   ,cd    :cd %:p:h<cr>:pwd<cr>
   ,te    :tabedit <c-r>=expand("%:p:h")<cr>/
   ,tf    :call fzf#run({'sink': 'tabedit'})<cr>
   ,tc    :tabclose<cr>
   ,tn    :tabnew<cr>
   ,tz    :tabnew **/*
n  <c-space>   * ?
D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65
tonny
  • 11
  • 2
  • What is the error message you got? – tivn Sep 16 '18 at 16:10
  • there's no error message. It just the 'shortcut' is not functioning. – tonny Sep 16 '18 at 18:56
  • Probably not the issue, but I highly recommend noremap variants over plain map – D. Ben Knoble Sep 16 '18 at 22:38
  • 1
    You need to specify clearly what you expect, what you type, whether the mapping is used before you apply the foreign vimrc or not. I see <leader>tf is not in the foreign vimrc while map <space> is. – tivn Sep 17 '18 at 02:50
  • Since you said that simply mapping <space> doesn't work you could check this question of mine How to debug a mapping? if you follow the steps of the answer and report the results here it might be easier to help you. Also the usual pitfalls: - don't put a comment on the same line as a mapping, specify the mode of your mappings (nmap instead of map) and use the nonrecursive version of the commands (nnoremap instead of nmap) – statox Sep 17 '18 at 09:22
  • 2
    Also I don't think that putting your complete vimrc in /etc is a good idea: your vimrc contains your mappings and your configurations, other users don't need such a complete generic vimrc (since they can override it with their own vimrc). And if you do that so you can have your configuration when editing a file as root, don't edit files as root use sudoedit instead. – statox Sep 17 '18 at 09:26
  • @D.BenKnoble, tried that, no effect. – tonny Sep 17 '18 at 10:32
  • @tivn: sorry, I don't understand what you mean with foreign vimrc. But the point is, all the mapping with <leader> is not processed. You can try to map it to anything, but it won't work. Same with <space>. Nearly all mapping won't work if I place it at global config folder (/etc/) – tonny Sep 17 '18 at 10:38
  • @statox I've updated the info thanks to your link. And I'm not put comment on the same line as mapping. For map mode, I've tried it with nmap vmap, nnoremap, vnoremap, etc, with no success. – tonny Sep 17 '18 at 11:06
  • @statox: Mainly just me using vim, so it's not a problem to put vimrc in global configuration etc. Sometimes I juggle between users and use vim. If I must put vim to each users, it's annoying. When I updating my vimrc, I must override all local vimrc for each user.

    sudoedit? Noted. Will try that.

    – tonny Sep 17 '18 at 11:11
  • @Tonny, by foreign I mean the vimrc that you download from Internet. AFAIK, vim does not read ~/.vim/vimrc . Try move it to ~/.vimrc or ensure you source it from this file if it is exist. – tivn Sep 17 '18 at 12:03
  • 1
    @tivn vim does in fact read ~/.vim/vimrc (theres a specific order it searches in though) – D. Ben Knoble Sep 17 '18 at 13:01
  • @Ben Knoble I stand corrected. On vim 7.3 of my Macbook, it does not read ~/.vim/vimrc but on vim 7.4 of my Linux it is indeed read unless ~/.vimrc exist. – tivn Sep 17 '18 at 13:52
  • @tivn: ~/.vim/vimrc is not a global, but a local config, like @D. Ben Knoble stated. And all local config, whether ~/.vimrc or '~/.vim/vimrc' is working correctly. What's not working is when you placed the vimrc to /etc (make it global) – tonny Sep 17 '18 at 15:11
  • What version of vim? I can't understand why it wouldn't parse <leader> correctly (but only sometimes) – D. Ben Knoble Dec 18 '18 at 00:50
  • @D.BenKnoble: The newest Vim (8.x.x) – tonny Jan 12 '19 at 15:21

2 Answers2

1

One thing I've just seen is that if cpo contains <, then special characters like <leader> won't be handled right:

                                *cpo-<*
        <   Disable the recognition of special key codes in |<>|
            form in mappings, abbreviations, and the "to" part of
            menu commands.  For example, the command
            ":map X <Tab>" results in X being mapped to:
                '<' included:   "<Tab>"  (5 characters)
                '<' excluded:   "^I"     (^I is a real <Tab>)
            Also see the 'k' flag above.

The default for vi (note: not vim) is all flags—perhaps the global vimrc is being read by vi or vim in compatible mode?

D. Ben Knoble
  • 26,070
  • 3
  • 29
  • 65
  • 1
    It’s this. The existence of a user vimrc causes nocompatible to be set implicitly, but the existence of a system-wide vimrc does not (See :help compatible). Adding an explicit set nocompatible will fix this, and is probably a good idea generally. – Rich Jan 10 '20 at 23:35
0

I'll list my alternative ideas that doesn't solve the actual problem:

  1. put the vimrc file elsewhere (prefer in /etc/skel/.vim/vimrc) then make a softlink to local .vim/vimrc. The command: mkdir .vim && sudo ln -s /etc/skel/.vim/vimrc .vim/vimrc
tonny
  • 11
  • 2