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>
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
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 in my .vimrc the following lines, which lets me switch windows with ctrl+hjkl:
nnoremap <C-h> <C-W>h
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-l> <C-W>l
These are fine for my desktop computer, but on my netbook, I want to have the active window completely fill the tiny screen. This means typing ctrl+w _ and ctrl+w | after each window change. The logical step would be to add those keystrokes to the mapping, yielding:
nnoremap <C-h> <C-W>h<C-W>_<C-W>|
nnoremap <C-j> <C-W>j<C-W>_<C-W>|
nnoremap <C-k> <C-W>k<C-W>_<C-W>|
nnoremap <C-l> <C-W>l<C-W>_<C-W>|
But that fails, consistently, when in a mapping, despite working when I simply type the required keys; and (as I have set 'showcmd') it seems to leave a trailing <C-W>.
I have also tried using :wincmd:
nnoremap <C-h> :wincmd h<cr>:wincmd _<cr>:wincmd |<cr>
nnoremap <C-j> :wincmd j<cr>:wincmd _<cr>:wincmd |<cr>
nnoremap <C-k> :wincmd k<cr>:wincmd _<cr>:wincmd |<cr>
nnoremap <C-l> :wincmd l<cr>:wincmd _<cr>:wincmd |<cr>
But that complains about trailing <cr> whenever my vimrc is sourced, so I'm not going to pursue that further without more research.
Any ideas?
Try using <Bar> instead of |. ie:
nnoremap <C-h> <C-W>h<C-W>_<C-W><Bar>
nnoremap <C-j> <C-W>j<C-W>_<C-W><Bar>
nnoremap <C-k> <C-W>k<C-W>_<C-W><Bar>
nnoremap <C-l> <C-W>l<C-W>_<C-W><Bar>
| are used to have multiply commands on one line and you will need to be escaped with a backslash when used literally:
nnoremap <C-h> <C-W>h<C-W>_<C-W>\|
nnoremap <C-j> <C-W>j<C-W>_<C-W>\|
nnoremap <C-k> <C-W>k<C-W>_<C-W>\|
nnoremap <C-l> <C-W>l<C-W>_<C-W>\|
On the other hand | can be useful:
nnoremap xxx :if 1 == 2 | echom "hello" | endif
I'm attempting to enable navigation based on displayed lines in VIM with set wrap linebreak enabled.
I have this function, which will toggle line wrapping with <Leader-W>
noremap <silent> <Leader>w :call ToggleWrap()<CR>
function ToggleWrap()
if &wrap
echo "Wrap OFF"
setlocal nowrap
set virtualedit=all
silent! nunmap <buffer> <Up>
silent! nunmap <buffer> <Down>
silent! nunmap <buffer> <Home>
silent! nunmap <buffer> <End>
silent! iunmap <buffer> <Up>
silent! iunmap <buffer> <Down>
silent! iunmap <buffer> <Home>
silent! iunmap <buffer> <End>
else
echo "Wrap ON"
setlocal wrap linebreak nolist
set virtualedit=
setlocal display+=lastline
noremap <buffer> <silent> <Up> gk
noremap <buffer> <silent> <Down> gj
noremap <buffer> <silent> <Home> g<Home>
noremap <buffer> <silent> <End> g<End>
inoremap <buffer> <silent> <Up> <C-o>gk
inoremap <buffer> <silent> <Down> <C-o>gj
inoremap <buffer> <silent> <Home> <C-o>g<Home>
inoremap <buffer> <silent> <End> <C-o>g<End>
endif
endfunction
This works perfectly. But I want to have wrap and linebreak enabled all the time and have this navigation mappings work. So I removed the function and left this.
set wrap linebreak nolist
set virtualedit=
set display+=lastline
noremap <buffer> <silent> <Up> gk
noremap <buffer> <silent> <Down> gj
noremap <buffer> <silent> <Home> g<Home>
noremap <buffer> <silent> <End> g<End>
inoremap <buffer> <silent> <Up> <C-o>gk
inoremap <buffer> <silent> <Down> <C-o>gj
inoremap <buffer> <silent> <Home> <C-o>g<Home>
inoremap <buffer> <silent> <End> <C-o>g<End>
Normal mode works fine, but insert mode does not. Any reason why this isn't working outside of the function?
There are two possibilities:
A plugin may override the insert mode mappings; check with :verbose imap <Up>.
Your mappings will only work in the first buffer; for global configuration, drop the <buffer> from the :map commands (like you switched :setlocal to :set).
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