Tag Archives: vim
Vimdiff and Vim to Compare Files
Vim and HTML Tags with the Surround Plugin
Continue reading
Copy/Pasting and Vim
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
"+y
- To paste from the buffer, type
"+P
I had no idea how I’d missed this really fundamental trick, so I thought I’d share!
Working with R and Vim
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!
Using Modelines in Vim
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:
:set modeline
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
Creating Presentations with LaTeX
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-latex-extra
, latexmk
, vim-latexsuite
, latex-fonts-recommended
and texlive-fonts-extra
packages from aptitude, and generated a PDF by running:
latexmk -f -pdfps presentation.tex
256 Colours in Vim
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
I grabbed two fantastic scripts – the Vim Color Sampler Pack and the rather awesome ScrollColors plugin which allows you to cycle through all your colorschemes and try them out.
Set Vim Shift Width
The setting I want is the shift width. I added this in my .vimrc file:
set sw=4
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!
Vim Macro: cleaning up line endings
:% s/^M$//
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.