Can I use SPACE as mapleader in VIM? - vim

From http://items.sjbach.com/319/configuring-vim-right (2009 archive from original) I got that you were supposed to be able to use Space as the mapleader in vim. I've tried but it does not seem to work. Is there anyone who made it work?
Tried:
let mapleader = <space>

Try the following instead:
let mapleader=" "
And remember to write the following line before that, to make sure spacebar doesn't have any mapping beforehand:
nnoremap <SPACE> <Nop>

Mapleader is a Vim string variable. To use space as leader, you must escape the special character.
let mapleader="\<Space>"
For more info see,
http://vimdoc.sourceforge.net/htmldoc/eval.html#expr-quote
EDIT:
This no longer works for me in my version of Vim. Even with the suggestion in the comments of unmapping the spacebar in normal mode by running nnoremap <SPACE> <Nop>.
I ending up going with the solution given in the answer below.
map <Space> <Leader>

The above solutions are great, however, nothing shows up in the bottom right command corner. If you don't have any use for the \ key anyway, try using
map <SPACE> <leader> and \ will show up in the command corner. That and you don't have to unmap space first, as suggested in the commends above.

If you are using neovim and lua config, you can try it:
-- map leader to <Space>
vim.keymap.set("n", " ", "<Nop>", { silent = true, remap = false })
vim.g.mapleader = " "

nnoremap <space> <Nop>
nnoremap <nowait> <space> /

Related

Need Clarification on vim leader key

//mapping1
tnoremap <Esc> <C-\\> <C-n>
// mapping2
let localleader = "\\"
tnoremap <Esc> C<localleader> <C-n>
I tried to modify the above mapping by replacing '\' by a localleader;
But it just prints C\ ^N in the terminal. Can anyone help me to find the mistake?
According to VIM's documentation accessed by the command :help localleader, you should assign the "\\" to a maplocalleader variable, such as:
let maplocalleader = "\\"
tnoremap <Esc> C<LocalLeader> <C-n>

How to map <D-A> to increment 1 in MacVim

How do I get the increment by 1 behavior in MacVim for Command-A? <C-A> increments as excpected. In windows I just have to unmap <C-A>, so in MacVim I've tried the following:
" Doesn't seem to work. <D-A> still selects all
macmenu Edit.Select\ All key=<Nop>
nnoremap <D-A> <C-A>
_
" Doesn't work, no mapping exists
nunmap <D-A>
I've looked at the following, but I still can't figure it out:
how to map command key when configurate .vimrc?
How to increment in vim under windows (where CTRL-A does not work...)
As explained in :help :macmenu,
you must do that in ~/.gvimrc,
<D-..> mappings are case sensitive so <D-A> is not the same as <D-a>.
So, in order to use <D-a> in place of <C-a>:
Create ~/.gvimrc if it doesn't exist.
Add the following lines:
macmenu Edit.Select\ All key=<nop>
nnoremap <D-a> <C-a>

Unable to get this function working in .vimrc

Not sure if this is the best place for this question but following this http://vim.wikia.com/wiki/Using_the_Windows_clipboard_in_Cygwin_Vim article I put this function Putclip in my vimrc however it doesnt seem to get triggered.
vnoremap <silent> <leader>y :call Putclip(visualmode(), 1)<CR>
nnoremap <silent> <leader>y :call Putclip('n', 1)<CR>
I thought the above two calls to the function should work in vm mode or normal mode when pressing y command. Even the highlight on mouse in vm mode doesnt work. Can someone please let me know what im doing wrong.
I use cygwin as the environment to do this and using vim version 7.3.
These map the command not to y, but to <leader>y. By default, the leader key is a backslash, so the command is really bound to \y. You can change that by setting the mapleader variable to something else before mapping a command to a key sequence incorporating it:
let mapleader = ","
vnoremap <silent> <leader>y :call Putclip(visualmode(), 1)<CR>
Now the function would be bound to ,y instead of \y.

Arrow keys in vim (linux) in insert mode broken for me

When I use the arrow keys in vim in insert mode I get letters inserted instead of movement.
Up produces an A
Down produces a B
Left products a D
Right produces a C
Does anyone know what would cause this?
Thanks in advance
If these keys work fine in normal mode, but do not in insert then you must have some mappings to the first one or two characters (normally <Up> is either <Esc>[A (terminals that use CSI) or <Esc>OA (xterm)). Try checking out output of
verbose imap <Esc>
, there should be not much mappings starting with <Esc> in insert mode (I have none, for example). I can say, that with arrow keys working normally in insert mode, using
inoremap <Esc> <Esc>
produces just the same behavior as if you had problems with terminal recognition or had 'compatible' set.
Your vim seems to be starting in the vi compatibility mode. Do this
Open Vim editor,
Get the path of your home directory by typing :echo $HOME
Check if you have .vimrc file in $HOME location,(if you don't have create it)
Add the following line line to .vimrc file
:set nocompatible
Find more solutions for the same problem here ( Especially if your problem is terminal related, the re-mapping of keys solution might work for you )
The following worked for me. Just put it in your .vimrc
:set term=cons25
Open Vim editor.
Get the path of your home directory by typing: :echo $HOME.
Check if you have .vimrc file in $HOME location, and if you don't have create it.
Add the following line line to .vimrc file: :set nocompatible
Reference: http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell
None of the answer here worked for me. I'm in Linux, with konsole/yakuake terminal and tmux. This fix works for me:
nnoremap <silent> <ESC>OA <ESC>ki
nnoremap <silent> <ESC>OB <ESC>ji
nnoremap <silent> <ESC>OC <ESC>hi
nnoremap <silent> <ESC>OD <ESC>li
inoremap <silent> <ESC>OA <ESC>ki
inoremap <silent> <ESC>OB <ESC>ji
inoremap <silent> <ESC>OC <ESC>hi
inoremap <silent> <ESC>OD <ESC>li

How do I map ctrl x ctrl o to ctrl space in terminal vim?

After searching a bit on the net it seems that I can't map CtrlSpace to anything/alot. Is there a way to do it today, what I found was usually 2 years old.
I've run into the same issue, the short answer is yes you can, and not only in the gui version. Adding this on you .vimrc is enough:
inoremap <C-Space> <C-x><C-o>
inoremap <C-#> <C-Space>
The problem seems to be that Terminal.app doesn't interpret <C-Space> correctly and Vim understands it as <C-#> which is a built-in mapping (:help CTRL-#).
Maybe you could go with something like the following in your .vimrc:
if !has("gui_running")
inoremap <C-#> <C-x><C-o>
endif
which seems to work, here, but I don't like the idea of overriding built-ins like that.
Instead you should try with <Leader> (:help leader), it gives you huge possibilities for defining your own custom mappings and (depending on the mapleader you choose) won't interfere with OS/app specific shortcuts/limitations and hence be more portable.
With this in my .vimrc:
let mapleader=","
inoremap <leader>, <C-x><C-o>
I just hit ,, to complete method names.
The nitpicker broke pablox solution. The crux of the solution was just about remapping. So when you disable remapping, it cannot work.
If you really want to throw in a noremap, this is what it looks like:
inoremap <expr><C-space> neocomplete#start_manual_complete()
imap <C-#> <C-Space>
What will not work: inoremap <C-#> <C-Space> 'cause the <C-Space> part will not be remapped itself.
Have you tried :inoremap <c-space> <c-x><c-o> ?
Does CtrlX CtrlO do anything when you type in insert mode? Is omnifunc set?
Add the following code to ~/.vimrc:
" Ctrl-Space for completions. Heck Yeah!
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
\ "\<lt>C-n>" :
\ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
\ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
\ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-#> <C-Space>
Source: https://coderwall.com/p/cl6cpq
To accommodate both Windows and Linux I applied this to ~/.vimrc
if has("unix")
inoremap <C-#> <c-x><c-o>
elseif has("win32")
inoremap <C-Space> <c-x><c-o>
endif
I had better results with this set of mappings across all modes on Mac OS. Have not tested Windows or Linux.
I don't understand how the excepted answer is supposed to work in terminal mode.
inoremap <C-space> <ESC>
vnoremap <C-space> <ESC>
cnoremap <C-space> <C-c>
" When in terminal, <C-Space> gets interpreted as <C-#>
imap <C-#> <C-space>
vmap <C-#> <C-space>
cmap <C-#> <C-space>
Like the others said, using inoremap with the correct key for your term (as discovered using i_Ctrl_v) should work. I will add to this another possible cause for problems with insert mode mappings: paste mode. As the docs state:
When the 'paste' option is switched on (also when it was already on):
- mapping in Insert mode and Command-line mode is disabled
This may seem irrelevant, but this very thing tripped me up trying to get a similar inoremap binding to work in Vim 8.2. I had set paste in my .vimrc, and had to chop it up with :finish statements (as [recommended in the vim faq) to isolate the line causing the problem.

Resources