I'm trying to make my arrow keys in vim useless to get used to hjkl.
After adding a few lines to my .vimrc file everything worked but the insert mode remap.
nnoremap <Down> :echo "No down for you!"<CR>
vnoremap <Down> :<C-u>echo "No down for you!"<CR>
inoremap <Down> :<C-o> echo "No down for you!"<CR>
nnoremap <Up> :echo "No up for you!"<CR>
vnoremap <Up> :<C-u>echo "No up for you!"<CR>
inoremap <Up> :<C-o>echo "No up for you!"<CR>
nnoremap <Left> :echo "No left for you!"<CR>
vnoremap <Left> :<C-u>echo "No left for you!"<CR>
inoremap <Left> :<C-o>echo "No left for you!"<CR>
nnoremap <Right> :echo "No right for you!"<CR>
vnoremap <Right> :<C-u>echo "No right for you!"<CR>
inoremap <Right> :<C-o>echo "No Right for you!"<CR>
The problem is, every time one arrow key is pressed it inserts the following string into my file:
:echo "No **** for you!
We have the vi.SE for Vim questions, it is always better to post directly there. Anyhow:
Sardorbek's answer is correct, mapping to <nop> is the right solution. i.e. this:
noremap <Up> <nop>
noremap <Down> <nop>
noremap <Left> <nop>
noremap <Right> <nop>
inoremap <Up> <nop>
inoremap <Down> <nop>
inoremap <Left> <nop>
inoremap <Right> <nop>
Yet, the reason that your inoremap was printing the lines into the file is because you did use <c-o> after : at the beginning of your mappings, therefore the normal mode command that was being run was e (not :echo). I believe that the lines you were seeing were actually:
:cho "No **** for you!
And not
:echo "No **** for you!
Moreover, <c-o> allows for only one normal mode command but you need two: echo the message, and negate the arrow key movement.
In essence, the following is horrible (really horrible, please do not do this) but would have worked:
inoremap <Down> <esc>:echo "No down for you!"<CR>ki
inoremap <Up> <esc>:echo "No up for you!"<CR>ji
inoremap <Left> <esc>:echo "No left for you!"<CR>li
inoremap <Right> <esc>:echo "No Right for you!"<CR>hi
In general, using <esc> is preferable to <c-o> and c-u (in visual mode) wherever possible.
Related
New update of plugin ideavim make my remap not working, how can I resolve it ?
He now make some tab indentation, I don't realy understand what is going on.
I just want to move on previous word typing <C-h> & <C-l> to move on next one.
Here is my .ideavimrc file:
" -------------------------------------------------------------------------------
" Navigation
" -------------------------------------------------------------------------------
" Go to next/previous word
nnoremap <C-h> <b>
nnoremap <C-l> <w>
vnoremap <C-h> <b>
vnoremap <C-l> <w>
nnoremap <C-S-h> <B>
nnoremap <C-S-l> <W>
vnoremap <C-S-h> <B>
vnoremap <C-S-l> <W>
" Insert Mode
inoremap <C-h> <Left>
inoremap <C-j> <Down>
inoremap <C-k> <Up>
inoremap <C-l> <Right>
cnoremap <C-h> <Left>
cnoremap <C-j> <Down>
cnoremap <C-k> <Up>
cnoremap <C-l> <Right>
Someone find the solution here:
Github forum
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 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 one-line text input that's broken into several soft line wraps.
When I press j, I'd go straight to the next hard line, line 2. How do I navigate among soft line wraps?
Use gj to go down and gk to go up by visual lines instead of hard lines.
put that to your .vimrc:
map <silent> <Up> gk
imap <silent> <Up> <C-o>gk
map <silent> <Down> gj
imap <silent> <Down> <C-o>gj
map <silent> <home> g<home>
imap <silent> <home> <C-o>g<home>
map <silent> <End> g<End>
imap <silent> <End> <C-o>g<End>
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