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

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.

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>

Difference between append and insert mode in Vim

I noticed this accidentally when playing around in vimtutor. What's the difference between append and insert mode in Vim? When I type a in normal mode (not A) I can insert text. When should I use one and not the other?
The append command will put the cursor after the current position, while the insert command will put the cursor before it.
Using the append command is like moving the cursor one character to the right, and using the insert command.
Using the insert command is like moving the cursor one character to the left, and using the append command.
You choose which depending on where you want to start typing.
Note that vimtutor doesn't initially make the case of the command obvious:
SHIFT+A (capital A, as opposed to a) the cursor moves to the end of the current line.
SHIFT+I (capital I, as opposed to i)moves to the start of the current line.
Another important aspect on Append is that if the position after the current position is a empty space followed by a word. After you are done writing it will concatenate both words.
E.g. A file with the following text:
Hi there.
With the cursor on i. After pressing the a button and then ESC you would have:
Hithere.

Remap End Key - $ Not Sufficient

I am trying to get off of using the arrow keys to navigate in VIM, so that I dont have to move my hands off the home rows. The problem I am having is finding the End Key equivalent. I used it a ton to go to the end of a line. I can still use it, but then I have to move my hands off the home rows, making this adjustment pointless. $ moves my cursor to the last character in the line, not after the last character in the line, which is where I want it to go. Why would I want to insert right before the last character on the line?
How can I remap the functionality of End Key (which can be used in insert and visual mode) to something else?
Thank you
It looks like you are doing $i which is the wrong approach.
$ is the right command to reach the end of the line but i is used to enter insert mode before the current character. You are supposed to use a to enter insert mode after the current character.
So you seem to be blocked because you don't know about a which is just as basic as i, IMO.
$a would solve your immediate problem.
But there's more, did you know that you can use I to enter insert mode at the beginning of the line? What command could we use to enter insert mode at the end of the line?
You are right, the correct command to enter insert mode at the end of the line is simply A, as #dusan commented.
You don't need to remap anything. What you need is a second (first?) injection of $ vimtutor.

Vim: insert text from a file at current cursor position

To insert text from a file in the current Vim buffer I use :r filename to insert the text below the cursor or :0r filename to insert in the first line.
How do you insert the contents of a file where [Cursor] is located?
Actual line with some coding [Cursor] // TODO for later version
Line below actual line ...
This inserts the contents of the file whose path is at the cursor position:
:r <cfile>
Insert a line break, read the file, and then take out the line break...
I propose Ctrl-R Ctrl-O = join(readfile('filename','b'), "\n")
Other solution:
Possibly open the other file in another window, use :%yh (h is a register name) and in your original file, in normal mode use "hp or "hP or in insert mode, Ctrl-R Ctrl-O h
To expand on the accepted answer with actual code, since I tried the suggestion and it worked nicely;
Here is an example of it working to insert a little php snippet:
`nnoremap <leader>php a<CR><ESC>:.-1read $SNIPPETS/php<CR>I<BS><ESC>j0i<BS><ESC>l`
In general the syntax is
`nnoremap [KEY SEQUENCE] a<CR><ESC>:.-1read [FILE PATH]<CR>I<BS><ESC>j0i<BS><ESC>l`
Just to break it down:
nnoremap : I'm about to define a new key mapping for normal mode
<leader>php : I would like to trigger the command sequence when this key combination is pressed. In my case <leader> is , so I type ,php to trigger the command.
Now for the command, bit by bit:
a<CR><ESC> : go into insert mode (after the cursor), insert a line break, go back into normal mode.
:.-1read <file><CR> : this enters the desired file on the line above the current line.
I<BS><ESC> : jump to the start of the line, delete line break, return to normal mode.
j0i<BS><ESC>l : Go down one line (to the remainder of the line that you were initially on), jump to the start, enter insert mode, delete the line break, return to normal mode.
l : position the cursor to the right of the pasted file (this just made the command work more like how you expect it to).
note
You have a choice of whether to paste before or after the cursor. I have chosen in this example to paste after the cursor because that is how the p command usually works to paste yanked text. Alternately, to paste before the cursor you should change the a at the start of the command to an i. You could use one of these exclusively, or you could bind them both to different but related key sequences. For example:
`nnoremap <leader>php i<CR><ESC>:.-1read $SNIPPETS/php<CR>I<BS><ESC>j0i<BS><ESC>l`
Could paste text before the cursor,
and :
`nnoremap <leader><leader>php a<CR><ESC>:.-1read $SNIPPETS/php<CR>I<BS><ESC>j0i<BS><ESC>l`
could paste text after the cursor. Or vice versa. I have made 'before the cursor' easier to trigger because I use it more often when pasting in-line.
other note
This solution is mainly useful if you're reading from a file that you expect to use often enough that it's worthwhile setting up a key mapping for it (ie reading a snippet from a file). This doesn't really help if you just want to read in a random files whenever since you won't have the key mapping ready.
Since it is very formulaic, I'm sure it would be possible to define a function that would take the file name as an argument and do the same thing though. I've never written a function in vimscript though so if someone who knows more feels like editing this answer to contain that solution - I urge them to do so!
" put this in your ~/.vimrc
" in insert mode press ,n
"
imap ,n <c-r>=expand("%:p")<cr>
Read more in wikia.

Resources