lervag / vimtex

VimTeX: A modern Vim and neovim filetype plugin for LaTeX files.
MIT License
5.53k stars 390 forks source link

`<leader>ll` and `<leader>lv` not working #2563

Closed lucawrabetz closed 1 year ago

lucawrabetz commented 2 years ago

I am in OS X Monterey 12.5.1, running vimtex with neovim v0.6.1 in iTerm2. vimtex is installed with vim-plug.

Compiling the .tex files and generating the pdf in a terminal with latexmk and pdflatex works perfectly. I am having the following issue: when I try a command such as <leader>ll or <leader>lv, vim ignores the <leader> and executes a normal l or v, i.e. moving the cursor right or going into visual mode. I have tried setting mapleader and maplocalleader to default, and I have also tried it with my usual remap of <Space>. In both cases, the result is the same. When I try another shortcut involving <leader>, it works (e.g. I have <leader>w remapped to :wq, and this shortcut works).

Originally posted by @lucawrabetz in https://github.com/lervag/vimtex/issues/69#issuecomment-1311006349

lervag commented 2 years ago

I am in OS X Monterey 12.5.1, running vimtex with neovim v0.6.1 in iTerm2. vimtex is installed with vim-plug.

I'm quite positive that there's something wrong with the installation of VimTeX. Does :help vimtex open the docs? Does :VimtexCompile work (as an alternative to <leader>ll)?

If not, can you show me the contents of your vimrc file?

lucawrabetz commented 2 years ago

:help vimtex opens the docs. :VimtexCompile outputs E492: Not an editor command: VimtexCompile.

Here is my vimrc (it is actually spread across multiple files but this is the equivalent of reading them all in the exact order they are sourced):

" set leader key
let mapleader = "\<Space>"
let maplocalleader = "\<Space>"

syntax enable                           " Enables syntax highlighing
set hidden                              " Required to keep multiple buffers open multiple buffers
" set nowrap                              " Display long lines as just one line
set encoding=utf-8                      " The encoding displayed
set pumheight=10                        " Makes popup menu smaller
set fileencoding=utf-8                  " The encoding written to file
set ruler                               " Show the cursor position all the time
set cmdheight=2                         " More space for displaying messages
set iskeyword+=-                        " treat dash separated words as a word text object"
set mouse=a                             " Enable your mouse
set splitbelow                          " Horizontal splits will automatically be below
set splitright                          " Vertical splits will automatically be to the right
set t_Co=256                            " Support 256 colors
set conceallevel=0                      " So that I can see `` in markdown files
set tabstop=4                           " Insert 2 spaces for a tab
set shiftwidth=4                        " Change the number of space characters inserted for indentation
set smarttab                            " Makes tabbing smarter 
set expandtab                           " Converts tabs to spaces
set smartindent                         " Makes indenting smart
set autoindent                          " Good auto indent
set foldmethod=indent
set laststatus=0                        " Always display the status line
set number                              " Line numbers
set relativenumber                      " Set relative numbers in line numbers
set background=dark                     " tell vim what the background color looks like
set showtabline=2                       " Always show tabs
set nobackup                            " This is recommended by coc
set nowritebackup                       " This is recommended by coc
set updatetime=300                      " Faster completion
set timeoutlen=500                      " By default timeoutlen is 1000 ms
set formatoptions-=cro                  " Stop newline continution of comments
set clipboard=unnamedplus               " Copy paste between vim and everything else

au! BufWritePost $MYVIMRC source %      " auto source when writing to init.vm alternatively you can run :source $MYVIMRC

let g:python3_host_prog = expand($PYTHON3) " path to python3 with pynvim installed
" let g:python_host_prog = expand("") " path to python2 with neovim installed

let g:node_host_prog = expand($NODE) " path to node

" Key reminders:
"   <C> - control
"   <CR> - enter
nnoremap <leader>w :wa<CR>
" Better nav for omnicomplete
" k completes, j undoes the completion
inoremap <expr> <c-j> ("\<C-n>") 
inoremap <expr> <c-k> ("\<C-p>")
" Use alt + hjkl to resize windows
nnoremap <M-j>    :resize -2<CR>
nnoremap <M-k>    :resize +2<CR>
nnoremap <M-h>    :vertical resize -2<CR>
nnoremap <M-l>    :vertical resize +2<CR>
" Better window navigation
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Good esc remap
inoremap gf <Esc>
inoremap fg <Esc>
inoremap FG <Esc>
inoremap GF <Esc>
" PLACEHOLDER <(++)>
inoremap <leader><leader> <Esc>/<(++)><CR>c6l
vnoremap <leader><leader> <Esc>/<(++)><CR>c6l
map <leader><leader> <Esc>/<(++)><CR>c6l
" LATEX SHORTCUTS
" REALLY REALLY SHORT ONES 
" move right without leaving insert mode
inoremap ;; <Esc>la
" bold text
inoremap ;bt \textbf{}<(++)><Esc>Ffla
" italic text
inoremap ;it \emph{}<(++)><Esc>Fhla
" text
inoremap ;tt \text{}<(++)><Esc>Ftla
" label
inoremap ;lb \label{}<Esc>Flla
" tag
inoremap ;tag \tag{}<Esc>Fgla
" ref
inoremap ;ref \ref{}<(++)><Esc>Ffla
" cite
inoremap ;cite \cite{}<(++)><Esc>Fela
" mathbb
inoremap ;mbb \mathbb{}<(++)><Esc>Fbla
" mathbf
inoremap ;mbf \mathbf{}<(++)><Esc>Ffla
" hat
inoremap ;hat \hat{}<(++)><Esc>Ftla
" bar
inoremap ;bar \bar{}<(++)><Esc>Frla
" transpose
inoremap ;tr ^\top<Esc>a
" mathcal
inoremap ;cal \mathcal{}<(++)><Esc>F{a
" MEDIUM ONES
" new packages
inoremap ;up \usepackage{}<Esc>Fela
" math mode 
inoremap ;mm $$<(++)><Esc>F$i
" math mode 2
inoremap ;m2m $$$$<(++)><Esc>F$hi
" fractions
inoremap ;fr \frac{}{<(++)>}<(++)><Esc>Fcla
" sum 
inoremap ;sm \sum_{}<(++)><Esc>F_la
" su is the sum with the upper bound - u for up!
inoremap ;su \sum_{}^{<(++)>}<(++)><Esc>F_la 
" sets
inoremap ;set \left\{\right\}<(++)><Esc>Frhi
" min
inoremap ;min \min_{}<(++)><Esc>F{a 
" max
inoremap ;max \max_{}<(++)><Esc>F{a 
" a space such as \mathbb{R}^{n}
inoremap ;sp \mathbb{}^{<(++)>}<(++)><Esc>F^hi
" ENVIRONMENTS
" generic 'begin-end'
inoremap ;beg \begin{}<(++)><CR><(++)><CR>\end{<(++)>}<CR><(++)><Esc>3k^f{a
" equation
inoremap ;eq \begin{equation}\label{}<(++)><CR><(++)><CR>\end{equation}<CR><(++)><Esc>3k^f{;a
" align 
inoremap ;al \begin{align}<CR><(++)><CR>\end{align}<CR><(++)><Esc>3k^f}a
" subequations
inoremap ;sub \begin{subequations}\label{}<CR><(++)><CR>\end{subequations}<CR><(++)><Esc>3k^f{;a
" algorithm
inoremap ;alg \begin{algorithm}[H]<CR>\caption{}\label{<(++)>}<CR>\begin{algorithmic}[1]<CR><(++)><CR>\end{algorithmic}<CR>\end{algorithm}<CR><(++)><Esc>5k^f{a
" matrix
inoremap ;mat \begin{matrix}<CR><CR>\end{matrix}<CR><(++)><Esc>2kI
" parentheses matrix
inoremap ;pmat \begin{pmatrix}<CR><CR>\end{pmatrix}<CR><(++)><Esc>2kI
" square brackets matrix
inoremap ;bmat \begin{bmatrix}<CR><CR>\end{bmatrix}<CR><(++)><Esc>2kI
" curly braces matrix
inoremap ;bbmat \begin{Bmatrix}<CR><CR>\end{Bmatrix}<CR><(++)><Esc>2kI
" pipes matrix
inoremap ;vmat \begin{vmatrix}<CR><CR>\end{vmatrix}<CR><(++)><Esc>2kI
" double pipes matrix
inoremap ;vvmat \begin{Vmatrix}<CR><CR>\end{Vmatrix}<CR><(++)><Esc>2kI
" auto-install vim-plug
if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  "autocmd VimEnter * PlugInstall
  "autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.config/nvim/autoload/plugged')
    " Better Syntax Support
    Plug 'sheerun/vim-polyglot'
    " File Explorer
    Plug 'scrooloose/NERDTree'
    " Auto pairs for '(' '[' '{'
    Plug 'jiangmiao/auto-pairs'
    " Conqueror of Completion (like intellisense in vscode)
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    " Airline - status bar
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'

    " All themes - add to the end of block to install a new one
    " (Don't forget to set up config ($NVIM/themes/<theme>.vim))
    Plug 'danilo-augusto/vim-afterglow'    
    Plug 'morhetz/gruvbox'
    Plug 'nikolvs/vim-sunbather'
    Plug 'NLKNguyen/papercolor-theme'

    " Tex !!!
    Plug 'lervag/vimtex'
    Plug 'matze/vim-tex-fold'

    " Csv
    Plug 'chrisbra/csv.vim'

call plug#end()
if (has("termguicolors"))
    set termguicolors
endif

let g:gruvbox_contrast_dark = 'hard'

colorscheme gruvbox

" TextEdit might fail if hidden is not set.
set hidden

" Some servers have issues with backup files, see #649.
set nobackup
set nowritebackup

" Give more space for displaying messages.
set cmdheight=2

" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300

" Don't pass messages to |ins-completion-menu|.
set shortmess+=c

" Always show the signcolumn, otherwise it would shift the text each time
" diagnostics appear/become resolved.
if has("nvim-0.5.0") || has("patch-8.1.1564")
  " Recently vim can merge signcolumn and number column into one
  set signcolumn=number
else
  set signcolumn=yes
endif

" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
      \ pumvisible() ? "\<C-n>" :
      \ <SID>check_back_space() ? "\<TAB>" :
      \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

function! s:check_back_space() abort
  let col = col('.') - 1
  return !col || getline('.')[col - 1]  =~# '\s'
endfunction

:filetype plugin on
" Make sure to :CocInstall coc-vimtex
filetype plugin indent on
let g:tex_flavor='latex'
let g:vimtex_view_method='skim'
let g:vimtex_quickfix_mode=1
let conceallevel=1
let g:tex_conceal='abdmg'
" enable tabline, the topline
" this puts it in airline domain
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#left_sep = ''
let g:airline#extensions#tabline#left_alt_sep = ''
let g:airline#extensions#tabline#right_sep = ''
let g:airline#extensions#tabline#right_alt_sep = ''

" enable powerline fonts
let g:airline_powerline_fonts = 1
let g:airline_left_sep = ''
let g:airline_right_sep = ''

" set to theme
let g:airline_theme = 'gruvbox'

" always show tabs
set showtabline=2 

" don't show -- INSERT --
set noshowmode
lervag commented 2 years ago

:help vimtex opens the docs. :VimtexCompile outputs E492: Not an editor command: VimtexCompile.

This seems to indicate that there's a plugin clash, perhaps with polyglot.

Can you do :scriptnames after opening a latex file (e.g. nvim test.tex) and report the output here?

Here is my vimrc ...

Here's parts of your vimrc with suggested changes by me with comments:

" The following section creates a lot of simple snippets. I strongly suggest
" that you instead install a real snippet engine, such as UltiSnips, and
" instead change these snippets into UltiSnips-snippets. See `:help
" vimtex-af-snippets`.

" PLACEHOLDER <(++)>
inoremap <leader><leader> <Esc>/<(++)><CR>c6l
vnoremap <leader><leader> <Esc>/<(++)><CR>c6l
" ...

" I would move this section to the very top of your vimrc file. vim-plug only
" modifies the `runtimepath` and sets stuff like `syntax enable` and `filetype
" plugin indent on`.

if empty(glob('~/.config/nvim/autoload/plug.vim'))
  silent !curl -fLo ~/.config/nvim/autoload/plug.vim --create-dirs
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
  "autocmd VimEnter * PlugInstall
  "autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.config/nvim/autoload/plugged')
    " WARNING: polyglot may not work well with VimTeX.
    " Better Syntax Support
    Plug 'sheerun/vim-polyglot'
    " File Explorer
    Plug 'scrooloose/NERDTree'
    " Auto pairs for '(' '[' '{'
    Plug 'jiangmiao/auto-pairs'
    " Conqueror of Completion (like intellisense in vscode)
    Plug 'neoclide/coc.nvim', {'branch': 'release'}
    " Airline - status bar
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'

    " All themes - add to the end of block to install a new one
    " (Don't forget to set up config ($NVIM/themes/<theme>.vim))
    Plug 'danilo-augusto/vim-afterglow'    
    Plug 'morhetz/gruvbox'
    Plug 'nikolvs/vim-sunbather'
    Plug 'NLKNguyen/papercolor-theme'

    " Tex !!!
    Plug 'lervag/vimtex'
    Plug 'matze/vim-tex-fold'

    " Csv
    Plug 'chrisbra/csv.vim'
call plug#end()

" You don't need the next lines, since `call plug#end()` does it for you:
:filetype plugin on
filetype plugin indent on

" g:tex_flavor and g:tex_conceal are not relevant for VimTeX and can safely be
" removed.
"let g:tex_flavor='latex'
"let g:tex_conceal='abdmg'

let g:vimtex_view_method='skim'
let g:vimtex_quickfix_mode=1
" This is an option, you need "set"
" Also, I would put this next to where you set options. It is not specific to
" LaTeX or VimTeX
"let conceallevel=1
set conceallevel=1

I would also suggest that you collect all the various options you set globally in its own section (i.e. all set ... lines), for instance just after call plug#end().

lucawrabetz commented 1 year ago

This is a bit embarrassing - it turns out I had never run :PlugInstall since adding vimtex to my vimrc - I found this out when I ran it as I was messing around with your suggestions. Thanks for the help and your comments to my config. The commands are now working.

lervag commented 1 year ago

This is a bit embarrassing - it turns out I had never run :PlugInstall since adding vimtex to my vimrc - I found this out when I ran it as I was messing around with your suggestions. Thanks for the help and your comments to my config. The commands are now working.

Glad to hear you figured it out. No need to be embarrassed. We've all made our share of silly mistakes! :)