How can I remap Ctrl-ArrowKeys to move between split buffers, like I can with <C-w> <ArrowKeys>?
Right now <C-Right> deletes until the end of line and goes into insert mode - which is not what i prefer (I use C for this) and would be happy to get rid of this behavior.
nnoremap <silent> <C-Right> <c-w>l
nnoremap <silent> <C-Left> <c-w>h
nnoremap <silent> <C-Up> <c-w>k
nnoremap <silent> <C-Down> <c-w>j
It must be said that not all mappings work on all terminal, so you mileage may vary. This is working well with gvim.
I also use those mapping when working with spli windows:
" To move between buffers and maximise the selected one
map <C-J> <C-W>j<C-W>_
map <C-K> <C-W>k<C-W>_
Combined with
" This sets the minimum window height to N
set wmh=0
It's pretty good.
I have been used this for a while now and I'm completely addicted!
Related
I have a .vimrc file (hosted in a git-repo), containing the following keymappings:
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-l> <c-w>l
map <c-h> <c-w>h
But recently, the mapping <c-j> stopped working, causing <c-j> to change to insert-mode.
My git-repository does not show any changes, but the :map command returns:
o <NL> <C-W>j
<C-K> <C-W>k
<C-L> <C-W>l
<C-H> <C-W>h
What could be the reason? And what does the <NL> stand for?
Executing :map <c-j> <c-w>j after vim started, fixes the mapping.
Doing a noremap <c-j> <c-w>j does not fix the problem
Moving the mapping to the end of the vimrc-file also causes no success...
EDIT 1.0:
:verbose map <c-j> returns:
v <NL> <Plug>IMAP_JumpForward
Last set from ~/.vim/bundle/vim-latex-suite/plugin/imaps.vim
n <NL> <Plug>IMAP_JumpForward
Last set from ~/.vim/bundle/vim-latex-suite/plugin/imaps.vim
o <NL> <C-W>j
Last set from ~/.vimrc
EDIT 2.0:
Disabling vim-latex-suite makes the mapping work again. But how can I combine both? Plugin+mapping?
The vim-latex-suite plugin overrides your <C-J> mapping. (I don't know why it defines a global mapping; a buffer-local one for Latex files might suffice, but I don't know the plugin.) As the plugin supplies <Plug> mappings, it's easy to redefine the conflicting one in your ~/.vimrc, e.g.:
nmap <Leader>j <Plug>IMAP_JumpForward
Under :help key-notation, you'll see that <C-J> and <NL> are equivalent. May Control key codes have special meaning:
<NL> linefeed CTRL-J 10 (used for <Nul>)
I am having trouble to activate the following mappings:
nnoremap <buffer> <C-K> <c-w>w
nnoremap <buffer> <C-S-K> <c-w>W
Where, I want have "pressing Ctrl+K in normal mode" to send me to the next buffer (of the same screen), in a clockwise way. <c-w>W in Vim will go the other direction. I want to map this action to be Ctrl+Shift+w.
Any idea why the mapping fails? I found only the latex-suite.vim has a mapping of <c-w> and none <c-s-w> has been mapped. The plugin mapping is buffer only.
Thank you for your input.
All the best,
-Linfeng
With the <buffer> keyword, your mappings only apply to the current buffer. So, when you have these in ~/.vimrc, they aren't effective, and if you type them in, you would need to have the same current buffer visible in multiple window splits. I don't think that's what you want. Instead, define them to be global mappings:
nnoremap <C-K> <c-w>w
nnoremap <C-J> <c-w>W
Edit: I've replaced <C-S-K> with <C-J>, because shifted control sequences are generally not available in Vim, unfortunately.
They could still be overwritten by some filetype plugins using nnoremap <buffer> <C-K>.
Alternative
I'd prefer the following set of directional mappings. They provide more precision, at the cost of wasting more keys:
nnoremap <C-j> <c-w>j
nnoremap <C-k> <c-w>k
nnoremap <C-h> <c-w>h
nnoremap <C-l> <c-w>l
I have the following lines in my .vimrc:
nnoremap <tab> :wincmd w<cr>
nnoremap <s-tab> :wincmd W<cr>
I want to move between Vim windows quickly using in Normal Mode. The above mappings work all right between windows, but when I get to the MiniBufExplorer, it gets stuck and doesn't rotate to the first window.
How should I map this so that it doesn't move into MiniBufExplorer?
There are two lines in the minibufexpl.vim plugin that remap Tab to cycle through the buffer names shown in the MiniBufExplorer window. If you remove/comment these, your tab remapping will work.
nnoremap <buffer> <TAB> :call search('\[[0-9]*:[^\]]*\]')<CR>:<BS>
nnoremap <buffer> <S-TAB> :call search('\[[0-9]*:[^\]]*\]','b')<CR>:<BS>
Additionally, there are global settings below which already control the C-Tab functionality for switching between either windows or buffers. You may want to modify these or at least be aware of this feature. NB, you will still have to remove the above Tab mapping to get Tab (instead of C-Tab) based movement.
if !exists('g:miniBufExplMapCTabSwitchBufs')
let g:miniBufExplMapCTabSwitchBufs = 0
endif
" Notice: that if CTabSwitchBufs is turned on then
" we turn off CTabSwitchWindows.
if g:miniBufExplMapCTabSwitchBufs == 1 || !exists('g:miniBufExplMapCTabSwitchWindows')
let g:miniBufExplMapCTabSwitchWindows = 1
endif
" If we have enabled <C-TAB> and <C-S-TAB> to switch buffers
" in the current window then perform the remapping
"
if g:miniBufExplMapCTabSwitchBufs
noremap <C-TAB> :call <SID>CycleBuffer(1)<CR>:<BS>
noremap <C-S-TAB> :call <SID>CycleBuffer(0)<CR>:<BS>
endif
" If we have enabled <C-TAB> and <C-S-TAB> to switch windows
" then perform the remapping
"
if g:miniBufExplMapCTabSwitchWindows
noremap <TAB> <C-W>w
noremap <S-TAB> <C-W>W
endif
Not exactly what you asked for but these are useful keyboard shortcuts to move between windows.
map <c-j> <c-w>j
map <c-k> <c-w>k
map <c-h> <c-w>h
map <c-l> <c-w>l
This makes Ctrl + <direction> move between windows (including MiniBufExpl when it's open). Tab is probably better reserved for code completion, check out the SuperTab plugin.
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.
I am using NERDTree on vim and usually open files with i
Is there an easy way to switch between different panes? Currently I use CTRL+W+W to move from one pane to another.
Long ago I found a tip (once on vim.org, now on wikia, apparently) that I've stuck with. Remap ctrl-[hjkl] to navigate splits. It has served me well.
" Use ctrl-[hjkl] to select the active split!
nmap <silent> <c-k> :wincmd k<CR>
nmap <silent> <c-j> :wincmd j<CR>
nmap <silent> <c-h> :wincmd h<CR>
nmap <silent> <c-l> :wincmd l<CR>
I prefer hitting single keys over hitting key-chords. The following maps pane movement to arrow keys:
" Smart way to move between panes
map <up> <C-w><up>
map <down> <C-w><down>
map <left> <C-w><left>
map <right> <C-w><right>
I know this is an old question, but I have a perfect way. Using the number of the split.
split_number C-w C-w
The panes are numbered from top-left to bottom-right with the first one getting the number 1.
for example to go to split number 3 do this 3 C-w C-w, press Ctrl-w twice.
Key mappings are definitely the way to go. I use the mappings mentioned by overthink. I also include the following mappings in my vimrc to move the splits themselves.
" Move the splits arround!
nmap <silent> <c-s-k> <C-W>k
nmap <silent> <c-s-j> <C-W>j
nmap <silent> <c-s-h> <C-W>h
nmap <silent> <c-s-l> <C-W>l
This makes it so that if the split opens in the wrong spot (lets say the left side and I want it on the right) I go to that split and hit <C-S-l> and the split moves where I want it to.
In order to be consistent with changing tabs via gt & gT, I'm currently trying out the g mappings for changing splits. I tend to hit the shift key as I go for the Ctrl key so this helps me avoid that mistake until I get better at not doing so.
nnoremap gh <C-W><C-H>
nnoremap gj <C-W><C-J>
nnoremap gk <C-W><C-K>
nnoremap gl <C-W><C-L>
I have mapped ctrl+w ctrl+w to <tab> (under normal mode as in normal mode tab does not have any use)and that's have made my life easier as now I can switch between panes easily by pressing <tab>.
For switching to a particular pane, I can press <i> + <tab> to switch between panes as split window panes also got their own number which can replace i.
Ex. i = 1,2...n.
Very easy way of achieving it. Type this shortcut twice, and that should work
ctrl+w ctrl+w