I want to remap <PageUp> to <C-u> and PageDown to <C-d> per the Vim scrolling documentation.
As it stands right now, my /etc/vim/vimrc looks like this:
nnoremap <PageUp> <C-u>
nnoremap <PageDown> <C-d>
I've tried a lot of different combinations and nothing I've done has worked.
My goal is to make the cursor move to the Start Of File or EOF when holding down PageUp/PageDown. As it is right now, the cursor stops before it gets all the way to the top (and PageDown scrolls past the EOF). Just annoyances I'm trying to fix.
EDIT: The above settings work fine. I was placing my mappings too early in the file.
What about the following mappings?
nnoremap <PageUp> gg
nnoremap <PageDown> G
Or simply using gg and G?
Instead of placing the mappings into the system-wide /etc/vim/vimrc, you should put user customizations into the ~/.vimrc file. Nonetheless, the global configuration (if that's what you want) should work, too. That it doesn't means that the mappings get cleared or redefined. You can check with
:verbose nmap <PageDown>
If it didn't get redefined, you have to hunt for :nunmap commands in all loaded scripts (:scriptnames), or capture a log with vim -V20vimlog.
You can do this with
map <silent> <PageUp> 1000<C-U>
map <silent> <PageDown> 1000<C-D>
imap <silent> <PageUp> <C-O>1000<C-U>
imap <silent> <PageDown> <C-O>1000<C-D>
from fixing-pageup-and-pagedown
Related
I know that I can use ctrl+w to shift between different Vim windows. But how do I remap the CMD-key to replace ctrl+w in various way? I'm specifically looking to bind cmd with the arrow keys, so that I can shift to NERDTree easily with CMD+LeftArrow. Appreciate the assistance.
I've tried to add the following to $MYVIMRC...
nmap <silent> <D-h> :wincmd h<CR> // For going to NERDTree
nmap <silent> <D-l> :wincmd l<CR> // For going back to file I'm working on.
In the left-hand side of a mapping, Command+Left is written <D-Left>. With this and other issues fixed (see below), your mappings should look like this:
nnoremap <D-Left> <Cmd>wincmd h<CR>
nnoremap <D-Right> <Cmd>wincmd l<CR>
or, simply, like this:
nnoremap <D-Left> <C-w>h
nnoremap <D-Right> <C-w>l
Other issues:
Recursive mappings (nmap) should be reserved to the rare situations where you want to use another mapping in your mapping. This is not the case, here, so nnoremap is the best choice.
The mapped commands don't echo anything so <silent> is useless.
Vim's comment leader is ", not //.
You can't have comments on the same line as a mapping anyway, see :help map-comments.
The newish :help <Cmd> is cleaner than using : in the right-hand side of a mapping.
Note that these mappings only work in the MacVim GUI.
I am using vim-markdown-toc plugin(successfully installed) and want to remapping some hotkey to specific function. I export this code autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked to my .vimrc file. But when I type :verbose imap <C-x>, it shows can not find the mapping.
Can anyone tell me what's the problem about this?
and also I also want to ask how to map one hotkey to multiple function?
autocmd Filetype markdown noremapb <silent> <C-x> :GenTocMarked
has two obvious errors:
noremapb should be noremap, without the b:
noremap <silent> <C-x> :GenTocMarked
There should be a <CR> at the end:
noremap <silent> <C-x> :GenTocMarked<CR>
The right-hand-side of a mapping is a macro: since you press <CR> to execute the command :GenTocMarked, it should be present in the RHS.
Then comes the diagnostic mistake: the :map command, and its non-recursive buddy :noremap create mappings for normal, visual, and operator-pending modes, but :imap prints out insert mode mappings so you can't really expect it to find a mapping created with :map.
Then comes the semantic mistake: the re in noremap is part of nore (short for non-recursive), not of remap. <C-x> is not a mapping so you are not "remapping" anything.
Then comes the scoping mistake: :noremap creates mappings for three modes, which is something you probably don't want. You should be more specific:
" normal mode mapping
nnoremap <silent> <C-x> :GenTocMarked<CR>
and, finally, the autocommand abuse mistake: there already is a built-in mechanism for sourcing filetype-specific config so there is no need to reinvent the wheel in your vimrc:
" in after/ftplugin/markdown.vim
nnoremap <buffer> <silent> <C-x> :GenTocMarked<CR>
I have this in my .vimrc
nnoremap <leader>p :CtrlP<CR><C-\>w
I change all nmap to nnoremap in my .vimrc and everything works fine except this one:
nnoremap <leader>p :CtrlP<CR><C-\>w
With nmap <leader>p :CtrlP<CR><C-\>w it does automatically insert word into CtrlP and with nnoremap it doesn't, I get blank field, like I just pressed Ctrl-P.
Why it doesn't work with nnoremap?
When you create a mapping with nnoremap, it does not consider your prior mappings when resolving what to do. In other words, if you had previously mapped any of these:
<CR>
<C-\>
w
Then those maps would be ignored in your <leader>p mapping, and instead the default action of those keystrokes would be used.
As far as I know, <C-\> has no default action, so I would suspect you have mapped it (or you are relying on a mapping that another plugin has added), but that mapping is not being taken into account here.
I've been trying to create a shortcut for switching between open window splits in vim, rather than having to use ctrl+w+[arrowkey] I would prefer to just be able to use ctrl+[arrow keys].
This is what I currently have in my vimrc:
map <silent> <C-v> <c-w>v
map <silent> <C-Left> <c-w>h
map <silent> <C-Down> <c-w>j
map <silent> <C-Up> <c-w>k
map <silent> <C-Right> <c-w>l
The first shortcut for doing the vsplit works fine, however none of the others work. I've tried several variations of this and yet none of them do anything.
I'm using standard debian wheezy with KDE, vim is running from konsole and the only plugins I have installed are NERDTree and Airline.
I'm hoping someone can help provide a solution because I've been searching online for hours and trying hundreds of options and nothing seems to make any difference.
EDIT
verbatim insert for the shortcuts doesn't output anything at all, neither in shell or vim.
First, make sure that <C-Left> is not handled by konsole. Start a fresh one and use cat:
$ cat
^[[1;5D
That is how it should work for <C-Left>. Similar for other arrows. If <C-Left> doesn't work in such a way, search for "\e[1;5D": ... in /etc/inputrc and ~/.inputrc and comment it. You may have to log out and log in to get effect of these changes.
Next, use
:verbose map
in vim to display all mapped shortcuts and their source. You should see your bindings in this list. Your bindings are correct and all work in my case.
try this:
nnoremap <C-DOWN> <C-W><C-J>
nnoremap <C-UP> <C-W><C-K>
nnoremap <C-RIGHT> <C-W><C-L>
nnoremap <C-LEFT> <C-W><C-H>
I found this code the forum to make my life easier when switching between tabs and I placed it in my ~/.vimrc. Happily, it works well. Unfortunately, whenever I ctrl+tab to change tab, the cursor moves back one character. Can anyone help me keep the cursor in one place?
set showtabline=2
:nmap <C-S-tab> :tabprevious<cr>
:nmap <C-tab> :tabnext<cr>
:nmap <C-t> :tabnew<cr>
:map <C-t> :tabnew<cr>
:map <C-S-tab> :tabprevious<cr>
:map <C-tab> :tabnext<cr>
:map <C-w> :tabclose<cr>
:imap <C-S-tab> <ESC>:tabprevious<cr>i
:imap <C-tab> <ESC>:tabnext<cr>i
:imap <C-t> <ESC>:tabnew<cr>
The cursor moves back one character because that's how i works. Technically, you can change
:imap <C-tab> <ESC>:tabnext<cr>i
to
:imap <C-tab> <ESC>:tabnext<cr>li
but staying in insert mode is not a very good idea. If you can't help it, I'd suggest you remove the three imap from your ~/.vimrc to force you to use Vim correctly.
By the way…
You don't need that leading : in your ~/.vimrc:
map <C-t> :tabnew<cr>
You don't really need those :map because you already have nmap (and imap, but it should go).
<C-t> is very useful, both in insert mode (indents the current line) and in normal mode (goes back in the tagstack). You shouldn't override it like that.
<C-S-Tab> will probabbly not work in a terminal.
Tabs are not designed as 1-to-1 proxies for files and thus should not be used as such. You should use buffers instead.
Everything romainl said is good advice, in particular that tabs are not supposed to work as one-to-one proxies for files, like in other editors. Learn to use buffers, and your life will be easier. They're really very simple: all you really need is :set hidden, :ls, :bn, :bp, maybe some mappings like the ones you're setting up for tabs, and a bit of the Vim help.
That said, romainl's mapping will fail at the end of a line. A better solution uses <C-o>, which takes you out of insert mode temporarily for one command, and takes into account stuff like end-of-line behavior. You could use:
:imap <C-tab> <C-o>:tabnext<cr>