Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some changes to the vimrc #186

Merged
merged 10 commits into from
May 15, 2018
Merged

Some changes to the vimrc #186

merged 10 commits into from
May 15, 2018

Conversation

chrisbra
Copy link
Contributor

@chrisbra chrisbra commented May 8, 2018

Hi this branch changes some of the Vim settings. I tried to make the commits as granular as possible to make reviewing easier.

Currently some settings can be improved a bit, so I slightly changed them. I tried not to change them according to my personal taste and if I did, I mentioned it in the commit message (cursor block style, command line completion, ...) and those could then reverted if needed.

The rest should keep Vim more closely to Vims upstream repository, especially since it sources the defaults.vim file anyhow (currently overwriting some settings).

Also I found comments beneficial, so I left a couple of more comments. One thing I did not know for sure is the usage of EDIT_MERGEMSG and EDIT_MSG. I am not sure whether both of them are needed or only one of them (and the other one was a typo). For now I left it as is (and added the other one to the settings as well. This can easily be reverted if needed. Also if this is correct, it might be beneficial to add some of this to upstreams filetype detection logic.

@dscho
Copy link
Member

dscho commented May 14, 2018

@chrisbra thank you for your contribution!

Could you please add "Signed-off-by:" footers to the commit messages (that's why the DCO bot marks this PR with a red X)?

git-extra/vimrc Outdated
@@ -1,16 +1,16 @@
" Setting some decent VIM settings for programming
" This source file comes from git-for-windows build-extra repository (git-extra/vimrc)

ru! defaults.vim " Use Enhanced Vim defaults
set mouse= " Reset the mouse setting from defaults
aug vimStartup | au! | aug END " Revert last positioned jump, as it is defined below

This comment was marked as off-topic.

This comment was marked as off-topic.

git-extra/vimrc Outdated
@@ -11,6 +11,7 @@ set vb " turn on the "visual bell" - which is much quie
set laststatus=2 " make the last line where the status is two lines deep so you can see status always
set showmode " show the current mode
set clipboard=unnamed " set clipboard to unnamed to access the system clipboard under windows
set wildmode=list:longest,longest:full " Better command line completion

This comment was marked as off-topic.

This comment was marked as off-topic.

autocmd BufReadPre COMMIT_EDITMSG,MERGE_MSG,git-rebase-todo setlocal fileencodings=utf-8

"Remember the positions in files with some git-specific exceptions"
" Remember the positions in files with some git-specific exceptions"

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

git-extra/vimrc Outdated
\ && expand("%") !~ "MERGE_EDITMSG"
\ && expand("%") !~ "ADD_EDIT.patch"
\ && expand("%") !~ "addp-hunk-edit.diff"
\ && expand("%") !~ "git-rebase-todo" |
\ && expand("%") !~ "addp-hunk-edit.diff" |

This comment was marked as off-topic.

This comment was marked as off-topic.

git-extra/vimrc Outdated
@@ -20,13 +20,13 @@ set statusline=%<%F%h%m%r\ [%{&ff}]\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(ex
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Set UTF-8 as the default encoding for commit messages
autocmd BufReadPre COMMIT_EDITMSG,MERGE_MSG,git-rebase-todo setlocal fileencodings=utf-8
autocmd BufReadPre COMMIT_EDITMSG,MERGE_EDITMSG,MERGE_MSG,git-rebase-todo setlocal fileencodings=utf-8

This comment was marked as off-topic.

This comment was marked as off-topic.

git-extra/vimrc Outdated
@@ -37,6 +37,4 @@ if has("autocmd")
autocmd Filetype diff
\ highlight WhiteSpaceEOL ctermbg=red |
\ match WhiteSpaceEOL /\(^+.*\)\@<=\s\+$/

autocmd Syntax gitcommit setlocal textwidth=74

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

set statusline+=\ (%{strftime(\"%H:%M\ %d/%m/%Y\",getftime(expand(\"%:p\")))}) " last modified timestamp
set statusline+=%= " Rest: right align
set statusline+=%l,%c%V " Position in buffer: linenumber, column, virtual column
set statusline+=\ %P " Position in buffer: Percentage

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

git-extra/vimrc Outdated
@@ -25,6 +25,12 @@ set statusline+=%= " Rest: right align
set statusline+=%l,%c%V " Position in buffer: linenumber, column, virtual column
set statusline+=\ %P " Position in buffer: Percentage

if &term =~ 'xterm'
let &t_ti.="\e[1 q" " Use a blinking block cursor when entering termcap mode

This comment was marked as off-topic.

This comment was marked as off-topic.

git-extra/vimrc Outdated
endif
if 0
set termguicolors " Allow trucolors on mintty
endif

This comment was marked as off-topic.

This comment was marked as off-topic.

@dscho
Copy link
Member

dscho commented May 14, 2018

I reviewed all patches, and left a few comments and suggestions.

chrisbra added 9 commits May 14, 2018 20:36
Signed-off-by: Christian Brabandt <cb@256bit.org>
This is actually useless, since further down we are actually setting the
statusline option to be displayed. So remove it.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Since version 8 Vim comes with the defaults.vim file distributed. That
file is already sourced on startup (as seen by the `:scriptnames`
command). However it loads usually after the system vimrc file, so it
could potentially overwrite settings that are set here without notice.

Instead, go ahead and source the file directly here and to prevent that
it will be loaded again after this file has been processed, set the
`skip_defaults_vim` variable.

While at it, reset the mouse setting which is set in defaults.vim. When
the mouse option is enabled, this prevents the usual copy/pasting with a
mouse from the terminal. Instead you would have to use <Shift> Mouse to
mark and copy. Revert this to the usual terminal behaviour.

Also do remove the last-position jump that is defined in defaults.vim,
since this file defines its own last-positioning jump so it is not
necessary to have it execute twice.

Signed-off-by: Christian Brabandt <cb@256bit.org>
The wildmode setting defines, how the files (and commands) are completed
in Vim. This means editing a file using `:e file` you can press tab and
have file autocompleted.

Unfortunately, the default command line completion for
files is rather un-intuitive when compared to e.g. bash or zsh (which
complete to the longest common string and then stop to show all possible
candidates and wait for the user to decide what to complete), since it
will complete to the first match.

This is not only unintuitevly, but also cumbersome, since you have to
watch carefully for the path being completed, possibly hit <BS> several
times to correct the wrong match, type something again, have it possibly
be completed to the wrong match again, correct again, etc...

To fix this, set the 'wildmode' option to a more sane setting, that will
stop at the longest common string and show possible completions and wait
for the user to complete further.

I argued to have this default setting changed
https://groups.google.com/d/msg/vim_dev/gL5DXac4NaU/sYTDeWctAwAJ, but
Bram decided that he likes the current behaviour better.

Signed-off-by: Christian Brabandt <cb@256bit.org>
The last position jump that is defined here, uses a couple of specific
file names to decided whether to skip jumping to the last position.

Vim however already knows some of those filenames and will set the
filetype option for those files to 'gitcommit' or 'gitrebase'.

So simplify this logic a bit, by checking against the filetype setting
when deciding if the cursor should be positioned at the last known
position for that file. This uses Vims regular expression engine to
check against a specific filetype, e.g. the filetype option matches
either 'commit\|gitrebase'

This is also more in sync with the example in the help (and in
defaults.vim) of Vim (:h last-position-jump), which basically skips this
for all commit like filetypes (so not only git, but also e.g. for the
mercurial filetype hgcommit).

The other filenames are currently not detected automatically by Vim, so
leave them there as is. However, if those are specific files that should
be detected automatically by Vim (and set to a specific filetype) it
might make sense to send a patch upstream.

While at it, have all comments start with a '" ' (e.g. add a leading
space after the comment character) to be consistent. This is only a
stylistic change.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Files with the '.diff' extension are automatically detected by Vim as
filetype=diff. So that specific autocommand can be removed.

Also files with the .patch extension are already detected as
filetype=patch, unless the first lines starts with 'From ...' in which
case Vim will set the filetype to gitsendemail.

Actually the logic there is:

  au BufNewFile,BufRead *.patch
	\ if getline(1) =~ '^From [0-9a-f]\{40\} Mon Sep 17 00:00:00 2001$' |
	\   setf gitsendemail |
	\ else |
	\   setf diff |
	\ endif

So leave this untouched for now and have patch files always set to
filetype diff.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Use a filetype autocommand instead of syntax autocommand, as this seems
to be more standard like, e.g. use Filetype autocommands instead of
Syntax autocommands.

Signed-off-by: Christian Brabandt <cb@256bit.org>
The default ftplugin for gitcommit files sets a textwidth setting of 72.
Do not overwrite it.

Signed-off-by: Christian Brabandt <cb@256bit.org>
In addition, instead of the absolute path, show only the relative path
(%f/%F). This makes it simpler to edit another file using :e because one
knows directly from which path to complete. Also this saves a bit of
space.

While at it, drop the `%<` (truncation atom), since by default, Vim will
start truncation from the start of the statusline (:h 'stl' search for <)

If desired, the path could be shown as well.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Currently, the call to termguicolors is disabled, because it does not
seem to look to good with the default settings (font is way too bold).

The termguicolors settings allows to use true colors (RGB values,
instead of using the 8/16/88/256 color index from the default xterm)
inside the terminal. This allows for a bit nicer colorschemes.

Most modern terminal emulators do support this nowadays. For the status
see https://gist.github.com/XVilka/8346728

One can use this oneline to check the status:
  printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"

Nevertheless, do not enable this option by default, leave it uncommented for
now. If the user wants this, he can simply uncomment/enable the option.

For now, only enable 256 colors (even if Vim detected only 8 usable
colors). 256 colors are supported by all terminals nowadays, even if
they only identify themselves as xterm compatible instead of xterm-256colors.

Hide the whole setting behind the check for the $TERM option, so it
won't influence a Vim run from cmd.exe

Signed-off-by: Christian Brabandt <cb@256bit.org>
@chrisbra
Copy link
Contributor Author

Could you please add "Signed-off-by:" footers to the commit messages (that's why the DCO bot marks this PR with a red X)?

Yeah I saw that, once I created the PR. If I had been a bit more careful before creating the PR, I would have Signed-off all those commits. I usually do not follow the git practice in this regard.

But since I had to reword (and slightly change) some of the commits anyhow, I also added Signed-off-by header.

Also I reworded the commits as required to explain a bit, why something was changed (and dropped the use blinking cursor commit, that was unneccessary and I should have configured my terminal directly instead of trying to fix this in Vim.)

autocmd BufReadPre COMMIT_EDITMSG,MERGE_MSG,git-rebase-todo setlocal fileencodings=utf-8

"Remember the positions in files with some git-specific exceptions"
" Remember the positions in files with some git-specific exceptions"

This comment was marked as off-topic.

@dscho dscho merged commit 0ca37d9 into git-for-windows:master May 15, 2018
@dscho
Copy link
Member

dscho commented May 15, 2018

Thank you for your contribution, and for your patience with me!

@chrisbra
Copy link
Contributor Author

Thanks for merging. One minor comment

I try to make a point in this project to be inclusive. Next time, please include the roughly 50% of humanity that happens to have a different sex than you do.

Hm I always thought he refers to the user which in my understanding would be neither masculine nor feminin. In German I don't think of 'männlich' wenn talking about "der Anwender". But it's not my monther tongue as you might guess, so I beg for pardon for the misunderstanding.

@dscho
Copy link
Member

dscho commented May 15, 2018

I always thought he refers to the user which in my understanding would be neither masculine nor feminin

No, in English "he" refers to a male being. Imagine how you would feel if you were addressed as a "she" 100% of the time? That's exactly why this should be avoided. Hence the "singular they". Example:

Whenever a user wants to open a file using Git's default editor, they only need to call git config -e -f <path>.

dscho added a commit that referenced this pull request May 16, 2018
The vim configuration [was
modernized](#186).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants