Snippet to find and replace appropriately:
%s/assert(\(.*\));/if(!(\1)) mexErrMsgTxt("\1");/g
Snippet to find and replace appropriately:
%s/assert(\(.*\));/if(!(\1)) mexErrMsgTxt("\1");/g
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
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
You can remove the swap file (.*.swp) of the current file in vim with a simple command in command mode:
:!rm .%.swp
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.
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
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
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.
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.
I use the following at the end of my .vimrc file to force vim to highlight Qt’s .pro project files like a make file:
au BufNewFile,BufRead *.pro set filetype=make
Looks much better than whatever it was trying to do before.
Dear spammers, you may enjoy posting on auto blog instead
Switch to mobile version