I have problem (VIM: E523: Not allowed here) that reproduce randomly after I've added next keymap:
inoremap <silent> <C-S> <cmd> :stopinsert \| :w<CR>
(It is going to NORMAL mode and save file)
Give this a try:
inoremap <silent> <C-s> <ESC>:w<CR>
Related
Help! My vim ui is weird. It is hard to explain in word, please see the picture.
Try cleaning the search register:
:let #/=""
I have some mapping to temporarelly disable hlsearch, actually it toggles it, wich is more convinient, in my humble opinion.
nnoremap <silent> <c-l> <ESC>:set hls! hls?<cr> :call clearmatches()<cr><left><c-l>
inoremap <silent> <c-l> <C-o>:set hls! hls?<cr> <C-o>:call clearmatches()<cr>
vnoremap <silent> <c-l> <ESC>:set hls! hls?<cr> <bar> gv :call clearmatches()<cr>
I've recently mapped 10j to <A-j> and 10k to <A-k>, which is seemingly quite amazing, but there is one problem with it:
When I normally type 10j (not using the shortcut), it will just move 10 rows down vertically but not move horizontally at all (given the lines have the same length), but when I use <A-j> it will always (well, interestingly enough, not always, but most of the times) also move one letter to the right.
Funnily enough, this happens only for <A-j>, whereas <A-k> works as intended. How can I prevent that? And maybe most importantly: Why is that?
If it helps, these are my other keybindings:
nnoremap K K<C-w>L
nnoremap <A-h> :set hls!<cr>
nnoremap / :set hlsearch<cr>/
nnoremap <A-j> 10j
nnoremap <A-k> 10k
nnoremap <A-w> W
nnoremap <A-b> B
nnoremap <A-v> V
nnoremap <A-m> '
nnoremap <A-p> "+p
nnoremap <A-y> "+y
nnoremap <A-4> $
nnoremap <A-3> 0
nnoremap Y y$
vnoremap <A-h> :set hls!<cr>
vnoremap / :set hlsearch<cr>/
vnoremap <A-j> 10j
vnoremap <A-k> 10k
vnoremap <A-w> W
vnoremap <A-b> B
vnoremap <A-v> V
vnoremap <A-m> '
vnoremap <A-p> "+p
vnoremap <A-y> "+y
vnoremap <A-4> $
vnoremap <A-3> 0
Yeah, I like the alt-key a lot.
You have a trailing space character at the end of your mapping:
:nnoremap <A-j>
n <M-j> * 10j<Space>
<Space> is the same command as l; it moves a character to the right (where possible).
The right-hand side in a mapping is taken literally (up to the end of the line or a | command separator). Another common mistake is appending a " comment to a mapping definition.
Plugin recommendations
If you regularly stumble over trailing whitespace (it's generally frowned upon in many coding styles, and tools like Git also highlight it as problematic), my ShowTrailingWhitespace plugin can alert you to those, and the DeleteTrailingWhitespace plugin can remove them for you. (The plugin pages have links to alternative plugins.)
I am using following code in my init file :
noremap <Up> gk
noremap! <Up> <C-O>gk
noremap <Down> gj
noremap! <Down> <C-O>gj
(from: http://vim.wikia.com/wiki/Moving_by_screen_lines_instead_of_file_lines)
This is to move the cursor one 'displayed line up' and not to one line up when using up key. Similar for down key.
However, now when I go to command mode and press ':' to insert a command, I cannot use up key to get previous command. Is there any way to get previous commands with up and down keys while using above code for insert mode? Thanks for your help.
Edit: The output of :verbose cmap <Up> is:
<Up> * <C-O>gk
In the Vim configuration file, the lines
noremap! <Up> <C-O>gk
noremap! <Down> <C-O>gj
will affect the Insert mode and Command-line mode. So If you want it to only affect the Insert mode, you can chanage it with
inoremap <Up> <C-O>gk
inoremap <Down> <C-O>gj
You can check the help with :help noremap! to inspect the modes it works.
I have the following keys mapped in my .vimrc file:
noremap <silent> <C-h> :bprev<CR>
noremap <silent> <C-l> :bnext<CR>
The commands they execute are provided from the buftabs script.
What I would like to do is prevent those key mappings from being executed when I'm in the NERDTree split. The reason for this is if the commands are run while in NERDTree, a file buffer gets loaded in the split instead. Then, to fix it, the window needs to be closed and opened again.
This is a similar problem as explained in another question, but the problem there was corrected by configuring the plugin, while the buftabs script does not have such an option.
In order to disable a mapping in certain buffers, one can define
a buffer-local mapping for the same key sequence, overriding the
original mapping with a no-op:
:autocmd FileType nerdtree noremap <buffer> <c-h> <nop>
:autocmd FileType nerdtree noremap <buffer> <c-l> <nop>
(See :help :map-arguments and :help <nop> for details on
<buffer> and <nop>, respectively.)
I updated my vimrc by looking at ib.'s solution.
autocmd FileType nerdtree noremap <buffer> <A-PageDown> <ESC>:wincmd w <bar> bnext<CR>
autocmd FileType nerdtree noremap <buffer> <A-PageUp> <ESC>:wincmd w <bar> bprevious<CR>
It goes back to the previous window and executes the command.
I'm not a fan of 80(or 72) characters pr. line followed by a line-break even if your VIM inserts the line-break itself - you'll easily run into inconsistency problems when editing that line of text afterwards. Otherwise I have nothing against the editor, but somehow editing text as I do in a GUI editor makes me sleep better at night.
So, I discovered that the reason for the line breaks was primarily due to inability to move through softly wrapped lines, and hence I found this article: http://vim.wikia.com/wiki/Move_through_wrapped_lines which works, but I'm looking for a solution that would work in insert-mode as well as edit-mode.
P.S. I'm probably a newbie at VIM :)
Why would you need to move through wrapped lines in insert mode? You'd better move through such lines in command mode with gj and gk and when you need to edit something, press i, edit and go out of insert mode.
The less time you'll be spending in insert mode, the better.
imap <Down> <C-o>gj
and
imap <Up> <C-o>gk
works for me.
My configuration is as follows:
vmap <silent> <Right> l
vmap <silent> <Left> h
vmap <silent> <Up> gk
vmap <silent> <Down> gj
nmap <silent> <Right> l
nmap <silent> <Left> h
nmap <silent> <Up> gk
nmap <silent> <Down> gj
imap <silent> <Up> <C-o>gk
imap <silent> <Down> <C-o>gj
My complete configuration is here:
https://github.com/Waxolunist/vimconf