Hi I'm trying to optimise my window management in vim by mapping ctrlk to ctrl+w, k so i can just press ctrl+k to switch to the split window above the one I'm working in (I'm doing this for h,j and l also but it's only k that's causing the problem).
I've added this into my .vimrc
noremap <silent> <c-k> <C-W>k
noremap <silent> <c-j> <C-W>j
noremap <silent> <c-h> <C-W>h
noremap <silent> <c-l> <C-W>l
However if I press ctrl+k, then something weird happens. It changes depending on where I am in the document.
If I'm at the top of a document with many lines beneath my curser, the cursor hops down a few lines and columns into a completely different place.
If I'm at the bottom of a document, it creates loads of spaces from the cursor onwards.
I've tested and removing the above lines causes the symptoms to stop happening. I'm just really confused as to what is going on!
Some info: I'm using the vim binary that comes with macvim via the command line.
Any help would be greatly appreciated!
Thanks!
I can’t explain the second problem, but if you pasted everything directly from the vimrc then you have lots of trailing spaces that must not be there. It can explain the first problem. Try running
:%sm/\s\+$
then save and see whether problem disappears. If it is so, use
:set list listchars=trail:-
to be able to see trailing spaces so that you won’t run into this problem again.
Maybe <C-k> is already mapped to something else. Try :verbose map <C-k>.
Maybe your mapping is triggered in visual or operator mapping, where <c-w>k has a different meaning.
You could try this:
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
, which will trigger only in normal mode.
Related
This question already has answers here:
Vim command to insert blank line in normal mode
(4 answers)
Closed 8 years ago.
I recently surprised myself wanting to insert blank lines above or below the current line either in normal or insert mode.
I usually add blank lines to my code for better reading or to properly separate blocks of code.
To do this I am using the following in my .vimrc:
" Add empty line above and below the current line
nnoremap <silent> <C-K> mP:pu! _<cr>:']+1<cr>`P
inoremap <silent> <C-K> <esc>mP:pu! _<cr>:']+1<cr>`Pa
nnoremap <silent> <C-J> mP:pu _<cr>:'[-1<cr>`Pa
nnoremap <silent> <C-J> <esc>mP:pu _<cr>:'[-1<cr>`Pa
The only ugly thing with these mapping is I'm using the marker P just to go back to the previous cursor position. I tried to use `` instead but it doesn't do what I expected.
Perhaps there is a slightly better solution otherwise this snippet works quite well for me.
I am slowly adding new mapping in my .vimrc. I noticed the <C-[a-z]> combinaisons are mostly free and the existing ones are pretty useless (i.e. <C-Q>, <C-H>, <C-M>…). Then I decided to bind them to new useful mapping:
<C-N> New file
<C-S> Save (:update!)
<C-P> CtrlP mixed mode
<C-S-P> CtrlPCmdPalette
<C-B> CtrlP buffers mode
<C-D> <C-C>ciw
…
instead of using a named marker, you can use the backtick ' to explicitly add a jump. like:
nnoremap <c-k> m`O<esc>``
nnoremap <c-j> m`o<esc>``
inoremap <c-j> <esc>m`o<esc>``a
inoremap <c-k> <esc>m`O<esc>``a
If you want a robust mapping that also handles [count], my LineJuggler plugin contains ]<Space> mappings (among others). This particular mapping can also be found in the unimpaired plugin.
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 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
I was wondering if there is a way to see what commands are run by vim when I press a certain key.
In particular I am facing the rather weird behavior that vim does not execute my redefined behavior to switch between splits. I have the following lines in my .vimrc that remap the movement keys:
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
nnoremap j gj
nnoremap k gk
According to these remappings I want to be able to switch between splits by simply using ctrl + one of the movement keys.
It works for all keys except for j and I wanted to find out if that key might have been remapped by one of my installed plugins.
Is there any way to check this?
You can find out more about the mapping using the following command:
:verbose nnoremap j
I do not know about any really debuging feature but you can try :verbose map <shortcut>. It often provides useful info.
I use <c-l> to switch to the window split right of the active window split. I'm having an issue with eclim where <c-l> doesn't appear to do anything when the project tree view is the active window using this simple vimrc (note that <c-w>l does work):
set nocompatible
nnoremap <c-l> <c-w>l
However, mapping to another key such as 'n' does change the active split to one window to the right using <c-n>:
set nocompatible
nnoremap <c-n> <c-w>l
I found the following line in eclim/autoload/eclim/tree.vim:
nnoremap <buffer> <silent> <c-l> <c-l>:silent doautocmd eclim_tree User <buffer><cr>
Commenting out the line allows me to use <c-l>. However, I'm not entirely sure what the previous line is for and what impact commenting it out has. Is there a safer away to work around this while retaining my existing key bindings?
Fixed:
https://github.com/ervandew/eclim/issues/58