Skip to content
Jason Charney edited this page Apr 5, 2017 · 9 revisions

Clean this mess up! This page could use some tidying.

Vim, or "vi improved", is my go-to text editor. While many people prefer the simplicy of Nano or the extensiblity of Emacs, Vim has been, my preferred text editor since even before I started using Linux.

Vim 8 came out in 2016, however if you try to install vim-nox which includes the interpretors that the vim package does not enable that you'll want if you use plugins, your still going to need to install from source because Raspbian still has Vim 7.4.

Before Installing Vim

  1. Install Python. A lot of new plugins depend on a bit of Python, and you will also need to do so to use Mercurial to get Vim.
  2. Install Mercurial. Vim has a GitHub now! You don't need Mercurial...for now. But if you want to go ahead, but use the Vim Mercurial instructions later. This wiki will use the Vim Git instructions.
  3. Install gawk.
  4. Instal Lua. (sudo apt-get install lua5.1 lua5.2) We have to install lua5.1 because for some reason, the Vim configure script will not recognize lua5.2. So if you are thinking of installing Lua 5.3 from source, you might want to rethink that plan.
  5. I also recommend installing Perl (which you don't need to do because it comes with Vim), Ruby (2.1 or greater, which Raspbian has), Tcl/Tk, and Lua. Many of Vim's plugins use these languages.
  6. Install the Ruby headers (ruby-dev).
  7. Install the Perl headers (libperl-dev).
  8. Install the Python headers (libpython-dev libpython3-dev)
  9. Install the Expect and Tcl/Tk headers (tcl-dev tk-dev tcl-expect-dev)
  10. Install the Lua headers (liblua5.1-dev liblua5.2-dev)
  11. Also consider installing all this ncurses stuff if it hasn't been installed. You'll definitely need it when we install tmux later FROM SOURCE! (libncurses5 libncurses5-dev ncurses-base ncurses-bin ncurses-term)
  12. And this stuff too. autoconf automake m4 libssl-dev libtinfo5 libtinfo-dev

Basically here's a summary of every thing that probably should be installed in a single apt-get command.

sudo apt-get install gawk lua5.1 lua5.2 liblua5.1-0 liblua5.2-0 liblua5.1-dev liblua5.2-dev ruby-dev libperl-dev libpython-dev libpython3-dev tcl-dev tk-dev tcl-expect-dev auto-tools-dev libltdl-dev libreadline-dev libreadline6-dev libtool libtool-bin libncurses5 libncurses5-dev ncurses-base ncurses-bin ncurses-term autoconf automake m4 libssl-dev libtinfo5 libtinfo-dev

Installing Vim

We will need to add a ./configure step to this with interpretors for Perl, Python (2 and 3), and Ruby (it will likely come with 2.1, which is OK), and Lua. If you haven't installed them according to my instructions, consider doing so before installing Vim. You may consider using Nano for editing. We need the interpretors for Powerline or other plugins if you feel like installing them.

$ cd ~/Software
$ git clone https://github.com/vim/vim.git
$ cd vim
# The next couple of steps might seem pointless now, but they will be useful later if you want to upgrade vim
# Be sure to be in the ~/Software/vim directory when you do this as well as the building instructions.
$ git fetch                                 # fetch anything new
$ git merge                                 # merge it
# Now for the building instructions.
$ cd src
$ make distclean                 # Only do this if you've built Vim before. Ideally, run this when upgrading or recompiling.
$ ./configure --help             # See any options available
$ ./configure --enable-luainterp --enable-perlinterp --enable-pythoninterp --enable-python3interp --enable-rubyinterp --enable-tclinterp 
$ make -j4 && sudo make install

If you don't have any local changes, you can use git pull instead of git fetch and git merge. But there are a few changes that look really cool that make using git fetch and git merge the better choice. (Unless of course someone can tell me otherwise.)

⚠️ Do not use the --with-tclsh argument for the ./configure file. It will run in a continuous loop.

When vim is done installing, it will likely be located at /usr/local/bin/vim.

~/.vimrc

You need a ~/.vimrc file to set up vim correctly! For your convenience, this file has been added to this repo for you to copy to your home directory. Ideally, if you have administrative privileges, copy it to /root as well. Once you've downloaded it, you can edit it to your heart's content.

Clone the hacktop repo with git or download the file directly.

cd ~/Software
git clone https://github.com/jrcharney/hacktop
cd hacktop/vim
cp .vimrc ~
sudo cp .vimrc /root                          # So root can use these settings.

From there, you are all set to use Vim. If you are new to Vim, run vimtutor to learn how to use it.

What about SPF13?

Don't! You can add the plug ins that SPF13 or Janus uses, but don't use them. SPF13 and Janus screw up Vim. The programmers didn't design (a good) uninstall script.

Suppose I ignored that last section and did it any way, or installed something that made Vim look weird in the console when StartX is not running?

As much as I recommend not using SPF13, you just can't help but love the new features like 256 color support for consoles that have 256 color support. However, despite this being 2015, command line environments still use 16 color support.

My advice for the moment is if you install 256 color support for vim or a console, use Nano as your text editor. I'm sure someone has come up with a nice solution. I'd certainly like to see it.

Useful tips

Copypasta like a boss

Here's what you need to know about a few vim commands:

  • mX means set a mark with a mark X. X can be any letter a through z.
  • d is the start of a "delete" command, but in Vim, it really means CUT rather than delete.
  • y is the start of a "yank" command, or COPY.
  • p and P are the "put" commands, or PASTE.

The usage of d and y commands are complex, but for simplcity, well just explain cutting or copying from a mark to the current line. Assuming you've set a mark, you can scroll to the other line that you want to set as the place to cut or copy from. It can be above or below the line you marked, it really doesn't matter. If will matter if you use number in your cut/copy command, so we won't mess with that.

A good way to keep thing straight is to use the buffer d for when you delete (cut) a set of lines, and y for when you yank (copy) a set of lines. Thus.

  • d'd means "delete the lines from here (the current line) to where mark d is marked"
  • y'y means "yank the lines from here to where mark y is marked."

This here is the process for deleting (cutting) a set of lines and pasting them elsewhere.

  1. md (mark the current line with the mark d.)
  2. Scroll up or down to the other line you wish to use as a boundary.
  3. d'd delete the lines from d to here. The lines between where d was marked and the line that the cursor was currently one should be removed.

Now let's see how yanking (copying) works. This here is the process for deleting (cutting) a set of lines and pasting them elsewhere.

  1. my (mark the current line with the mark y.)
  2. Scroll up or down to the other line you wish to use as a boundary.
  3. y'y delete the lines from y to here. The lines between where y was marked and the line that the cursor is is still there.

Note that these two methods DO NOT store our lines to a named buffer. Marks and buffers are not the same.

Finally the putting (pasting) part.

  • Use p to put the cut or copied lines on the next line.
  • Use P to put the cut or copied on the current line.

For more information see

See Also

External Links

Setup

  1. [Assemble the Hardware](Assemble the Hardware)
  2. [Install the Software](Install the Software)
  3. 🆙 [Setup your Raspberry Pi](Setup your Raspberry Pi)
  4. [Download the Missing Parts](Download the Missing Parts)

Typical Utilities

  • [Downloading and extracting with curl and tar](curl and tar)
  • [Browsing with ls and cat](ls and cat)
  • [Searching with grep and find](grep and find)
  • [Filtering with sed and awk](sed and awk)
  • [Piping with less, pv, and tee](less, pv, and tee)
  • Monitor your system with htop
  • Multiplex with tmux

Clone this wiki locally