Vim Tip: Open file in new tab
Posted by: nico on
Oct 21st, 2009 |
Filed under: Programming, Vim Tips
Posted by: nico on
Oct 21st, 2009 |
Filed under: Programming, Vim Tips
Posted by: nico on
Oct 6th, 2009 |
Filed under: Vim Tips
Not all is lost, you don’t have to commit sepuku (at least not for this one). Just use Vim’s indent method like this:
:set foldmethod=indent
That should give you a better view of the code flow. As always, use ‘%’ to navigate all those pesky { and }.
Posted by: nico on
Sep 17th, 2009 |
Filed under: Vim Tips
![]() |
Are you still puzzled by last week’s C++ question, yet you are too lazy to actually search for a Rot13 decoder OR use gcc to check if it works? Well, Vim can do the trick, just use g? to convert text to Rot13 |
You may combine it with block selection or you can just convert the whole damn thing using “ggg?G”. gg goes to the beggining, g? converts to rot13, G goes to the end.
This is all very nice but I’m still trying to figure out a way to convert back from rot13 to normal text, can anyone provide a clue?
Posted by: nico on
Sep 8th, 2009 |
Filed under: Gnome, Linux, Programming, Vim, Vim Tips
Someone recommended me Inconsolata as a nice programming font (it’s monospaced). I’m using it right now and it’s not bad. Let’s see how can you install it:
Easy and it looks even better when used with gVim. You can go to Edit > Select font to change the font preference, however this won’t set a new default for the next time you start gVim. To do this we need to add it to the .vimrc, and again, to do this we need to know the font’s name.
Type “:set guifont?” to see the font’s name. In my case it’s “Inconsolata Medium 14″ (I changed size and type). Now add the following to your .vimrc:
Notice I added a backslash before the spaces, otherwise Vim will try to parse Medium and 14 as separated parameters to “Inconsolata”, which obviously won’t understand. Have fun with your new fonts.
Posted by: nico on
Aug 13th, 2009 |
Filed under: Vim Tips
![]() |
There’s an easy way to select the whole contents of the document: “ggVG”. May seem like a lot at first glance but let’s review it part by part: |
gg: Go to the beggining of the document
V: Enter visual mode
G: Go to the end of the document
Easy, isn’t it? Now you can press any other command to copy, delete or whatever you like.
Did you knew that Vim can “Make your woman smile for a week”?
Me neither: http://www.vim.org/trivia.php.
![]() |
Editing source code means you’ll be doing a lot of indenting and reindenting. There’s an easy way to indent or de-indent a block, using just “<” and “>”. |
Using “>” without anyother command will indent that line by itself; use visual mode (Shift + V) to select several lines and indent them in one keystroke. You could also press “v%>” while sitting at the beggining of a block to indent it. The same applies to “<”.
![]() |
Vim is the best editor for programmers and as such it has some neat “programmer commands”, which make editing source code a lot easier. Take for example a block with code, or a function definition: how many times did you have to copy the code between parenthesis from one place to the other? |
You could do ’0f(df)’ to delete “int bar, int baz” but that won’t do if the definition is more complicated than that. ‘dib’ is a better choice to delete the text.
(ACTION)i{b|B} applies ACTION to a block, for example, pressing diB in
(with the cursor placed at _) will delete lots of source code.
![]() |
So, you have a paragraph, or any kind of text, and need to replace a substring without altering other paragraphs. You could write :set number and then :A,Bs/what to search/what to replace/g, being A and B the start and end of the paragraph, or you could just use visual mode. |
Enter line selection mode (Shift + V) and then select a block of text. Without moving the cursor any further type :s/SEARCH/REPLACE and the search string in the selected block will be replaced without altering any other part of the document.