When we are on the subject, does anybody know a decent "indention-fixer" that does NOT change the code in any way (like removing / adding { or }), but fixes the code so indention is alwayws a multiple of 4 spaces, and that replaces TABs with spaces? Some of my sorce-files have become a mixture of 4 and 8 space indentions (some of my tools incorrectly replace TAB with 8 spaces). I used some Linux-based tool years ago, but it broke my code as it tried to add / remove {} as well, which was no hit.Kevin wrote:So what are the configuration changes that both of you made?
I just checked my config and there isn't much special stuff in it. The only big thing is cscope integration (which I consider essential), and then there are smaller useful things like highlighting trailing whitespace or anything > 80 characters in a source file, enabling FPC extensions for Pascal syntax highlighting etc. I tried things like omnicppcomplete because everyone keeps saying that you absolutely need some context-sensitive autocompletion, but to be honest I found it to be more annoying than helpful. So I'm back to Ctrl-P for now.
Best IDE for OSDev / Cross Compiling
Re: Best IDE for OSDev / Cross Compiling
Re: Best IDE for OSDev / Cross Compiling
VIM.
Makes shift vs. tab visible. (Trailing spaces, too...)
Sets the relevant values (how big an indent should be / how far a tab should indent).
Tells VIM that indents should be spaces, not tabs, and activates the indent plugin.
Runs the indent plugin over the current source file.
If you have everything but the :retab in your ~/.vimrc, all you have to do is to call :retab to turn tabs into spaces for the given source file.
(Or vice versa, I know we have some TAB users out there.)
Combined with a macro, re-tabbing several thousand source files is a matter of a dozen keystrokes and 1-2 minutes waiting time. I did just that recently.
To get rid of trailing spaces:
qq/\s\+$
d$@qq@q
(qq - start recording macro for key 'q'. /\s\+$ - search for 1..n trailing spaces. d$ - delete until EOL. @q - call self. q - end recording. @q - execute macro for key 'q' (until EOF).)
Code: Select all
:set listchars=tab:>-,trail:·
:set list
Code: Select all
:set shiftwidth=4
:set tabstop=4
Code: Select all
:set expandtabs
:filetype plugin indent on
Code: Select all
:retab
If you have everything but the :retab in your ~/.vimrc, all you have to do is to call :retab to turn tabs into spaces for the given source file.
(Or vice versa, I know we have some TAB users out there.)
Combined with a macro, re-tabbing several thousand source files is a matter of a dozen keystrokes and 1-2 minutes waiting time. I did just that recently.
To get rid of trailing spaces:
qq/\s\+$
d$@qq@q
(qq - start recording macro for key 'q'. /\s\+$ - search for 1..n trailing spaces. d$ - delete until EOL. @q - call self. q - end recording. @q - execute macro for key 'q' (until EOF).)
Every good solution is obvious once you've found it.
Re: Best IDE for OSDev / Cross Compiling
You can also use = in visual mode to reindent only a specific part.
But I would really use :%s/ \+$//g for this one.
Oh, that's a nice demonstration of macros, maybe I should take a closer look some time.Solar wrote:To get rid of trailing spaces:
qq/\s\+$
d$@qq@q
But I would really use :%s/ \+$//g for this one.
Re: Best IDE for OSDev / Cross Compiling
Sadly any trivial demonstration of macros (and quite some non-trivial ones) can also be done with a search-and-replace.Kevin wrote:Oh, that's a nice demonstration of macros, maybe I should take a closer look some time.
But I would really use :%s/ \+$//g for this one.
One advantage of the macro is that it remains bound to the 'q' key until replaced with a different macro (including being saved on exit). Yes, VIM also keeps a command history, but that's limited in size, and doesn't come with the mnemonic of the key.
Every good solution is obvious once you've found it.
Re: Best IDE for OSDev / Cross Compiling
The thing is the source sometimes contains 4 spaces for a single indention, and sometimes 8 spaces, so trivial replace will not do it. The tool needs to understand C-syntax, but should not fiddle with { and }.
Re: Best IDE for OSDev / Cross Compiling
= does do this.
Re: Best IDE for OSDev / Cross Compiling
Not quite. If you have both 4 and 8 space indents, retab/= will see that as two different indent levels.
Re: Best IDE for OSDev / Cross Compiling
With emacs: 1. set up indentation for c-mode (google) 2. C-< C-space C-> M-x indent
I'm not so familiar with or interested in some vi-clone as a more IDE or anything, I use emacs when I need more power, and nvi when doing simpler things.
I'm not so familiar with or interested in some vi-clone as a more IDE or anything, I use emacs when I need more power, and nvi when doing simpler things.
Re: Best IDE for OSDev / Cross Compiling
= doesn't care about the original indentation, it reformats everything (and I seem to remember that it doesn't always understand everything correctly, which is why I'm usually very careful with it).Rusky wrote:Not quite. If you have both 4 and 8 space indents, retab/= will see that as two different indent levels.
Re: Best IDE for OSDev / Cross Compiling
I just ran = on this:
It simply replaced each " " with a tab. My ~/.vimrc looks like this (partial):
More generally, one interesting setup would be to use eclim to integrate vim with Eclipse. That way you get an IDE with the text-editing capabilities of vim.
Code: Select all
{
asdf
asdf
}
Code: Select all
set tabstop=4 shiftwidth=4
filetype plugin indent on
Re: Best IDE for OSDev / Cross Compiling
But your test "code" isn't valid C code. vim probably interprets it as one line-wrapped statement. Put a semicolon at the end of each line and it will indent them to the same level.
Re: Best IDE for OSDev / Cross Compiling
Good point. That does work. However, :retab is apparently not equivalent to =, at least when converting to tabs.
Re: Best IDE for OSDev / Cross Compiling
Yes, retab is different, I think it only converts n spaces to a tab (or vice versa).
Re: Best IDE for OSDev / Cross Compiling
I downloaded & installed VIM for Windows, made the changes to the _vimrc file as below:Kevin wrote:= does do this.
Code: Select all
:set shiftwidth=4
:set tabstop=4
:filetype plugin indent on
Re: Best IDE for OSDev / Cross Compiling
I was talking about visual mode where you select a block that you want to have reindented (it can be started with v or Shift-v). In normal mode you need to specify the range on which = should work, for example G for "until the end of the file". Do this on the first line and the whole file is reindented, so everything combined gives you a gg=G in normal mode.