want to pick header by pressing enter in vim(clang) - vim

I've installed clang for my vim. Now when I'm typing for example #include , i see "" or <> headers, but when I hit enter on it, it's just typing new line instead of picking that preset.
I don't want to get a new line after pressing enter when I have variants to choose.

Related

Neovim block paste

I've read some posts about copying and inserting via block/visual selection but I think something is wrong on my side. If I copy the word hello, then move the cursor onto the second " of the next line, block select all " and press shift+p in order to paste hello between the ", it pasts hello on each line but removes the second ".
origin:
"hello"
""
""
""
result:
"hello"
"hello
"hello
"hello
I think you are doing it the wrong way in visual block mode. If I understand you correctly, you want to insert here inside the quotes in line 2, 3, 4, right?
This is the correct way:
Copy the word here.
Go to first " in line 2 and press Ctrl-V to start visual block mode.
Press 2j to also select line 3 and line 4.
Press A (note, this is capital A!)
Now we are in insert mode, press Ctrl-R, followed by ", then press <ESC> to leave insert mode.
After these steps, you should get what you want. For more info, open neovim and try read :h v_b_A.
I suggest trying to load neovim with no config file:
nvim -u NONE
The paste the text you want to change and test to se what happens.
In normal mode you can use: "+p, whereas on insert mode you can try:
Ctrlr+

How to repeat a navigation command in Vim

The . key can be used to repeat the last insert command. However, we might do some navigation that is not part of the insert, but we want it repeated.
Imagine commenting out lines like so:
// line of text
// line of text
line of text
line of text
The insert command is to put the two forward slashes and a space. That can be repeated using the . key. The navigation would be to navigate down one line and then left some number of characters. That part is not captured by the . key command.
How can we achieve this functionality? I read that it was not available in Vi some years ago, but I'm wondering if it exists now in the latest version of Vim.
Press qX, where X is any of the writable registers (typically: pick any lowercase letter).
Do whatever actions you want to record.
Press q again to stop recording.
Press #X (where X is the same register) to play it back (count times, if used with a count).
Press ## to replay the most recently used macro (count times).
I read that it was not available in Vi some years ago, but I'm wondering if it exists now in the latest version of Vim.
If the Vim docs are to be believed, Vi did not support recording (steps 1-3), but did support #. Then you would have to manually yank the characters into the target register with "Xy<motion> or some other register-writing command. That also works under Vim, but I can't recommend it because it is much more error prone.
Another approach would be "block select then edit" approach:
ctrl + v - block select
then go down j or down-arrow
shift + i will put you in insert mode. Make the change here where you want it to be reflected on all the other lines you've selected.
esc twice will show/repeat that change you made on the line one.
If you have a big range of similar lines and want to put // at the beginning of it, you can do something like:
:15,25norm! I//<space>
You can also use visual area (vip selects an entire paragraph)
:'<,'>norm! I//<space>
using a pattern
:g/TODO/norm! I//<space>

How to get line numbers of selected text in vim

Is it possible to get the line numbers of selected text to pass to an external command?
Context: I'd like to integrate pyfmt into vim. Ideally, I'd like to be able to select some text and type some shortcut to have the selected text reformatted by pyfmt.
So far I've found that running !pyfmt -i % will format the whole file. pyfmt also supports a --lines START-END option. I'd like to be able to pass the line numbers of the beginning and end of the selected text to pyfmt so that only what I want to reformat gets reformatted. Is this possible?
Select the lines you want to format (preferably linewise, using capital V to enter visual mode), and then, without leaving visual mode, type :!pyfmt -i.
This will not give you the line numbers. Instead, it will filter the selected lines through the command and replace them with the output.
I will provide my case as follow and I think it can be customized to your case, easily.
I have a Vim-Plug plugin Plug 'tpope/vim-commentary', and it has a command: (l,r are line numbers)
:l,rCommentary
When you visual-selected lines in Vim and then press : you will get:
:'<,'>
Based on this observation the command I need is: (visual mode mapping)
vnoremap <silent> my_shortcut :Commentary<CR>gv
i.e. I just need :Commentary since when it execute : the '<,'> is added for you.
To understand <silent>: https://stackoverflow.com/a/962118/5290519

spacemacs vi bindings not working

I am using spacemacs in GUI mode.
I was going through evil-tutor inside spacemacs. It told me to hit "j" to jump to next section. I was unable to do so since it was typing the letter "j" instead inside the buffer.
Similarly, I was unable to give commands such as ":qa! < ENTER >" and "x" to delete the character below the cursor. It just inserts the text.
help!

How to add a line in the middle of the program in TI-Basic Editor?

I am writing a simple Pong game in TI-Basic but the editor won't let me insert a line into the code I've already written.
For example
print "Hello world"
<--Where I want to insert the code
print "hello again"
x = 5
If I try to insert code it simply writes over previous code, I cannot create a new line.
Are you coding on the TI-84 calculator? If so, all you have to do is press "2nd" and then "DEL" (to the left of the arrow-pad). You will note the blue text, "INS", above the "DEL" key. Then simply press ENTER to add a new line.
There is a relevant section on page 511 of this TI-83 manual.
Inserting and Deleting Command Lines To insert a new command
line anywhere in the program, place the cursor where you want the new
line, press 2nd INS, and then press
ENTER . A colon indicates a new line.
To delete a command line, place the cursor on the line, press
CLEAR to clear all instructions and expressions on the
line, and then press DEL to delete the command line,
including the colon.

Resources