To open a new file in a horizontal split I can do:
:sp file.py
Is there a way to open my native terminal (I'm on mac) in the same way? Something like:
:sp terminal?
:terminal is what you want.
See :help terminal
My vim mappings
nmap <leader>t :term<cr> " horizontal split
nmap <leader>tv :botright vertical terminal<cr> " vsplit
Related
I'd like to be able to open my wiki in a similar way that :vsplit some/file.md works.
This might be a known issue with some terminals, as seen in this answer.
You can still remap the command if you'd like, for example:
:nmap <Leader>vs <Plug>VimwikiVSplitLink
Or if it does not interfere with your bindings:
:nmap <Leader>vs :VimwikiVSplitLink<CR>
EDIT
Now that I finally understood your request, to launch vimwiki from vim in a split you can just chain commands, i.e.:
:sp | :VimwikiIndex
:vs | :VimwikiIndex
This should do the trick.
For remapping, as #DavidVII pointed out, just escape the |:
nmap <Leader>vs :vs \| :VimwikiIndex<CR>
Since I've started using Vim tabs (I'm a bit late to the game since they've been there since 2009!), I find I'd like most thing to default to tabs, so I always open files with vim -p file1 file2 etc. I would like :help / :h to always open in tabs also. I can do :tab help ctrl-w or :tab h ctrl-w but how can I use .vimrc to always default :h or :help to open in a new tab?
Additionally, is there a way to take an open file and push it into a tab, or to tell vim to take all open buffers and dynamically shift them all into tabs?
"take an open file and push it into a tab"
You can do that with this normal mode command:
<C-w>T
or this equivalent Ex command:
:wincmd T
See :help ctrl-w_t and :help :wincmd.
":h to always open in tabs"
You only need to put the aforementioned Ex command in after/ftplugin/help.vim:
wincmd T
You can use autocmd to always open help in a new tab
" This won't work if you open the same help file more than once
autocmd FileType help wincmd T
" This works
autocmd BufEnter *.txt if &filetype == 'help' | wincmd T | endif
Or you can define a new command to only open it in a new tab, when in a small screen or there are many to read, for example.
With the following, you can use :Tabhelp ....
function! Tabhelp(arg)
execute 'tab help '.a:arg
endfunction
command -nargs=? -complete=help Tabhelp call Tabhelp(<q-args>)
I'm currently trying to write my own setup for autocompiling and previewing LaTeX code using Vim and Zathura. This is the code I have currently have in my tex.vim file:
:map <F6> :w <bar> ! pdflatex -synctex=1 -interaction=nonstopmode %<CR><CR>
:map <F7> :! zathura $(echo % \| sed 's/tex$/pdf/') & disown<CR><CR>
This works fine as long as when I compile the code (from Vim) I am in the directory where my tex files are. However, I would like this to work regardless of my position (since I frequently open files from Vim using the :e command). How do I fix this?
Also, I would like Zathura to open only if the PDF preview is not already open. Does anyone have any suggestions as to how to do such a thing?
You can use :h filename-modifiers instead of your sed hack, so this should do:
nnoremap :<C-u>w <bar> ! pdflatex -synctex=1 -interaction=nonstopmode %:p<CR>
nnoremap :<C-u>! zathura %:p:r.pdf<CR>
I have also changed these mappings to use :nnoremap which you should prefer anyway.
If you want to expand your Vim-fu even further you can check :h compiler and :h compilet-tex which will handle setting proper 'makeprg' for you which will allow you to use :make to build your TeX files.
An alternative would be to simply use vimtex (https://github.com/lervag/vimtex)
Mapping: <localleader>lv
I am looking for a way to automatically resize my open v-split panes in Vim after I call NERDTreeToggle.
I have NERDTreeToggle being called on the shortcut "ctrl+\" at the moment, and ideally what I want is to call the keyboard shortcut "ctrl+w =" immediately afterwards.
Any ideas? Thanks.
If this is your current mapping:
:nnoremap <C-\> :NERDTreeToggle<CR>
You can just append the window command after it:
:nnoremap <C-\> :NERDTreeToggle<CR><C-w>=
Alternatively, you can execute this from command-line mode as well, via :normal!:
:nnoremap <C-\> :NERDTreeToggle<Bar>execute "normal! \<lt>C-w>="<CR>
Note that for window commands, there's also a special :wincmd to invoke them:
:nnoremap <C-\> :NERDTreeToggle<Bar>wincmd =<CR>
I'm trying to open a PDF file from Vim using the commands
let openpdfname = "!open " . expand("%:t:r") . ".pdf"
map <F6> :silent execute openpdfname<CR> | redraw!
The PDF opens up in Preview and all is well, except that the Vim screen is not repainted. I use vim 7.2.108 (shipped standard with OSX 10.6) from the terminal window. I tried removing my ~/.vimrc entirely to try and determine the cause, with no luck.
Hitting Ctrl-L repaints the screen, but I thought 'redraw!' would have the same effect!?
Thanks for any hints!
Move <CR> to the end of mapping. You are trying to execute redraw after you exited command mode. Of course, it does not work.
The correct syntax that does what I expect is:
map <F6> :silent execute openpdfname<CR>:redraw!<CR>
Try this:
map <silent> <F6> :silent execute openpdfname<CR>