Useful Vim tips


#1

Something I found very useful when configuring my own .vimrc file was the reload command, reducing the need to keep saving, closing and reopening:

:so %

Although I understand it actually means ‘source current file’. Please add your own…


#2

Hi! Since Zed forgot it:

undo: u
redo: CTRL-R


#3

Thanks! Yes, I had a brain fart and couldn’t make my hands work. I’ll see if I can work that into the beginning of the next Seminar.


#4

@gpkesley That’s definitely useful. To extend it, I found these via Google:

  • nnoremap <leader>sv :source ~/.vimrc
  • nnoremap <leader>ev :e ~/.vimrc

This way, if I think of something while I’m Vimming, I can add it real quick right then.


#5

My nr 1 tip ( that I didn’t respect recently) : never copy a .vimrc file without understanding what each line does.
Not even if it’s Zed Shaw’s .vimrc :smiley:


#6

I have another tip that I found as a result of laziness. For those like me who don’t already know it, autocmd InsertLeave * write will cause Vim to save every time you get out of insert mode. Saving is important, and this way, it becomes less of a hassle. The only time you still have to save is after editing in normal mode.


#7

On the last Vim school I wanted to know the difference between ^ and 0 which both seemed to go to the beginning of the line.

However, when the text is indented it is clearer that ^ goes to beginning of (indented) text whereas 0 goes to the beginning of the line (including any white space).


#8

Tight! I’m going to add this autocmd today and try it out. Thanks!


#9

I’ve been using https://github.com/vim-airline/vim-airline-themes for formatting the status bar. Even this simple display is pretty neat at highlighting which mode you are in, the language detection, character count, etc.

I use Vundle so installation is simple, and the .vimrc config is also very simple.

Here’s an example of the clarity:


#10

I’m using powerline since they have a plugin for tmux too so they both look the same:


It looks like this:
Normal mode:

Insert mode:

Visual mode:

I admit I’m a sucker for those arrows, had to install some powerline fonts to make them appear :smiley:
@gpkesley , are you sure you don’t need to install some fonts? Those question marks appeared to me too when I didn’t have them installed.
it’s cool they patched lots of fonts so you can continue using your favourite font in vim. It looks the same but contains a few more characters like those arrows and so on.
They even patched my fav font from Pop OS :wink:


#11

Hmmm, can’t remember but I wasn’t overly bothered about fonts, just a visual indicator of the mode I was in.

I did spend a while playing with Vim themes before realising that I didn’t need them.

I must admit, I’ve not used tmux a lot since realising ctrl-z and fg were so useful.


#12

I love the ctrl-z fg trick too, didn’t know about it till Zed told us, but I got used to tmux and sticking with it.
I just switch between bash and vim with ctrl+A and arrow (mapped caps to ctrl, told you)


#13

I’m glad I learned about tux. I think for dashboarding it’s excellent. Particularly if you have a server running and need to view logs as well as inputting via other windows. Shame you can’t run browser in one pane.


#14

But you can :smiley:
You can use lynx and see how google really sees web pages :wink:
https://lynx.browser.org/
I mainly used it for testing accessibility or when checking the consistency of a page for SEO.
Not using it anymore, just saying it’s doable…


#15

Let’s see @io_io, you can do:

ctrl-z – Pause the current thing.
jobs – that command shows you what is running.
bg – Take that last thing and make it run again, but in the background.
fg – Take that last thing and pull it into the foreground again.

Then if you give fg and bg a job number it will do that to whatever job number that is.

This is kind of what made Unix awesome back in the day. The ability to start jobs and make them go in the background.

AND, if you want to see how you do all that in Python, here’s my library that does:


#16

Thank you, will take a look!
In fact I remember I forked that but didn’t know much Python at that time.


#17

More useful maps:
inoremap ( ()<Left>
inoremap [ []<Left>
inoremap { {}<Left>
Never worry about missing parentheses or brackets again. And as aside, I notice, @zedshaw, that you don’t seem to use anything like these. Personal preference?


#18

I tend to keep things simple and just use what’s working for me @TriforceHero777. I may try a few of these suggestions though as they sound great.