-
Notifications
You must be signed in to change notification settings - Fork 0
Using Vim
Do we really need this? Probably not but in my (biased) opinion if you're working on spock, which means you're using ssh and probably X-Fowarding, then you can use some fancy text editor like sublime but in general the fact that you're interacting through an ssh tunnel will slow down operations. This slowing down of operations in my experience is pretty annoying and so, why not learn to use a light-weight hassle free editor that is already on spock and is a much much better option than sublime, atom, [insert inferior editor].
OK, first a joke... how do we create a random sequence of character? Easy, get a bunch of undergraduates into vim and then tell them to try and figure out how to get out of vim. However bad the joke, it serves a purpose and it's this: without patience vim can be frustrating, without willingness to Google vim can be impossible. Keeping this in mind below I present some the bare bones to using vim.
Getting into vim:
If you'd like to create a file that doesn't yet exist do so with the command:
vi my_file_name.txt
that command will start up vim, and will (after you've succeeded at writing to it and saving it) create a file named my_file_name.txt. Once you're in vim you need to hit the key i on your keyboard to get into "edit" mode. Edit mode is a mode in vim which lets you alter the text of the document you've opened. To get out of edit mode hit the key esc on your keyboard. To save what you've done so far follow the sequence of commands:
- if you're in edit mode hit
escto get out of it - hit the keys
shift+;on your keyboard to make the character: - hit the key
won your keyboard - you should now see
:wat the bottom left of your screen - hit enter
A thing to note, you can also use vim to open up existing files, in the example above my_file_name.txt would simply be the path to the file you want to open. So if you are currently in the directory where a.txt lives, then you would do vi a.txt, accordingly if you are in some directory say /scratch and the file you want to open (again a.txt) is in your home directory then you would do vi ~/a.txt (as an aside, ~ is short hand for the path to your home directory which could be something like /home/username).
That sequence (before the note/aside) saves your changes and does not take you out of vim. That sequence also demonstrates a pattern for commands in vim. There are possibly an innumerable number of commands (because of addons) that you can perform while in vim, and for any command the first "element" of it must be the character :, hence we do shift+; to get :
Likewise to evaluate that command you must hit enter once you've gotten your desired pattern (where a pattern simply means something like :w).
Given the information above lets briefly look at some other commands:
- Saving your changes to a file and exiting vim
:x - Forcing an exit from vim while throwing away any edits you might have made
:q! - Setting line numbers
:set nu - Removing line numbers
:set nonu
Aside from commands there are also various keyboard shortcuts. These are sequences of patterns that you type that perform some action, for example hitting the key d twice will delete a line. Hitting the key v will get you into "visual" mode which allows you to highlight portions of the file (that you can then perform operations on). Hitting cntrl+d will result in a "jump" several lines down the file and cntrl+u will jump you up the file.shift+b will jump you to the start of the preceding "word" in a line, shift + w will jump you to start of the proceeding word. check this link for a condensed specification of commands and shortcuts.