I found vimrc key remapping of / in vim-better-default plugin and added to my config.
The remapping works as expected, but this remap also causes an issue with jump using the relative number. For example, when I run 5<CR>, I need to type enter once more for it to work and it only jumps for 4 lines. The output in the bottom display is :.,.+4
I tried adding these but it did not work either.
autocmd CmdwinEnter * nnoremap <CR> <CR>
autocmd BufReadPost quickfix nnoremap <CR> <CR>
Thanks,
Related
I would like to go-to a tag when pressing enter (instead of clicking with the mouse when mouse=a) or pressing ctrl-], which is a bit of a stretch for me. Is it possible to do the mapping in the help section only, such as:
:nnoremap *help* <CR> <C-]>
I do exactly that in an ftplugin for :help files: put your mapping in ~/.vim/after/ftplugin/help.vim and use <buffer>:
nnoremap <buffer> <CR> <C-]>
Create a buffer-local mapping when a help file is loaded:
:autocmd BufReadPost $VIMRUNTIME/doc/help*.txt nnoremap <buffer> <CR> <C-]>
If the "help page" you meant is vim doc/help, they have ft=help. You can verify it by :echo &ft or :set ft?.
Then it is easy if you want to create mapping only for those filetypes. You can do it using autocommand:
autocmd FileType help map....
If you want it to be buffer local mapping, you add <buffer> in mapping.
How can I configure Vim to set
"require 'pry'; binding.pry"
in Ruby and
"debugger;"
in JavaScript when pressing F2 via key mapping?
You can set this in your .vimrc as follows:
autocmd FileType ruby map <F2> orequire 'pry'; binding.pry<ESC>
autocmd FileType javascript map <F2> odebugger;<ESC>
When the F2 key is pressed in a *.rb file, "require pry" will be set and "debugger" is set in a *.js file.
The other answer is correct, but not completely correct. You should use the noremap variant of map (see :h noremap), and the proper noremap for whatever mode your are in. If that's insert mode, then it's inoremap <F2> require..., or nnoremap for normal mode, etc.
You can also put those mappings into their own file instead of your vimrc so that you don't need to use autocommands (see :h ftplugin). And (thanks to the comments for reminding me) use <buffer> mappings so they only apply to the file you set them on (see :h <buffer>). In all, this is a good setup for you:
In ~/vim/after/ftplugin/ruby.vim, put the line:
inoremap <buffer> <F2> require 'pry'; binding.pry
and in ~/vim/after/ftplugin/javascript.vim, put the line:
inoremap <buffer> <F2> defbugger;
On windows, the vim directory is instead the vimfiles directory. If you want those mappings in normal mode instead of insert mode, you need to put i or O or another character like that at the front to go into insert mode and put <Esc> on the end to exit insert mode.
I have remapped the Enter key in normal mode to add a new line:
nnoremap <CR> o<Esc>k
Works great, but now in the command line (entered by q:) this command add new line either, but I would like to leave it in default mode, this is execute the selected command from history.
So the question is, how can I remap a key in normal mode, but not in command line?
This autocommand does what you want:
augroup commandlinewindow
autocmd!
autocmd CmdwinEnter * nnoremap <buffer> <CR> <CR>
augroup END
It's the "command-line window", by the way, not the "command line".
In addition to command-line window you'll almost certainly need this one. For quickfix window:
autocmd BufReadPost quickfix nnoremap <buffer> <CR> <CR>
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
I have the following code in .vimrc
" to eliminate the effect of the line 1560 in taglist.vim
if v:version >= 700
nnoremap <buffer> <silent> t
\
nnoremap <buffer> <silent> <C-t>
\
endif
The command does what it should do. However, the command gives also me the following error at Vim's startup
No mapping found
No mapping found
How can you eliminate the keyboard shortcut, such that you do not get the message in Taglist but you can still use the default "T" for browsing up in Dvorak?
Delete it. I don't use taglist, but the example you gave in your post does nothing.
It is supposed to map something to something, but the right side is missing, i.e. something is supposed to being mapped to "t" and "C-t", but that something isn't defined.
Or, you can do this:
:silent nnoremap <buffer> <silent> t (and analoguous for the second line)
(mapping stays but the message will not be displayed)