Friday, September 25, 2015

More on Editing Multiple Documents in vim

Using vim Windows

We’ve talked about using buffers to edit multiple documents in vim. Each file lives in a buffer which, in turn, lives in it’s own tab page, rather like a tab in a web browser. But sometimes I want to view one file while editing another, and it would be handy to have both files in the same screen at once. To support that, vim gives us windows.
To split the screen into multiple windows in vim, switch to command mode and run :split or control-w followed by s. This will split the screen into two windows, each containing a copy of the file that was in the original screen. Running :split again will create a third pane, and so on.
If you want to open the new pane with a different file, run :split myfile. This will open a new window with the other file loaded inside. To open a window with a new, blank file, run :new or control-w n.
The active window can be resized with with the command :resize # or z#, where the # sign is the number of lines high that the window should be.
To move up and down among the visible windows use control-w k and control-w j respectively. To close the selected window, run :close or press control-w c.
There are actually many commands to manipulate buffers and windows in vim. These are the basics and will get you through most common tasks. To learn more, go to vim’s command mode and run :help window.
Be seeing you.

Friday, September 11, 2015

I'm an Alias, I'm a Legal Alias

Useful Command Aliases

When working from the command line I like to cut down on the amount of typing that I do because a) I get in a hurry, and b) I fat-finger the things I’m trying to type, so c) I end up doing things over to get them right. I use aliases to take some common tasks and shorten them up so that I can save time and face.
If you look at my *nix systems you’ll find several aliases for various incarnations of ls:
alias l='ls -F'
alias la='ls -a'
alias ll='ls -lh'
The first of these, -F, appends a character to the end of the file name to identify the file type: * for executable files; @ for symbolic links; and / for directories. Regular files don’t have any special character following their names. While most Linuxes and BSDs use a colorized ls command these days, this is useful if you need to work from a terminal or remote session that doesn’t support color.
The second alias lists all files, including hidden ones, and the third displays a detailed listing with file sizes in “human readable” format: gigabytes or megabytes instead of bytes.
Aliases can be more sophisticated, standing for piped output. When I use the df command to check free disk space, usually I just want to see mounted logical volumes and not pseudo-filesystems and LVM disks. I pipe the output of df to grep to get what I want:
alias dfh='df -h | grep -v "^[[:alpha:]]"'
And to see a sorted list of details about my own processes:
alias myps='ps aux | grep ^$(whoami) | sort -k 2b'
An alias can also contain several commands—a mini-script, if you will:
alias sched='echo ""; cal; echo ""; calendar -w 3; echo ""'
Perhaps I have inspired you to experiment with aliases and discover some of the cool things you can do with them.
Be seeing you.

Tuesday, September 8, 2015

Editing Multiple Documents in vim

Using vim Buffers

When editing a file in vim it is stored and displayed in a buffer, something like a tab in a web browser window. You can open multiple files at once and easily move back and forth among the buffers to work with each file.

Opening Multiple Files in vim

To open multiple files in vim when you start your session, simply list them on the command line:
$> vim myfile1 myfile2 myfile3 myfile4
This will start vim with four buffers pre-loaded with your four files. You can use wildcards:
$> vim documents/myfile*
If you already have vim running and want to open another file, go to command mode and type:
:e documents/myfile5
You’ll be happy to know that you can use tab completion with the :e command. If you want to create a new file within vim, from command mode run :enew which will open an empty buffer. Just remember to save the file with a name anytime before you exit:
:sav documents/myfile6
To see the buffers open in your current session, from command mode run :buffers. Note that each buffer lists the file that it contains, and each has a unique number. To move to a different buffer, run :b# where the # sign represents the number you want to move to. For example, to begin editing the file in buffer number 3, run:
:b3
Keep in mind that before you can switch to a new buffer you must save or discard all the changes made to the current one. Use the :w command to save your file before changing buffers.
You can cut, copy and paste among buffers just as you would within a single file. Just remember that if you make a cut you will need to save the changes in the current file before switching to the target buffer.
When you no longer want to work on a file you can close its buffer with the “buffer delete” command, :bd. This command closes the file in the current buffer and deletes the buffer; the file is not removed. By adding a number you can delete a specific buffer. For example:
:bd3
This will close the file in buffer 3 and delete the buffer. And quitting vim will close all files and delete all buffers.
Be seeing you.

Thursday, September 3, 2015

PowerShell and Chocolatey Goodness

A movement has long been afoot to bring a useful package management system to Windows. If you’ve used apt or yum or yast or some similar tool in a Linux distribution, then you know how easy it can be to install new software to your computer with the right utility. Enter chocolatey, the PowerShell package manager for Windows.
Before starting a new class I make sure I load up my instructor computer with my favorite text editor and my chosen file manager:
choco install -y vim doublecmd
If I’m going to play videos for my class, I may also add a nice player:
choco install vlc
Of course, if I see that the machine I’m using has an older version of PowerShell I may want to update that:
choco install -y powershell4
What if I don’t know the name of the package I want? If I want to install the Angry IP network scan tool but know not what the package is called, I’ll ask chocolatey:
choco search angry
This is such a cool tool that rumor has it that even Microsoft is interested in using it. We’ll see. Perhaps managing software in Windows will soon be as easy as it is in Linux.
Bee seeing you.