This question already has answers here:
Move entire line up and down in Vim
(21 answers)
Closed 9 years ago.
I was wondering which was the shortest way to turn upside down two adjacent lines in vim, for example:
Hi
How are you?
in
How are you?
Hi
Are there some special shortcuts or should I consider to write a macro for this?
Use ddp when your cursor is on the first line.
dd deletes the current line.
p pastes the deleted line under the current one.
What you need is a mapping: what that mapping does, even if it's 20 commands chained, doesn't really matter.
nnoremap <F6> :m-2<CR>==
and
nnoremap <F6> ddp
both do exactly what you want in slightly different ways. One command is complex and relatively smart while the other is simple and relatively dumb but they are equivalent in the way that they are both done with a single keystroke.
Of course you can use somerhing else than F6.
Related
This question already has answers here:
Vim: search and highlight but do not jump
(14 answers)
Closed 2 years ago.
I was getting the cursor word as: noremap <leader>h *N, but this moves the screen. What I want is:
Highlights the <cword>; and
Not move the screen, nor the cursor.
Here is my system: Linux, running neovim v0.4.3 with python2&3 support.
OBS: I know about the plugin inkarkat/vim-mark but I got some errors and it is much more than I need.
I tried using the builtin matchadd, but could not enter the <cword> (it interprets the string literally), and within brackets it considered it a regex.
If I understand you correctly, then here is the answer to your question:
ViM: Search and highlight but do not jump
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Is there any way to reduce the command in VIM?
In vim to open your NERDTree menu you type :NERDTree, but that actually really annoys me, because it's long and mixed case. Since you close it with q, I want to open it with a short key (maybe :n, you can also provide suggestions for that if you feel like it). How can I change that?
I am sorry if this is simple, but I am a newb, and I don't know form where to start aproaching such a problem -from the plugin files, or is there a special remapping technique in your .vimrc.
You can use
map <F2> :NERDTreeToggle<CR>
to map NERDTree to any key you like (F2 in this example)
it's also possible to map it to :n
map :n :NERDTreeToggle<CR>
but that's not very common, I like using one of the F-Keys because that's faster.
This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
When navigating through word-wrapped text in VIM, how to make the selector move onto wrapped line sections?
Hi all,
I'm editing some source files with large chunks of text and lines that wrap in my terminal. If I want to move down one "line" as I see it in the terminal, I can't press 'j' as this will jump to the next carriage return. So I end up holding down 'w' until I'm where I want to be. This seems dumb to me.
Is there some way someone knows to achieve what I want? Something akin to 'l80' which would give me what I'm after so long as my terminal is displaying 80 columns, but wouldn't work as soon as the number of columns in the terminal changes. Nor would it jump the real lines when it hits them.
Thanyou
Use gj and gk to move up and down within a wrapped line.
A lot of people map:
nnoremap j gj
nnoremap k gk
To make this more convenient. It doesn't have any adverse effects.
(If you aren't familiar with customizing Vim, you can just put those two lines in ~/.vimrc, and restart, and it should behave like you want it to.)
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
In vim is there a way to delete without putting text in the register?
Most of the time, I use yy to yank and line and then paste with p somewhere. However, if I use dd to delete any line, or dw to delete any word, I will lose anything that I had yanked. Is there a workaround to this problem?
Thanks,
The same question has been answered a few times, I think.
You can map the correct command to eg <leader>d with:
nnoremap <leader>d "_d
This question already has answers here:
Vim: search and highlight but do not jump
(14 answers)
Closed 4 years ago.
I often use * to highlight all instances of the current word, and the fact that it advances to the next word is pretty annoying. I'd like to disable this behavior, knowing that I can always use "n" if I actually need to advance.
Any insight?
EDIT: I should add that I'd like to avoid a screen redraw at all costs as it is visually distracting.
Try this:
nnoremap * :let #/ = "\\<<C-R><C-W>\\>"<CR>
(Assumes you have 'hlsearch' on). This just changes the current search pattern to the word under the cursor (surrounded by \< and \> to match word boundaries). If you have hlsearch enabled, it will highlight the word. n and N will then work as normal.
See:
:help :let-#
:help quote/
:help c_CTRL-R_CTRL-W
Try this Vim Tip. I find it very useful. The most interesting is that you can have more matches and every one in different color.
I cannot give an exact answer, but this Vim Tip tells you what you have to add to your .vimrc to simply highlight the word under the cursor when Vim is in idle state.
Works without any key-remapping...
You can remap it to return:
nnoremap * '*N'
(but this redraws the screen)