VIM - Move through wrapped lines (in insert mode) - vim

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

Related

My vim ui is weird. It is hard to explain in word, please see the picture

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>

Vim <A-j> Keybinding for 10j moves cursor to the right

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.)

Different up/down key functions in different modes in vim

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.

Remap arrow keys vim

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.

Navigate between soft lines in Vim

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>

Resources