4 ms·
These are all good tips but most of the anti-patterns seem to skew towards beginners (e.g. don't use the arrow keys, don't navigate in insert mode). One that I
by foob 10y ago
These are all good tips but most of the anti-patterns seem to skew towards beginners (e.g. don't use the arrow keys, don't navigate in insert mode). One that I think is more common among intermediate, and even advanced, users is the misuse of tabs, windows, and buffers.
A lot of people have a tendency to think of each tab as corresponding to a single open file. This is very understandable because it closely matches the paradigm of most IDEs but it's actually an anti-pattern in VIM. Tabs are really meant to be more like workspaces where you arrange multiple windows into a desired layouts. You then have one buffer for each file that you're dealing with and view them in your windows. It's perfectly fine for multiple windows to share a single buffer or to switch out the buffer that is being viewed in any given window. This StackOverflow answer [1] and this blogpost [2] both go into a fair bit more detail.
If you're trying out this approach for the first time then you probably want to add `set hidden` to your configuration in order to avoid automatically closing buffers that aren't currently being viewed in a window. Coupling this approach with fzf.vim [3] makes managing very large numbers of files a breeze compared to using one tab per file.
[1] - http://stackoverflow.com/a/26710166 http://stackoverflow.com/a/26710166
[2] - http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-tabs/ http://joshldavis.com/2014/04/05/vim-tab-madness-buffers-vs-...
[3] - https://github.com/junegunn/fzf.vim https://github.com/junegunn/fzf.vim
- grimgrin 10y agoFor any Windows devs that happen to use vim inside of mintty (that comes with downloading git), you'll discover that installing fzf doesn't work out so well. It'd be fine on cygwin, surely. In mintty, though, it'll yell about missing ncurses and then offer to install the legacy Ruby version, which also fails for curses related reasons. So, that said, check out ctrl-p. https://github.com/ctrlpvim/ctrlp.vim https://github.com/ctrlpvim/ctrlp.vim It's a nice quick way to see a filelist that you can filter, like fzf. You can filter on: * the whole project, excluding .gitignore stuff * all open buffers * Most Recently Used (MRU) file list In addition to the built in ^p binding, I also add: nnoremap <leader>v :CtrlPMRUFiles<cr> nnoremap <leader>b :CtrlPBuffer<cr>
- sevensor 10y ago> vim inside of mintty (that comes with downloading git), Is git for windows using msys2 yet? If not, do yourself a favor and start using msys2 instead. It has packages for git and vim, and it uses pacman for pacage management. I've had a great experience using it.
- grimgrin 10y agoThis looks really promising. Thanks. And Git for windows is using mintty, which is a terminal emulator for cygwin, msys, and msys2, but I'm not really sure what is being provided/used. A buncha unix tools and definitely not a package manager. And for those unaware: > MSYS2 is an independent rewrite of MSYS, based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 with the aim of better interoperability with native Windows software. > The name is a contraction of Minimal SYStem 2, and aims to provide support to facilitate using the bash shell, Autotools, revision control systems and the like for building native Windows applications using MinGW-w64 toolchains. > We wanted a package management system to provide easy installation of packages, and ported Arch Linux's Pacman. This brings many powerful features such as dependency resolution and simple complete system upgrades, as well as providing the build system - makepkg{,-mingw} - which is used to make these packages Also: http://stackoverflow.com/a/25023611/463678 http://stackoverflow.com/a/25023611/463678 Github: https://msys2.github.io/ https://msys2.github.io/
- sevensor 10y agoMsys2 also has mintty, and I can attest that tmux works great, if that's a consideration. This is pretty much where I spend my days (Msys2 / mintty / tmux / vim) when I have to work in Windows.
- grimgrin 10y agoIs there a popular convention for using something like this or cygwin, in that it has its own $HOME, and I have a buncha dotfiles in my Windows user home? Possibly just symlinking it all over to MSYS $HOME? I am definitely happy about being able to install tmux. edit: just seems like I should ditch what I was doing in windows home, because git bash used the same home and I had everything there. ssh stuff, git config, inputrc, .vim, etc. But if I'm no longer using git bash, no need. edit: sadly git runs very oddly in this. not sure what git bash is doing differently, but I'm comparing .64 seconds for a git status, versus over a minute with MSY2. weird.
- gchadwick 10y agoPersonally I just never use tabs. Things like ctrl-p or the built-in tab completion for :buffer and :edit make switching files so quick I don't really need multiple workspaces. But I then I pretty much exclusively work with three windows side-by-side, NERDTree, File 1, File 2. I guess if you like switching window layouts a lot then tabs could be very useful.
- vlunkr 10y agoThank you! you just sent me down a rabbit hole of figuring buffers out, but it was totally worth it. That second link is especially nice.
- dhimes 10y agoYeah, I dunno. I see your point and will certainly explore it, but I easily use tabs for both. I mostly use marks to skip around in a file and tabs for opening different files. Why? Because I can see them. The drawback with buffers (and too many marks and registers etc.) is that it's easy to lose track of where things are. So tabs make buffers easy- you can glance up and see where the file that you need is. The numbering system is a little screwy (starting at 1 instead of 0) though.
- cyberpunk 10y agoWell, I've been using vi and it's brethren since about 2002 and I've pretty much always used the arrow keys; after some point it becomes muscle memory... I never really understood what the problem with this was; I rarely actually use them (esc|capslock /str,ctrl+f|b etc) is usually how I move around and if I'm wanting to move a few chars my little finger is not moving very far (at least, on apple keyboards)... Is this heathen territory? ;) Do you see any big advantage of using a lot of buffers/tabs/splits over running multiple vims inside tmux? My workflow seems to be more multiple vim's and shells inside tmux (I have ` as my "control key" in tmux, which is right beside z on my keyboard) which always feels quicker to me than ctrl+ww or ctrl+w<arrow>; and I really like the "zoom" functionality there... hitting `` to switch between windows in tmux is really nice, too.. :}
- u801e 10y ago> Do you see any big advantage of using a lot of buffers/tabs/splits over running multiple vims inside tmux? One advantage would be the ability to use vim registers to copy text from one buffer to another instead of having to go through tmux or screen. Another would be word or line completion in a given buffer using contents in another buffer. In general, by running multiple vim instances instead of a single vim instance, you lose the opportunity to leverage vim to manage multiple buffers by using information in a given buffer.
- gizmo385 10y ago> Do you see any big advantage of using a lot of buffers/tabs/splits over running multiple vims inside tmux? I think my personal benefit is that I don't have to make a bunch of new SSH connections every time I want to split files in vim, I can just open up a new buffer.
- deleted 10y ago[deleted]
- happyslobro 10y agoThank you for the tabs and buffers reminder, that is something that I should keep in mind now that I'm using Vim on a 4K monitor. At that scale, it feels perfectly natural to have 9 to 12 windows open, so that all of the sources that I might need to even consider are within my field of view. I just wish I had more control over window layouts. Something like the controls of a good tiling window manager, like I3. There is just no way to open 12 files in a list of windows, and then arrange them into a sort of rectangle tree, but I prefer to open all the files I will need at once from the command line, using globbing operators and brace expansion.
- JadeNB 10y ago> One that I think is more common among intermediate, and even advanced, users is the misuse of tabs, windows, and buffers. The author addresses that, too, in https://sanctum.geek.nz/arabesque/vim-misconceptions https://sanctum.geek.nz/arabesque/vim-misconceptions: > The model Vim uses for [tabs and windows](https://sanctum.geek.nz/arabesque/buffers-windows-tabs https://sanctum.geek.nz/arabesque/buffers-windows-tabs) is rather different from most GUI editors, but both are supported and have been for some time.