Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing leader in Vim

Tags:

vim

It took me almost two years of programming till I decided to switch Textmate for Vim and I love it so far. However, after playing with it for a few days I hit a first issue.

As a beginner I reached for Janus as many people do but in the end I decided to create my own configuration from scratch to get to know the stuff better. I backed my configs up and started writing my new .vimrc file. But later on (pretty early) I noticed that leader key isn't working, it does nothing when I press it, well it just beeps. I didn't change the key for a leader nor did any key mapping so I was kinda surprised.

So once again I removed my .vimrc file and .vim directory to start with a clean state. It didn't help. So I opened Vim and tried to reconfigure a leader to a different key to see if it helps.

:let mapleader
> E121: Undefined variable: mapleader
:let mapleader = ','
:let mapleader
> mapleader          ,

Looks fine but nothing really happened. Even when I put it under a different key my Mac just beeps and thats it. There's no vim configuration in my home directory, no plugins, nothing. Setting leader in '.vimrc' instead of vim console doesn't help either.

I saw some discussions here on timeouts for key pressing but it have not got me anywhere.

I'm kinda stuck here and not able to use Vim for my day to day job even if I'd love to. Any help would be highly appreciated.

like image 915
Kreeki Avatar asked Nov 19 '12 00:11

Kreeki


People also ask

What does Silent mean in vim?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.


1 Answers

Follow these steps carefully…

  1. Create a blank .vimrc file in your $HOME directory:

    $ cd
    $ touch .vimrc
    

    Vim should now run in "nocompatible" mode which is what we all want.

  2. Open your blank ~/.vimrc and add these lines:

    let mapleader=","
    nnoremap <leader>a :echo("\<leader\> works! It is set to <leader>")<CR>
    
  3. Hit ,a, you should obtain the following message in the command line.

    <leader> works! It is set to ,
    

<leader> may not be useful right from the start, though, there are other things to worry about.

Anyway, from there, I'd suggest you to add these few non-opinionated settings that will make your life considerably easier:

filetype plugin indent on
syntax on
set autoindent
set hidden
set incsearch
  1. filetype plugin indent on allows Vim to recognize the filetype of the files you open and to apply all sorts of built-in filetype-specific settings (indent rules, completion…).
  2. syntax on turns syntax highlighting on.
  3. set autoindent copies the indent of the current line when you do <CR> life sucks so much if this is off.
  4. set hidden allows you to open a new file or switch to another buffer without saving the changes to the current one.
  5. set incsearch makes search-based navigation (/foo, ?bar) instantly awesome by turning incremental search on.

After that, it's up to you to add settings and mappings as you need them.

like image 182
romainl Avatar answered Sep 27 '22 17:09

romainl