Posts Tagged ‘vim’
Friday, April 26th, 2013
This is the vim find and replace command I used to switch from the legacy DynamicSparseMatrix command coeffRef to the new format using the Triplet class.
%s/\([^\.]*\).coeffRef(\([^,]*\),\([^)]*\)) *+= *\([^;]*\);/\1_IJV.push_back(Triplet<Scalar>(\2,\3,\4));/g
Tags: dynamicsparsematrix, eigen, sparsematrix, triplet, vim
Posted in code | No Comments »
Monday, December 31st, 2012
Snippet to find and replace appropriately:
%s/assert(\(.*\));/if(!(\1)) mexErrMsgTxt("\1");/g
Tags: assert, c#, matlab, mex, vi, vim
Posted in code | 1 Comment »
Thursday, November 15th, 2012
vim creates little files to keep a persistent undo. The names are like:
.filename.txt.un~
The dot prefix and the tilde suffix make these files a pain to deal with in bash. Here’s how to move these files to another directory:
mv .*un\~ other_directory
Tags: bash, dot, full stop, mv, period, tilde, undo, vi, vim
Posted in code | No Comments »
Tuesday, September 27th, 2011
I recently download the glsl syntax highlighting plugin for vim. It perfectly recognizes my .vert and .frag files. But as soon as I added the line:
#version 120
vim starting thinking the filetype was not glsl but conf.
The cause seems to be that the glsl plugin suggests a rather weak form of recognizing the filetype. Adding the following to your .vimrc file
au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl setf glsl
When instead to override whatever vim is doing to think that the file is conf you must use the only slightly different
au BufNewFile,BufRead *.frag,*.vert,*.fp,*.vp,*.glsl set filetype=glsl
Tags: glsl, shader, syntax, syntax highlighting, vi, vim, vimrc
Posted in code | 2 Comments »
Wednesday, June 22nd, 2011
You can remove the swap file (.*.swp) of the current file in vim with a simple command in command mode:
:!rm .%.swp
Tags: delete, file, recover, remove, swap, swo, swp, vi, vim
Posted in code | No Comments »
Thursday, May 12th, 2011
Editting .tex files with vim I noticed that sometimes I got full syntax highlighting, but other times only certain keywords were markes and the colors were a bit different. Turns out this was because vim was occasionally recognizing files (based on keywords) as plaintex rather than tex. You can see what filetype vim thinks you have open by issuing:
:set ft
For a bit I was fixing this on a case-by-case basis, if vim’s highlighting was wrong I would issue:
:set ft=tex
and that would fix it for at least the current file and session.
The real permanent fix was to add the following to my ~/.vimrc file:
let g:tex_flavor = "latex"
Now all my .tex files are recognized as tex and not plaintex.
Tags: latex, plaintex, syntax highlighting, tex, vi, vim
Posted in code | No Comments »
Wednesday, December 15th, 2010
Here’s a simple bash one-liner that converts a quad mesh stored in an OBJ file into a triangle mesh stored in a OBJ file. It splits every quad (a,b,c,d) into two triangles (a,b,c) and (a,c,d).
I issue this in the bash shell of my mac (you may have to tweak the sed syntax):
cat quads.obj | sed -E -e "s/f ([0-9\/]+) ([0-9\/]+) ([0-9\/]+) ([0-9\/]+)/f \1 \2 \3`echo -e "\r"`f \1 \3 \4/g" > triangles.obj
Or I open the file with vim and use:
:%s/f \([0-9\/]\+\) \([0-9\/]\+\) \([0-9\/]\+\) \([0-9\/]\+\)/f \1 \2 \3\rf \1 \
3 \4/g
Tags: bash, mac os x, mesh, obj, quad, regex, sed, triangle, vi, vim
Posted in code | No Comments »
Tuesday, November 30th, 2010
I excitedly upgraded vim to the new vim 7.3 (persistent undo is the big feature). To my dismay all the fancy digraphs I’ve been using to display math characters stopped working. And when I issued:
:digraphs
I only saw a handful of characters (maybe just ASCII), certainly no interesting unicode characters.
Luckily the fix was easy. I just needed to enable the “multi-byte” feature. To do this, in the vim project directory I issued:
./configure --enable-multibyte
make
sudo make install
Tags: mac os x, vi, vim
Posted in code | No Comments »
Monday, September 20th, 2010
A friend at work wanted to be able to see the name of the current file he was editing in vim without closing it or saving it. The solution he found was to enter in command mode:
<ctrl> <shift> G
This displays a little info bar on the bottom.
This made me remember that you can use % as a standin for the current file's name when issuing a command. As in:
:!echo %
which displays the current file name (up to bash gotchas).
Or you could write the current file to filename.temp with:
:w %.temp
I used this in an earlier post to typeset a latex document from vim as a oneliner.
Tags: bash, vi, vim
Posted in code | No Comments »
Tuesday, August 31st, 2010
I use the following at the end of my .vimrc file to force vim to highlight cmake’s CMakeLists.txt files like any other cmake file:
au BufNewFile,BufRead CMakeLists.txt set filetype=cmake
Looks much better than whatever it was trying to do before, which for me was nothing.
Tags: cmake, highlighting, syntax, vi, vim, vimrc
Posted in code | No Comments »