Friday, November 3, 2017

Re: Changing vim defaults for editing Go files

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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: