What's the quickest (as far as anyone knows) way to change this:
int main()
{
into this:
int main() {
provided the cursor is on the {
?
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this communityWhat's the quickest (as far as anyone knows) way to change this:
int main()
{
into this:
int main() {
provided the cursor is on the {
?
It actually took me a little while to figure this out on my own, too: dh
Now, I use a macro for "merging" lines like this: let @m=' 0i ^[0wd0dhi ^['
This will take the current line, with the cursor positioned anywhere on that line and merge it with the previous line, while inserting a space, and leave you back in NORMAL mode. Note: the ^[
are escapes gotten by typing ctrl-r<Esc>
which is control-r then the esc key. To be sure you've done it correctly, those two characters will behave as one if you try and move the cursor over them.
Put the above line in your ~/.vimrc or ~/.vimrc.local and then either restart vim or do :source ~/.vimrc
dh
will result in int main(){
, not int main() {
, and it only works if you've added h
to your whichwrap
setting.
– Rich
Apr 5 '17 at 8:35
whichwrap
setting. Learning something new every day.
– GH05T
Apr 5 '17 at 13:01
Besides that I think that opening braces on a separate line is the better style, you can do
:g/^\s*{\s*$/-1j
to append all occurences in the whole file of opening braces in a separate line to the previous line.
If this is your coding style (for some no good reason), you can add this to your .vimrc
to be executed automatically when opening source code files.
kJ
? (and some more text is here because comments need it :) ) – grochmal Apr 5 '17 at 1:18