One note with the “Passing request to Consul services” section: when you use a DNS name in proxy_pass
, that name is only ever resolved at startup. If the IP address the domain name points to could ever change you should define an upstream
. Nginx only does normal DNS TTL / refresh in upstreams.
This is rarely mentioned and you learn it the hard way. @alexdzyoba I think it’s a good thing to add to your great article :)
I have previously documented a workaround for this (although, really the open source version should just support this): https://tenzer.dk/nginx-with-dynamic-upstreams/.
Ah yes, I had seen the variable hack once before! Both the variable hack and upstreams need the resolver set, so both will do the trick.
Thanks for pointing out! But what about “valid” option in resolver directive? It should control the TTL for DNS cache.
It does, but proxy_pass
doesn’t use DNS TTL, it only ever resolves once, unless you use a variable or an upstream. The Nginx docs aren’t very clear, but the resolver
setting says it’s used for upstreams.
For over 10 years I’ve been a very ardent (some would say zealous) supporter of (n(eo))vim, carefully tweaking and updating my configuration to be as barebones or as feature-full as I needed and desired, and spreading the gospel of Vim to all those that would listen.
About 6 months ago I tried out the vimagit plugin, which I found immediately useful. I then realized that this plugin was based off of the emacs magit package, which intrigued me further, and that sent me down a rabbit hole of trying out emacs with evil-mode (gasp! horror!).
I’ve been a (spac)emacs+evil user since that day. It combines all of the muscle memory that I know and love (complex word motions, edit sequences, etc.) from vim, and gives me a TUI-based editor that has all all of the project/IDE based functionality that I had always spent far too much time configuring and fighting against in vim. I just don’t have the energy for that anymore.
If you’re like me and love vim, and are looking to “revamp” your setup like the post describes, give Spacemacs a try. There are others, too (e.g. doom-emacs), and there are of course the DIY build-it-yourself setups that you can tinker with endlessly, but I was completely astounded by how intuitive and how short of a learning curve spacemacs with evil mode was.
Yes, I saw magit from my colleague and that’s how I discovered vimagit. I’ve heard good things about evil mode but I’m not ready to try yet, though you’re sound convincing.
The emacs magit package was the primary reason I tried the switch. After watching a few instructional videos & reading some documentation, I had to try it out. It’s every bit as good as I had hoped for.
Using emacs+evil with some project-level plugins like helm for autocompletion and projectile for navigation has been fantastic. It took me a few days to get used to some of the different key combinations to navigate around, but that was quite minimal in the grand scheme of things.
One of these days I’m gonna bite the bullet and try out emacs. I have so much invested into my vim environment that it scares me to leave….
Are we talking vim trix? Oh my god I love talking vim trix.
Neovim has an integrated terminal. One thing I like doing is making an autocommand that, whenever I save the file, runs a specific test suite in the terminal. It’s like a lightweight test runner.
Another Neovim thing: set inccommand=nosplit
. This shows you realtime what an :s
command will do, and they’re working on extending it to normal
and g
.
One thing you might not have realized about the undo: it’s not a list of changes, it’s a tree. You can navigate it both chronologically and changewise and jump between different branches. I use the mbbill//undotree
plugin to visualize it. Absolutely fantastic.
kshenoy/vim-signature
shows marks on the sidebar and lets you add marks like !
or ?
to your file.
I’ve been doing some weird exobrain experiments too, but those aren’t anywhere near ready to share yet =)
I haven’t found a good use for embedded terminal but I think that’s because I use i3 and terminals everywhere.
Could you elaborate on your terminal case? Maybe share the autocommand?
Good article; I have a few nitpicks :-)
autocmd FileType yaml set tabstop=2 shiftwidth=2
you should never use set
from an autocmd
, as that will affect all buffers, not just the YAML one, so if you have a YAML and Python buffer open then both will be affected; yikes!
Always use setlocal
(or setl
for short) if you want to set something specific to the bufer.
In addition, it’s good practice to keep autocommands in an augroup:
augroup my-yaml
autocmd!
autocmd FileType yaml set tabstop=2 shiftwidth=2
augroup end
otherwise reloading the file means set
will get run twice (try it: :source ~/.vim/vimrc | au FileType yaml
) For this set
(or setl
) command it’s not a huge deal, but for other stuff there’s a large performance penalty. Also see: Why should I use augroup?.
source ~/.vimrc
You can use ~/.vim/vimrc
as well; that has worked since Vim 7.3.something (a long time). This way all your vim files are in one directory.
I agree the undo history is very useful, but it’s annoying that it it’s easy to accidentally use it. I wrote a little plugin which, IMHO, improves the UX of it a lot: https://github.com/Carpetsmoker/undofile_warn.vim
you also need to create that undodir manually, otherwise it won’t work. This is what I have:
set backupdir=$HOME/.vim/tmp/backup " Set/create directory to keep backup, swap, and undo files.
set directory=$HOME/.vim/tmp/swap
set viewdir=$HOME/.vim/tmp/view
set undodir=$HOME/.vim/tmp/undo
if !isdirectory(&backupdir) | call mkdir(&backupdir, 'p', 0700) | endif
if !isdirectory(&directory) | call mkdir(&directory, 'p', 0700) | endif
if !isdirectory(&viewdir) | call mkdir(&viewdir, 'p', 0700) | endif
if !isdirectory(&undodir) | call mkdir(&undodir, 'p', 0700) | endif
Newer Vim versions won’t error out if the directory already exists, so I suppose this can be a little simplified now.
For Insert mode completion I think the future is Language Server Protocol (LSP); this way we’ll have one LSP client for Vim that will work for everything (provided there is a lsp). I am currently using vim-lsc, and it works very well. There are many more options (ALE also includes an LSP client, for example).
At any rate, here’s my ~/.vim directory, in case you’re interested: https://github.com/Carpetsmoker/dotfiles/blob/master/vim/
you also need to create that undodir manually, otherwise it won’t work.
No, the article is about Neovim, which automatically creates ‘undodir’ and ‘directory’ (swapfile directory) if needed. But not ‘backupdir’.
if !isdirectory(&directory) | call mkdir(&directory, ‘p’, 0700) | endif
mkdir(&directory)
(and mkdir(&undodir)
, etc.) isn’t advisable for most users, because those options are comma-separated lists.
I didn’t want to emphasize on Neovim and I believe most of the things I use can be applied to Vim.
P.S. Thanks for Neovim!
IMO, Vim help is the most underestimated feature of Vim
I have been using vi/vim since .. 1999(?) and it took me a looong time to get beyond beginner. The fact that we still have to learn vim tips by sharing configs and articles speaks to how poorly the documentation is presented. My primary sources for going beyond beginner were vimcasts and more recently greg hurrell’s screencasts.
It’s fine that help is built in for powerusers, but in a typical terminal window, :help gets half the width or height. Good luck reading new material like that while trying it out. I have never been able to find an up-to-date vim documentation in HTML format. I just now discovered that neovim has documentation available in browsable HTML format.
Also, I cannot find Vim changelogs anywhere. I learned about packs and async by accident. I still don’t know how to use async. Looking at neovim.org, I see the latest news is from 2017, so I assume nothing worthwhile has happened since then.
Looking at neovim.org, I see the latest news is from 2017, so I assume nothing worthwhile has happened since then.
Plenty has happened. Newsletter is coming soon.
There’s also a releases page that makes it pretty clear that several major releases have occurred, not to mention the pulse page.
Thanks.
You will probably want to include releases with changelogs under the news headline. For example, on OpenBSD.org, it only takes one click from the front page to get a list of changes in the most recent release.
I agree that Vim documentation is hard for newcomers. But for me it was invaluable.
Also, I’ve used https://vimhelp.org/ as up-to-date online doc. Currently it’s built for Vim 8.1.
Also, I cannot find Vim changelogs anywhere. I learned about packs and async by accident.
The Vim changelogs are within its help system, linked from within the Versions section in the top-level help. The most recent file describing changes is at :help version8.txt
– it describes packages, async I/O, and more in its New Features section. (Note that Vim’s async implementation works differently from NeoVim’s.)
Nice article.
Beware that InstrumentHandler
is deprecated, and the functions in https://godoc.org/github.com/prometheus/client_golang/prometheus/promhttp are the recommend replacement.
Splitting out latency with a success/failure label is also not recommended as a) if you have only successes or only failures, your queries break and b) users tend to create graphs of only success latency and miss all those slow failing requests. Separate success and failure metrics are better, and also easier to work with in PromQL.
Thanks for the suggestions Brian! promhttp package contains even more nice things like in flight requests. Maybe we should explicitly say ok in docs that InstrumentHandler is deprecated in favor of promhttp types? I don’t mind making a PR in docs
That’s already mentioned in the docs: https://godoc.org/github.com/prometheus/client_golang/prometheus#InstrumentHandler
This article is insanely good: easy to ready, actual examples & situations. Please write some more :)
Thanks, that means a lot for me as an author.