Changing vim defaults for editing Go files

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Changing vim defaults for editing Go files

Luveh Keraph
I am using vim to edit Go language files. vim does something that I find really irritating, but that I do not know how to override.

When I add a line like

    import (

vim automatically inserts several tab characters in the next line, leaving the cursor at the end of those characters.

I hate that. I would like to have a single tab character, not several. Or even nothing at all. Anybody know how to change this behavior? This may be silly of me, but if I cannot change that I'd rather use a less clever and proactive editor.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Changing vim defaults for editing Go files

Gary Johnson-4
On 2017-11-03, Luveh Keraph wrote:

> I am using vim to edit Go language files. vim does something that
> I find really irritating, but that I do not know how to override.
>
> When I add a line like
>
>     import (
>
> vim automatically inserts several tab characters in the next line,
> leaving the cursor at the end of those characters.
>
> I hate that. I would like to have a single tab character, not
> several. Or even nothing at all. Anybody know how to change this
> behavior? This may be silly of me, but if I cannot change that I'd
> rather use a less clever and proactive editor.

This appears to be due to some of your option settings.  I don't use
Go; I just tried some experiments starting from:

    $ vim -N -u NORC --cmd 'filetype indent plugin on' thing.go

Typing

    import (

and hitting Enter indents the new line by a 'shiftwidth'.  By
default, this is a single tab.  This behavior is affected by at
least:

    'shiftwidth'
    'tabstop'
    'expandtab'

If you are seeing several tab characters at the start of that new
line, it would be because your 'shiftwidth' setting is some multiple
of your 'tabstop' setting.

There are a number of ways to change that behavior to what you want.
I would recommend creating a file named

    ~/.vim/after/ftplugin/go.vim

and putting there the option values you want, set using "setlocal",
not "set", so that they will apply to only Go files.

Take a look at:

    :help 25.3
    :help 'shiftwidth'
    :help 'tabstop'
    :help 'expandtab'

HTH,
Gary

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Changing vim defaults for editing Go files

Frank Shute
In reply to this post by Luveh Keraph
You don't mention if you are using the vim-go plugin:

https://github.com/fatih/vim-go

You might want to give it a try.

With regards about vim formatting your Go source this way or that,
it's somewhat moot because you have to run your source through the Go
formatter before you can run/build it.

When I write Go with vim, I generally don't worry too much what it
looks like; as long as it's legible and then just let 'gofmt' do it's
stuff.


Regards,

On 3 November 2017 at 17:06, Luveh Keraph <[hidden email]> wrote:

> I am using vim to edit Go language files. vim does something that I find really irritating, but that I do not know how to override.
>
> When I add a line like
>
>     import (
>
> vim automatically inserts several tab characters in the next line, leaving the cursor at the end of those characters.
>
> I hate that. I would like to have a single tab character, not several. Or even nothing at all. Anybody know how to change this behavior? This may be silly of me, but if I cannot change that I'd rather use a less clever and proactive editor.
>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.



--

Frank

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.