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>
Related
I want to create an alias for two commands together - :tabnew and :E on gvim command prompt. And, I want to add that as a shortcut in .vimrc.
I tried cabbrev t tabnew | E but it doesn't work. Is it possible to use | in cabbrev?
Try this:
:cabbr t tabnew \| :Explore
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
e.g. I want to map
nnoremap <a-v> :vs | term<cr>
but vim is interpreting this as nnoremap <a-v> :vs followed by the separate command term<cr>. How do I declare the the associativity here? Using eval and execute do not work.
I asked too soon, figured it out a minute later: you simply escape the pipe:
nnoremap <a-v> :vs \| term<CR>
I read lot posts, lso few here on SO but nohing usefull, what I want to do simply is to set $M to open vimrc while running vim (coding) so simply when I type :edit $M vimrc file is open and I can edit it and as I understand it correctly when I type :source $M vim writes changes and it returns to the actual file I was editing (coding). I run on linux fullpath to vimrc is : /etc/vimrc
If you don't like the (better) answer above, here's the answer to your actual question...
Vim uses environment variables freely and happily. If you run vim like this:
$ M=~/.vimrc vim
then you will be able to do the
:e $M
:source $M
that you were wanting to do.
If you do this either on the command line (for this session) or in your .bashrc:
export M=~/.vimrc
then that environment variable will be available when you run vim in other ways as well.
Incidentally, I'm not familiar with your expectation of how :source will work. I would expect that you would have to :w to save, then run your :source $M and then do :e # to get back to your previous file you were editing. Easier would be to open a new window or tab, probably, but all that is personal preference.
From http://learnvimscriptthehardway.stevelosh.com/chapters/07.html
:nnoremap <leader>ev :vsplit $MYVIMRC<cr>
:nnoremap <leader>sv :source $MYVIMRC<cr>
Then (assuming - is your leader) you can just type
-ev
to edit your .vimrc and just type
-sv
to source it.
(Obviously those mapping lines need to be put in your .vimrc themselves so that they are available moving forward.)
That's not quite the answer to your question, but hopefully even more direct that what you were hoping for...
(Check out http://learnvimscriptthehardway.stevelosh.com/chapters/06.html to see how to define if you haven't done that before.)
so I find out how to set leader let mapleader = ","
nmap <leader>v :tabedit $MYVIMRC<CR>
http://vimcasts.org/episodes/updating-your-vimrc-file-on-the-fly/
but problem is wtih let $MYVIMRC=/etc/vimrc what could be wrong on that?? I have my vimrc just there in /etc
In addition to Peter's answers, you might simply create a link:
$ ln -s /etc/vimrc ~/.vimrc
I realize that I can :nmap <leader>rc :!cat %<CR> to provide an easy set of triggers, but I would like to do this instead.
nmap <leader>rc :up :!cat %<CR> but it complains about needing only one filename. How do I get vim to recognize both commands, in series?
You are missing a <CR> after :up. <CR> tells vim you want a carriage return here.
nmap <leader>rc :up<CR> :!cat %<CR>
The reason up is complaining about multiple file names is that it sees :!cat and %<CR> as two arguments to up.
So the new macro executes
:up
:!cat %
instead of
:up :!cat %
(Side Note: you should probably use nnoremap instead of nmap)
ZyX recommends using the following mapping instead.
nnoremap ,rc :up\|execute "!cat" shellescape(#%, 1)<CR>
This uses | to separate commands and escapes the %. Escaping the % leads to a more robust mapping just incase the filename contains special characters.
Help for :h execute and :h shellescape