How to move from line to line using VI - putty

I am using PuTTY to connect to my CentOS shell server. My only problem is the keyboard I currently use is a 60%. Meaning I have no arrow keys... Darn. How could i move around the shell without arrow keys? Thanks. If you are not familiar with PuTTy, it's just a way to connect to a server like a regular command prompt.

I have found the solution! You are actually supposed to use HKJL to move around in command mode! Not the arrow keys. Reason listed below.
https://superuser.com/questions/599150/why-arrow-keys-are-not-recommended-in-vim

J move cursor down one line
K moves cursor up
H moves cursor right
I moves cursor left
Make sure to take a look at the help manual if you're starting with VI because if for example you want to go to the end of the line at line 40 you don't want to press J 40 times and then go to the end of the line or if you're looking for an specific line or word you can use /string
Reference:
http://glaciated.org/vi/

Related

Is there a shortcut to comment out multiple lines in Marvel Sense?

I can comment out one line at the time with #, but is there a multiple lines comment toggle keyboard shortcut?
Well this could be done easily if you use vim
Specifically you could use macros .
Start recording a macro by typing qa where a will be the command name later.
Then type 0 to go to start of line . enter insert mode with i type # Esc and j to jump to next line.
type q to stop recording
now invoke command by typing 10 #a.
there's not no
but marvel sense is super old, 5.X era. do you mean Kibana Console? if so, definitely raise a feature request for this :)

Paste from a file one line (or section) at a time

I am a teacher using Windows and would like to be able to paste short program snippets one after another from a file of examples I have into whatever programming environment I am teaching (e.g. the python IDLE shell or editor). During the lecture I would have IDLE open and then use Ctrl-v to paste line 1 from the file into IDLE, execute & discuss it, then use Ctrl-v to paste line 2 from the file into IDLE, execute & discuss it, then use Ctrl-V to get line 3 into IDLE, and so on ...
I suspect there is some way to do this with a clipboard manager, but haven't found it online.
Being able to paste sections of code instead of just single lines would be really useful as well. The sections of code in the file could be separated by a blank line or some kind of text string indicator.
Having this functionality would allow me to have all my examples ready in a file and then during the lecture have quick access to all the examples one at a time by using Ctrl-v.
The following AutoHotKey script will paste lines from the clipboard, one line at a time, when you press Win+Ctrl+V (on Windows).
If you haven't used AutoHotKey, I highly recommend it.
#^v::
{
originalClipboard := Clipboard
StringSplit, ClipLines, originalClipboard, `n`r
size := StrLen(ClipLines1) + 3
Clipboard = %ClipLines1%
Send ^v`n
Clipboard := SubStr(originalClipboard, size)
return
}
Caveats:
It may not robustly handle line endings--it only works for two-character \r\n endings (the Windows standard). This should be most if not all real-world usages.
AutoHotKey seems to be only for Windows.
After you paste a line, that line is removed from the clipboard so that you are ready for the next one.
It always pastes a whole line at a time, even if the source was a partial line.
When you run out of clipboard lines, it pastes blank lines till you realize it.
It adds a new line by sending a newline. Not sure if this works in all text editors, but it worked in Notepad and a few others I tried.
There may be other nuances that it doesn't handle well.
Unfortunately, I cannot comment, but the great solution by #Patrick only works for me when I add a sleep command - otherwise, the clipboard content gets overwritten before the line is pasted. So if you run into a similar issue, the following version might do it:
#^v::
{
originalClipboard := Clipboard
StringSplit, ClipLines, originalClipboard, `n`r
size := StrLen(ClipLines1) + 3
Clipboard = %ClipLines1%
Send ^v`n
sleep, 500 ;
Clipboard := SubStr(originalClipboard, size)
return
}
Install the MultiLineRun.py script from the IdleX extensions for IDLE (or the whole of IdleX). Idlex is available here: http://idlex.sourceforge.net/.
If you want to automate it:
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
shell.AppActivate("Python 2.7.9 Shell")
# or the title of your idle shell window
for line in source.readlines():
# open your source file of examples
# better parse it into groups of commands
# and work each group in a batch
line= line.replace("(","{(}") # sendkeys escape
line= line.replace(")","{)}")
shell.SendKeys(line)
shell.SendKeys("{ENTER}") # for good measure.
"""SendKeys sends a string to the active window.
You can automate reading lines in batches linked to a button press etc
put in delays, copy per char etc
Go to town and make it a mini slide show!
"""

Reformatting text (or, better, LaTeX) in 80 colums in SciTE

I recently dived into LaTeX, starting with the help of a WYSIWYM editor like Lix. Now I'm staring writing tex files in Sci-TE, It already has syntax higlighting and I adapted the tex.properties file to work in Windows showing a preview on Go [F5]
One pretty thing Lyx does, and it's hard to acheive with a common text editor, is to format text in 80 columns: I can write a paragraph and hit Return each time I reach near the edge column but if, after the first draft, I want to add or cut some words here and there I end up breaking the layout and having to rearrange newlines.
It would be useful to have a tool in Sci-TE so I can select a paragraph of text I added or deleted some words in and have it rearranged in 80 columns. Probably not something working on the whole document since it could probably break some intended anticipated line break.
Probably I could easily write a Python plugin for geany, I saw vim has something similar, but I'd like to know if its' possible in Sci-TE too.
I was a bit disappointed when I found no answer as I was searching for same. No helpers by Google either, so I searched for Lua examples and syntax in a hope to craft it myself. I don't know Lua so this can perhaps be made differently or efficiently but its better then nothing I hope - here is Lua function which needs to be put in SciTE start-up Lua script:
function wrap_text()
local border = 80
local t = {}
local pos = editor.SelectionStart
local sel = editor:GetSelText()
if #sel == 0 then return end
local para = {}
local function helper(line) table.insert(para, line) return "" end
helper((sel:gsub("(.-)\r?\n", helper)))
for k, v in pairs(para) do
line = ""
for token in string.gmatch(v, "[^%s]+") do
if string.len(token .. line) >= border then
t[#t + 1] = line
line = token .. " "
else
line = line .. token .. " "
end
end
t[#t + 1] = line:gsub("%s$", "")
end
editor:ReplaceSel(table.concat(t, "\n"))
editor:GotoPos(pos)
end
Usage is like any other function from start-up script, but for completness I'll paste my tool definition from SciTE properties file:
command.name.8.*=Wrap Text
command.mode.8.*=subsystem:lua,savebefore:no,groupundo
command.8.*=wrap_text
command.replace.selection.8.*=2
It does respect paragraphs, so it can be used on broader selection, not just one paragraph.
This is one way to do it in scite: first, add this to your .SciTEUser.properties (Options/Open User Options file):
# Column guide, indicates long lines (https://wiki.archlinux.org/index.php/SciTE)
# this is what they call "margin line" in gedit (at right),
# in scite, "margin" is the area on left for line numbers
edge.mode=1
edge.column=80
... and save, so you can see a line at 80 characters.
Then scale the scite window, so the text you see is wrapped at the line.
Finally, select the long line text which is to be broken into lines, and do Edit / Paragraph / Split (for me the shortcut Ctrl-K also works for that).
Unfortunately, there seems to be no "break-lines-as-you-type" facility in scite, like the "Line Breaking" facility in geany. not anymore, now there's a plugin - see this answer
Well, I was rather disappointed that there seems to be no "break-lines-as-you-type" facility in scite; and I finally managed to code a small Lua plugin/add-on/extension for that, and released it here:
lua-users wiki: Scite Line Break
Installation and usage instructions are in the script itself. Here is how SciTE may look when the extension properly installed, and toggle activated after startup:
Note that it's pretty much the same functionality as in geany - it inserts linebreaks upon typing text - but not on pressing backspace, nor upon copy/pasting.
the same but more easy, I think...
put this in the user properties:
command.name.0.*=swrap
command.0.*=fold -s $(FileNameExt) > /tmp/scite_temp ; cat /tmp/scite_temp >$(FileNameExt)
command.is.filter.0.*=1
Ciao
Pietro

VIM Blockwise Insert

I would like to insert a hash at the beginning of a selected block of text in VIM (ruby comment). I selected the lines in Visual Mode, but how do I perform the same operation to all lines?
You have two primary options:
Select in block visual mode (ctrl-v), then use I to insert the same thing along the left side of the entire block. Similarly A appends; see blockwise operators.
Select the lines in normal visual (v) or visual line (V) mode, then run the same command on all of them, for example s/^/# / or normal I#. Typing : while you have a visual selection automatically uses the visual selection as the line range (denoted by '<,'>).
While in visual mode do the
:'<,'>s/^/#
actually, '<,'> will be inserted automatically when you hit :.
You better use this.
COMMAND MODE with set number to see lines
:10,50s/^/#/g
First number before comma is the start line and second number after comma is the end line. Both are included.
Another question might have copied this question, so came here from How to Insert in Visual Block Mode.
Highly recommend that people take a look at this cheat sheet: http://www.rayninfo.co.uk/vimtips.html
As people do more research into VIM people will see a lot of %s/^/# with the % sign in front and by replacing the % sign with what pops up in Visual Block Mode with :'<,'> the symbols that pop up you are able to do insert, etc.
:'<,'>s/^/# (applied on selected lines only)
:%s/^/# (applied globally)
(sharing my two cents after researching how to add a hrefs' to different lines).

I get this window while editing Ruby Files in Vim. What is it?

I usually get this new window open up suddenly while I am editing a Ruby file in VIM. This is getting irritating because, i cant type in anything while its processing. And it usually happens arbitarily. Does any one here know which plugin could be doing this? Or is this somekind of VIM's process?
This is happening when you hit K in normal mode.
K Run a program to lookup the keyword under the
cursor. The name of the program is given with the
'keywordprg' (kp) option (default is "man"). The
keyword is formed of letters, numbers and the
characters in 'iskeyword'. The keyword under or
right of the cursor is used. The same can be done
with the command >
:!{program} {keyword}
There is an example of a program to use in the tools
directory of Vim. It is called 'ref' and does a
simple spelling check.
Special cases:
- If 'keywordprg' is empty, the ":help" command is
used. It's a good idea to include more characters
in 'iskeyword' then, to be able to find more help.
- When 'keywordprg' is equal to "man", a count before
"K" is inserted after the "man" command and before
the keyword. For example, using "2K" while the
cursor is on "mkdir", results in: >
!man 2 mkdir
- When 'keywordprg' is equal to "man -s", a count
before "K" is inserted after the "-s". If there is
no count, the "-s" is removed.
{not in Vi}
If you notice, it's running ri in the open window, which is the ruby documentation app.
In Unixy environments, the help program normally runs inline, just displacing the vim output for a minute.
Is this using gvim, or command-line vim?
In either case, you can try monkeying with 'keywordprg' to fix the popup
Or, if you can't train yourself not to type it, you can just use :nnoremap K k to change what K does (in this case, just treat it as normal k command and go up one line).
I have this same issue on my work desktop, but not my home machine. The setups are near identical.
While stalking down a possible cause, I noticed that when I leave my cursor over a Ruby symbol such as File, Vim would popup a short description of the File class. After comparing all the various vim scripts and ri-related files that I could find, I finally settled on the only solution that worked...
Open $HOME/_vimrc and add the following line:
autocmd FileType ruby,eruby set noballooneval
Previously, I commented out a block in $VIMRUNTIME/ftplugin/ruby.vim, but Brian Carper suggested a better solution of :set noballooneval. I added the autocmd line so it is only executed with Ruby files.
If anyone figures out a true solution, please contact me. :(

Resources