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
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>
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 have created this vim command:
command! -complete=file E vsplit | wincmd l | e
When I use it by this
:E <Tab>
It works as expected. But when i want to complete path relatively to home directory, it shows ^I for each TAB hit:
:E ~/<TAB>
# shows as:
:E ~/^I
For :e command tab-completion works good.
You need to specify how many arguments:
command! -complete=file -nargs=? E vsplit | wincmd l | e <args>
See :h :command-nargs
However you are re-creating a command that already exists :vsplit and using 'splitright' setting. Put set splitright in your vimrc and now you can use :vsplit directly.
:set splitright
:vsp foo.txt
If you do not feel like setting 'splitright' then you can use :rightbelow. Example:
:rightb vsp foo.txt
For more help see:
:h 'splitright'
:h :vsp
:h :command-nargs
:h :rightbelow
I am searching through a large codebase and find vimgrep unusably slow, so I'm using :grep from within vim, which displays a list of files, then says Press ENTER or type command to continue.
After I press Enter I can then type :copen to get to the list of results. But I'm wondering if I could automate this process? Adding the -q flag to grep seems to have the effect of causing grep to do nothing and then copen to be blank, which, unless I'm doing something wrong here, isn't really desirable.
I am using vim 7.4
You could define such a command :
command! -bar -nargs=1 Grep silent grep <q-args> | redraw! | cw
This will allow you to call it like Grep pattern, and :cw which opens the quickfix list only if it isn't empty.
Use an autocommand. Here is the one suggested by Tim Pope for :Ggrep. It will work for your case as well:
autocmd QuickFixCmdPost *grep* cwindow
For more information see:
:h :au
:h QuickFixCmdPost
:h :cwindow
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