Hacker News new | ask | show | jobs
by Arch-TK 507 days ago
I've always just closed vim to use the terminal, and started it up again to go back to editing. I find it difficult to operate any other way.

I know people who use ^Z to suspend vim and then foreground it again.

2 comments

> I've always just closed vim to use the terminal

You don't mind losing all your editor state? If you don't like working with multiple terminal windows, why not open a term within vim with `:term`?

I don't lose any editor state, at least nothing I care about.

In my configuration vim will save (among other things):

- Cursor position

- Undo history

- Register state

:term is clunky for me, mainly because my muscle memory is to just :wq

I got it working as seamlessly as I could once just in an attempt to use it but I stopped pretty quickly.

What editor state are you losing when you leave vim?

I run a pretty light vanilla vimrc (60 lines maybe) and with two lines you can enable vim undofiles and returning the cursor to the last location upom reopening a file. For me, quitting vim is functionally equivalent to ^Z?

You may lose LSP state like rust-analyzer's which takes a while to restore. You may lose opened buffers and positions within them (unless you have some session restore logic which may also take time), window layout, copy buffers, edit history and lots of other state.
Ah I don't run any LSPs so that's fair.

Retaining positions, buffers, and edit history between sessions is all straightforward in vanilla vim though. Unless you run an autolinter or formatter that edits your target file and wipes the history.

For that there is ra-multiplex (to which I contributed sockets support).

I don't use any other LSPs which have a long warmup time, but if I did then they can also be used behind ra-multiplex.

You lose the open windows/tabs. Apart from trivial one-off scripts I basically never have only a single tab open.
I don't use tabs, sometimes I use split windows (usually only when vim-diffing), mostly I use multiple terminal windows in a tiling WM. I do use multiple buffers but I usually don't care about editing more than one or two at a time and it's easy to re-open these whenever I need to.
That's true for me too but usually my tabs and windows are managed one level higher, by the terminal emulator, or I'm opening vim with -o/-O to open a split window directly.
I’ve definitely done the ^Z thing. The catch is to remember you did it if you get distracted in the terminal. Nothing like finding some vim job in the background and you can’t remember what it was.
For me it only works because I never reuse a single terminal for unrelated things. Additionally, I have my virtual desktops grid set up so that different types of tasks are always in certain places, so if the switcher shows a terminal somewhere, I know roughly what it's for even without going to look at it. So I can't "lose" a terminal.

So it's fine for X11 terminals, but not for /dev/tty2

Don't forget you can just :!some-shell-command though - not just in vim but in lots of programs even.