Getting vim shebang plugin working - vim

Sorry if this is a silly question, I'm brand new to Vim.
I've downloaded the following shebang plug-in (http://www.vim.org/scripts/script.php?script_id=3366 version 1.1) to the directory .vim/plugin
When I open a file (e.g. "vim pypr.py") and in type in ":\X [enter]" (in normal mode) I encounter the following error:
"E10: \ should be follow by /, ? or &"
My .vimrc file in its entirety is as follows:
execute pathogen#infect()
syntax on
filetype plugin indent on
syntax enable
set background=dark
colorscheme solarized
map <leader>X :w<CR>:call SetExecutable()<CR>
I googled the error, and the results were not helpful in resolving the problem.
Any ideas what I'm doing wrong? I suspect I just don't know how to use the leader command.

The mapping
map <leader>X :w<CR>:call SetExecutable()<CR>
says to enter \X where \ is leader's default value. You can find the current leader value by
:let mapleader
It is \ if it says Undefined variable or it will show the current leader value.
Or you can map to another key like F6 so that pressing F6 will achieve what you are looking
nnoremap <F6> :w<CR>:call SetExecutable()<CR>

With mapping you don't need : and [Enter] — just type \X.

Related

Where is command v mapping in Vim

I have no idea how got into my vim configuration, and its behavior is very wired.
:verbose imap
get
i <C-R><C-R> * <C-R>*
Last set from ~/.vim/plugin/keymapping.vim line 43
! <D-v> <C-R>*
Press ENTER or type command to continue
What is ! <D-v>? Why it has no file path?
BTW, in my .vimrc, I did set nocomapatible and using iterm 2.
What is ! <D-v>?
From :h key-notation:
<D-...> command-key (Macintosh only) *<D-*
So, <D-v> is just ⌘+v
And prefix ! in the imap results indicate that it's applicable for both insert mode and command-line mode.
Why it has no file path?
Because this is vim built-in mapping, not set by user or a plugin and is coming from stand mac mappings. check :h mac-standard-mappings.

Why doesn't <leader> commands work in my installation of vimwiki?

My Vimwiki doesn't start with leader + ww command, only with :VimwikiIndex.
I think it's related to leader.
:echo mapleader generates two errors:
E121: Undefined variable: mapleader
and
E15: Invalid expression: mapleader
Any ideas how to fix this?
If the variable mapleader is not defined, then the leader key defaults to \ (see :h mapleader). So your wiki should start by typing \ww.
If you want to redefine you global leader key, you have to set the mapleader variable in your vimrc file, i.e. to set it to the Space character:
let mapleader = " "
It's important to put it in your vimrc file, because it will be run before plugins are loaded; if you run this command in the command line, it will not change the existing mappings, then you actual mapping will still be \ww.
Please note that, as explained in the doc of the plugin you are talking about, you can also define your own custom mapping which will replace <leader>ww, by running:
:nmap [YOUR MAPPING] <Plug>VimwikiIndex
For example, to open your wiki with Space+w:
:nmap <space>w <Plug>VimwikiIndex

Using NERDCommenter

The tutorial gives this example:
<leader>c$ |NERDComEOLComment|
Comments the current line from the cursor to the end of line.
But pressing \c$ or ,c$ in vim copies the current line and switched to insert mode.
I've installed the plugin via pathogen and :help nerdcommenter does work, but there's no mention of nerdcommenter in the output of :scripts, don't know if that means the plugin hasn't been successfully installed.
This looks fine. Here are some troubleshooting tips:
Check the :scriptnames output for .../plugin/NERD_commenter.vim; it needs to be there.
Check :echo loaded_nerd_comments
Check :echo g:NERDCreateDefaultMappings
Check :nmap <Leader>c
Do other mappings work? Define :nmap <Leader>x :echomsg "Works"<CR> and press \x.
If mappings don't work, you may have accidentally :set paste. Undo with :set nopaste.

GoLang Highlighting in vim not working

I've seen multiple places(including here) that to add syntax highlighting you have to add certain lines to the .vimrc:
"Stuff for GoLang"
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on
That is what's currently in my .vimrc
Restarted vim, terminal, system, and still no highlighting. Any suggestions?
Okay guys, I go the answer:
$GOROOT needs to be defined or you can simply put the location of your go installation.
Ensure that the corresponding runtime files are actually there.
$GOROOT must be defined; check with :echo $GOROOT
There must a syntax plugin (syntax/go.vim) below $GOROOT/misc/vim. Check with :echo filereadable($GOROOT . '/misc/vim/syntax/go.vim').
After opening a Go file, you can check again via :scriptnames and :syntax list.

vim conditional keymap when a tex file is open

I am trying to make a keymap that will call latexmk when .tex is available (it would be better if .tex is the currently open and active buffer)
I tried :
:nnoremap <Leader>lw :if filereadable('*.tex')<cr>up!<cr>:!latexmk -pdf<cr>endif<cr>
when trying to make latexmk -pdf run, but unfortunately, its just prompting those line in the window, and doing nothing like:
~
:if filereadable('*.tex')
: up!
: :call Tex_RunLaTeX()
: endif
Press ENTER or type command to continue
kindly help.
(it will be great, as told, if this can be done when .tex is the currently open and active buffer.)
NB: this question and its variant has been asked here several time here eg this and this, hence sorry for the repetation. I have failed to solve my problem with those.
You need to do 3 things:
fix your mapping to run the command properly
create a mapping local to a specific buffer by using the <buffer> option for nnoremap.
load the mappings for just a specific filetype.
First fix the mapping by using executing the command as single ex command by using <bar> and removing :'s & <cr>'s. We also remove the filereadable portion because we just wrote the file.
nnoremap <buffer> :up!<bar>!latexmk -pdf<cr>
or you can use an expressing mapping like FDinoff suggested.
Note the <buffer> option on the mapping. This makes the mapping only available to the current buffer not every buffer.
Now we need to make sure this mapping only works for tex filetypes. This can be done via an autocommand in your .vimrc like so:
autocmd FileType tex nnoremap <buffer> :up!<bar>!latexmk -pdf<cr>
The other way option is by creating a filetype plugin. (see :h ftplugin for more details)
A simple example is do create a file named, ~/.vim/ftplugin/text.vim and place your mappings inside like so:
nnoremap <buffer> :up!<bar>!latexmk -pdf<cr>
I personally lean more towards the ftplugin approach but having a everything in your .vimrc file can be nice.
I feel like this could be done with an autocmd.
The autocmd only loads the mapping when the file is a tex file.
autocmd FileType tex nnoremap <leader>lw :up! \| !latexmk -pdf<CR>
If you want to do this filereadable('*.tex') which just checks to see if a file in the directory is a tex file. You could use the expr mapping from the first link. In the else part of the expression we just put an empty string so the mapping will do nothing.
nnoremap <expr> <leader>lw filereadable('*.txt') ? ':up! \| !latexmk -pdf<CR>' : ''

Resources