In NeoVim (not really Vim but humor me :P), I can create panes with terminals in it. So I don't need Tmux anymore. Also, I can use Vim bindings for scrolling through the terminal panes and copy stuff. That feature made my workflow way more fluid.
Don't worry, I’m a neovim user myself. ✊
I’m actually the other way around in regards to neovim’s :terminal, though. I am using tmux, and prefer splitting the tmux window instead of starting a terminal session in Vim.
I must say I’ve never taken the time to set :terminal up properly, as I’m still getting a couple of “command not found” errors when starting it.
Fun fact: I’ve actually tried using tmux splits instead of Vim’s built-in ones a while back, but that didn’t really work because I didn’t find a way to share sessions between Vim instances.
So, what does your workflow look like? Do you open up Vim and do everything from there, in one instance?
Yes, I do everything inside Nvim now. When I was using Vim+Tmux, I was using a plugin for moving between Vim and Tmux panes transparently. I also needed special config for getting access to the system's clipboard. That wasn't necessary when I got rid of Tmux. Are you using those plugins?
The only thing I had to do for getting my Nvim's terminal splits just the same as iTerm's was to source my .bashrc file inside .bash_profile. I also added some useful mappings like:
" Maps ESC to exit terminal's insert mode
tnoremap <Esc> <C-\><C-n>
" Maps ctrl-b + c to open a new tab window
nnoremap <C-b>c :tabnew +terminal<CR>
tnoremap <C-b>c <C-\><C-n>:tabnew +terminal<CR>
" Maps ctrl-b + " to open a new horizontal split with a terminal
nnoremap <C-b>" :new +terminal<CR>
tnoremap <C-b>" <C-\><C-n>:new +terminal<CR>
" Maps ctrl-b + % to open a new vertical split with a terminal
nnoremap <C-b>% :vnew +terminal<CR>
tnoremap <C-b>% <C-\><C-n>:vnew +terminal<cr>
also removed the number lines and got terminal buffers to automatically enter into insert mode with
" Enter Terminal-mode (insert) automatically
autocmd TermOpen * startinsert
" Disables number lines on terminal buffers
autocmd TermOpen * :set nonumber norelativenumber
I'm attaching a screenshot of my current setup. Also here's my dot file repo if you want to take a look 🤓 github.com/jesusabarca/.dotfiles
I use vim-tmux-navigator to switch between Vim and tmux splits, configure Vim to use the unnamed paste buffer, and use reattach-to-user-namespace to do the same in tmux (although that doesn’t seem to be required anymore).
I’ll try the built-in terminal again sometime soon, though!
Terminal panes have been in Vim since 8.1 I think. This is still commonly touted as a reason to use neovim, but it's not really an issue nowadays.
Cool, I didn't know that. I went from Vim 7.x directly to Nvim.
I personally prefer just using iTerm panes.
| | Webpack |
| vim |---------|
| | Backend |
My favorite so far is setting macros in command-line mode.
This post basically blew my mind. I don't actually use macros that often and when I do I always get stage fright whenever I start recording. But as the article says, macros are just registers that you can set and edit.
If I wanted to convert this.
const test = require('tape')
import test from 'tape'
I would start typing a command.
Inside the quotes I'll write the keys that the macro would execute. The cool thing about this is that if you get something wrong you can undo, go back in the commands history, edit the macro and try again.
The final result would be this.
:let @i='^cwimport ^[f=cwfrom^[wdwds(j'
There is just no way I would get that right on the first try.
You'll have to be careful with special characters like "Escape". The way you get then in the command is by pressing ctrl+v first. For the escape character you would press ctrl+v first and then the escape key.
Macros have been near the top of the list I’ve been planning to properly figure out for years now, I just never get around to it. I always have a hard time blindly recording macros with q<letter><commands>q.
I love the idea of writing macros in command mode, and having them available in the command history. That article looks great, too. Great suggestion!
Brace yourself... you can still use your q...q command to record them as you go. Then, find a blank line somewhere and "qp and boom - your macro is right there. Tweak it, then highlight it and "qy and now @q will replay your new one.
Blew my mind when I figured out there was nothing special about qq.. it's just putting things into a buffer to replay.
Here are a number of tricks in core Vim I've found useful over the years:
vim filename +line_num
vim filename +/pattern
And it's not technically a Vim trick, per se, but I like running my shell in Vi mode!
There are a couple of tricks in Vim that I love.
about your 1. there's another more awesome trick:
when renaming variables, you can search for it using / or * (reverse with ? or #) and use cgn (reverse cgN) to modify it, using . to change the next match.
The -gn movement is working on the next match. So you can spare one key (n or N) when bulk renaming variables.
tl;dr : Instead of
you can do:
NeoVim has a "preview" functionality when you're doing substitutions.
First: set inccommand=split
Then, enjoy incremental highlighting of the text that will be impacted by any substitutions until you hit [ENTER]: :%s/foo/bar/g
Column selection and insertion in multiple rows. Ctrl + V to select vertically and then I to insert in multiple rows.
The operations you can do with the built-in file explorer (aka netrw):
I don't know. I used mostly ADT for Effectedkeyboard development, but I indeed edited config files and there splitting lines accidentally or jumping to a new line was a hustle(?) So J and B worked just fine
*. Find the next occurrence of whatever "word" is under the cursor.
I have many tricks on at my "init.vim"
"Make search faster
:nnoremap <space> /
"Alternate "nonumber | number | relativenumber"
:nnoremap <C-n> :let [&nu, &rnu] = [!&rnu, &nu+&rnu==1]<cr>
" allows me to use a smarter cgn
nnoremap c* *<c-o>cgn
nnoremap c# #<C-o>cgn
" allows to type gf to "go to file"
I also like "Ctrl-6" to jump to alternate buffer ":%y+" to copy the entire buffer to the clipboard. "gx" to open links. "gv" to reselect. "gi" to start insert at the last inserting point.
" Use whole "words" when opening URLs.
" This avoids cutting off parameters (after '?') and anchors (after '#').
" See http://vi.stackexchange.com/q/2801/1631
" copy the last command to clipboard
" avoid clipboard hacking security issue
inoremap <C-R>+ <C-R><C-R>+
On my ~/.zshrc and ~/.bashrc I have
" lvim opens the last edited file on vim
alias lvim='vim -c "normal '\''0"'
# Edit clipboard on a vim scratch buffer
alias vimscratch="vim -c 'setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile'"
alias pbpaste='xclip -i -selection clipboard -o'
alias pbcopy='xclip -selection clipboard'
alias vcb="pbpaste | vimscratch -"
# Open files very quicly using fzy
alias nfu='nvim $(find ~/.dotfiles -type f | fzy)'
Vim has a biult-in file explorer: :E
I use it to open existing files or just to explore the filesystem through the terminal
:%!python -m json.tool
Auto pretty formats json files :)
I like to encrypt files sometimes.
vim -x /path/to/file/somefile.txt
My favorite Vim trick is Spacemacs 👀
Anywho, macros. I know it sounds a bit basic but boy are they powerful (and they turn heads, both in a technical and non technical setting).
Macro! Definitely macro! (Although it is a feature not a trick)
Whenever I want to search for the current word, I just type:
and then n or N to navigate through the results.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.