How can I add ~/.vimrc to ~/.ideavimrc? I've used the command source ~/.vimrc in
~/.ideavimrc file.
~/.vimrc file
command! Wq :wq
~/.ideavimrc file
source ~/.vimrc
When I type my own command Wq in webstorm I get something like this: Unexpected character ':' in range |:wq. How can I achieve this? Any help will highly appreciated.
Looks like an issue in IdeaVim. Try to replace command! Wq :wq with command! Wq wq.
I've filed a ticket: https://youtrack.jetbrains.com/issue/VIM-2005
Related
i want to create a shortcut to run typescript in vim how can i access the filename in .vimrc
i want to run short scripts.
nmap <leader>r :! ts-node current-file<return>
First try %, as this gets substituted by the file name (as explained in :help :!):
nmap <Leader>r :! ts-node %<CR>
But if the file name contains whitespaces or special characters, you might see some errors. In that case, you need to escape the file name as follows:
nmap <Leader>r :execute '!ts-node ' . shellescape(expand("%"))<CR>
You're strongly adviced to read :h cmdline.txt, section 6 :h cmdline-special from top down to bottom.
nnoremap <leader>r :!ts-node %:S<CR>
I can't figure out how to map an internal command in vim.
I want to map to the command :Indent, the action g=GG (indenting the whole document)
I did this :
:command Indent execute "g=GG"
And it doesn't seem to work.
I successfully mapped
:command Java execute ":!javac *.java; echo ' **** done **** ' "
but how do i make it compile only the file that i am working on.
gg=G is a normal mode command. You need to use :normal, here:
:command! Indent normal! gg=G
But… :Indent<CR> is much longer than gg=G so I'm not sure that's a good idea.
I don't understand the need either. Still, if you want a command, at least let's have it support ranges:
:command! -range=% -nargs=0 Indent <line1>,<line2>normal! ==
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
A lot of times, when I want to save a file in vim and immediately exit thereafter, I accidentally type :Wq instead of :wq.
Vim naturally gives me this error:
E492: Not an editor command: Wq
I'm wondering, is it possible to remap :Wq to :wq?
You can create a simple vim command that is basically an alias for wq. Place the following in your ~/.vimrc file:
command! Wq wq
For more help see:
:h :command
You can also use ZZ which is the same as :wq<CR>
Though abbreviations suggest themselves for this (:cnoreabbrev Wk wk), their main disadvantage is that they are also applied in other places, such as when using Wk in a search pattern.
With the cmdalias plugin, you can define an alias:
:Alias Wk wk
PS: There is no :wk command, did you mean :wn[ext]? For a simple :w, have a look at this question
I generally use GVim, but most of my configuration is done via .vimrc (like keymappings) because I want them in vim and gvim. So when I edit my vimrc and then source it from gvim, I have to source my .gvimrc after that in order to get my colorscheme back (since it's gvim only). I tried to write a function to do this, and ran into the problems described in the comments below:
function ReloadConfigs()
:source ~/.vimrc
if has("gui_running")
:source ~/.gvimrc
endif
endfunction
command! Recfg call ReloadConfigs()
" error: function already exists, add ! to replace it
function! ReloadConfigs()
:source ~/.vimrc
if has("gui_running")
:source ~/.gvimrc
endif
endfunction
command! Recfg call ReloadConfigs()
" error: cannot replace function, it is in use
Is it possible to do something like this? Or, since my .gvimrc only has a few lines, should I just put its contents into an if has("gui_running") block?
You've put your function somewhere in your .vimrc. This means that, while it's being executed, the :source .vimrc is trying to redefine it, which is a problem. You could try doing this:
if !exists("*ReloadConfigs")
function ReloadConfigs()
:source ~/.vimrc
if has("gui_running")
:source ~/.gvimrc
endif
endfunction
command! Recfg call ReloadConfigs()
endif
If the function is already defined, this should skip redefining it, avoiding the issue.
I would say that whatever you have in your .vimrc that's messing up gvim settings should be surrounded by an if !has("gui_running") block.
An autocmd seems to be the easiest way of handling what you're trying to do:
autocmd BufWritePre .gvimrc,.vimrc source <amatch>
This way you get your configuration file automatically reloaded when you save it without having to mess around with functions. Alternatively, you could use a mapping to trigger :source $MYVIMRC or :source $MYGVIMRC.