To paste between vim and something else, use the + (plus) buffer in vim. It contains the contents of your system clipboard, and you can also write to it. If you're not already using buffers in vim, then you should probably read the excellent documentation but for a very quick start:
- To copy something into the buffer, select it in visual mode and type
- To paste from the buffer, type
I had no idea how I'd missed this really fundamental trick, so I thought I'd share!
It's possible to run R just from a prompt, which works well for individual commands but isn't great for editing those commands or keeping track of what you did. Looking around, I found that there is (of course!) a Vim-R plugin available, so I gave it a try - and really liked it! It is enabled for files ending in .R or .Rmd and allows you to launch an R prompt and run one or many lines in that prompt directly from vim.
The .Rmd format is actually for R Markdown, which is a markdown format that lets you embed R. I've been using it as a sort of lab book to keep track of what I did and why. You can then generate a document with all the R code shown and evaluated - very neat!
You may have seen this, a comment line at the start or end of a document which gives the settings for vim to use, something like this:
/* vim: set sw=2: */
This is a modeline in vim. I tried adding my own at the top of my sourcefiles, but vim seemed to ignore them. It turns out that modelines are disabled in vim by default (for security reasons) but you can easily turn them on in your .vimrc with:
The only change I want to make is the tab sizes which is why I use the line above. The vim modeline documentation is the best place to go if you want to add options of your own to this line
Getting started was a struggle, I've never really used anything like it before and if there's one thing LaTeX doesn't do well, it's error messages! The blog post I linked above has a sample presentation in it and I used that as my starting point. The source code goes in a file with a ".tex" suffix, e.g. presentation.tex. I then installed the
texlive-fonts-extra packages from aptitude, and generated a PDF by running:
latexmk -f -pdfps presentation.tex
Touring Colours in Vim
Please excuse the all-over-the-place spelling in this post, I'm British so "colour" is a word and "color" is a vim command. Confused? Me too
The setting I want is the shift width. I added this in my .vimrc file:
Hopefully this will help someone else with the same issues. I've been grappling with the tab/space/indentation settings for vim as long as I've been using it and I don't think I'm done yet. Maybe one day I'll solve it and write a big overview but for now, you can read the previous installment and pass on any tips you may have via the comments!
As an aside, I now completely understand why projects have vim settings in their files - I've got different coding standards going on inside different projects so I'm spending a lot of time fiddling with .vimrc these days!
To type the correct ^M character, you'll need to press Ctrl + V followed by Ctrl + M (the first combination means "take the next combination literally).
To turn this into a macro you should do the following. In command mode, pressq, followed by any letter. This will be the shortcut to access the macro. Then type the command as above. Finally, press q again to stop recording and its done. You can use your macro by pressing @ and then the letter you chose.