Shortcut for YcmCompleter GoToDefinitionElseDeclaration does not work - vim

I installed YouCompleteMe (https://github.com/ycm-core/YouCompleteMe#general-usage) for Vim with Vundle. In my .vimrc I have:
nnoremap <leader>g :YcmCompleter GoToDefinitionElseDeclaration<CR>
But when I type Ctrl-g at the befining of a variable in a file opened with Vim, nothing happens. YcmCompleter GoToDefinitionElseDeclaration works though.
When I type :let mapleader in vim I get the error E121: Undefined variable: mapleader
How can I make the short command Ctrl-g an 'alias' for YcmCompleter GoToDefinitionElseDeclaration ?

Ctrl is not by default the leader and is best not chosen as a leader because it has so many other shortcuts associated with it. To map Ctrl-g though you just need to define it like this:
nnoremap <C-g> :YcmCompleter GoToDefinitionElseDeclaration<CR>
For more information on the leader key check out this article: https://tuckerchapman.com/2018/06/16/how-to-use-the-vim-leader-key/

Related

Why doesn't <leader> commands work in my installation of vimwiki?

My Vimwiki doesn't start with leader + ww command, only with :VimwikiIndex.
I think it's related to leader.
:echo mapleader generates two errors:
E121: Undefined variable: mapleader
and
E15: Invalid expression: mapleader
Any ideas how to fix this?
If the variable mapleader is not defined, then the leader key defaults to \ (see :h mapleader). So your wiki should start by typing \ww.
If you want to redefine you global leader key, you have to set the mapleader variable in your vimrc file, i.e. to set it to the Space character:
let mapleader = " "
It's important to put it in your vimrc file, because it will be run before plugins are loaded; if you run this command in the command line, it will not change the existing mappings, then you actual mapping will still be \ww.
Please note that, as explained in the doc of the plugin you are talking about, you can also define your own custom mapping which will replace <leader>ww, by running:
:nmap [YOUR MAPPING] <Plug>VimwikiIndex
For example, to open your wiki with Space+w:
:nmap <space>w <Plug>VimwikiIndex

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>

Vim: Shortcut to toggle between NERDTreeCWD and NERDTreeClose

I'd like to be able to use the same shortcut to jump to a file in NERDTree and close NERDTree. I have no experience with VimL and could use some help.
Add the following to you vimrc
set autochdir
noremap <F2> :NERDTreeTabsToggle<cr>
The first command will automatically change the current directory to be the same the same as the file you are editing.
The second command will then set F2 to toggle toggles NERDTree on/off for all tabs. you can use any key i prefer F2.
Just say you want to do this with <leader>n:
" This in your ~/.vimrc
nnoremap <leader>n :NERDTreeFind<CR>
" This in ~/.vim/ftplugin/nerdtree.vim
nnoremap <buffer> <leader>n :NERDTreeClose<CR>
Substitute whatever you want for <leader>n.

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

vimrc help : trying to map Ctrl-s to :w

My current .vimrc file is
syntax on
colorscheme zellner
set nu
set ruler
set si "Smart indet
map <C-s> :w<cr>
I thought the last line would allow me to hit control-s to automatically save while in normal mode?
{
The last line is just the trim downed version of what I really want which is
map <C-s> <esc>:w<cr>a
}
Am I forgetting something?
I'm using vim 7.3 that came with my mac.
Like mentioned if you want it on both modes you have to just put
inoremap <C-s> <esc>:w<cr>a
nnoremap <C-s> :w<cr>a
in your .vimrc.
But note that if you are using the terminal vim then you might have a problem
mapping ctrl-s. By default it stops the flow. In that case add the following to your .bashrc (not sure if the same problem in zsh):
stty -ixon
If I got it right, you want
:inoremap <C-s> <esc>:w<cr>a
Whoops, just read you want it in normal mode
:nnoremap <C-s> :w<cr>
When you're writing commands in vim files (like .vimrc) you don't need the :. It is only a method of entering commands on the command line.

Resources