0

when I use: vim <file_name> vim opens an empty buffer with no name ([No Name]). But when I type: :tabnew <file_name> it opens the file properly. I tried :bdelete to delete the open buffer which didn't help. Here is what :ls returns:

2 %a   "[No Name]"                    line 1

What causes this problem? This is my .vimrc:

inoremap ;; <esc>
inoremap \\ /
inoremap { {<CR>}<Esc>ko
inoremap <C-e> <C-o>$
inoremap <C-a> <C-o>0
inoremap <C-M-f> <C-o><C-f>i
inoremap <C-M-b> <C-o><C-b>i
inoremap <C-x> <Delete>
inoremap <C-u> <C-o>u
inoremap <C-k> <C-o>gk
inoremap <C-h> <Left>
inoremap <C-l> <Right>
inoremap <C-j> <C-o>gj
inoremap <C-M-x> :call delete(expand('%')) | bdelete!

call plug#begin('~/.vim/plugged')

Plug 'joshdick/onedark.vim'
Plug 'tpope/vim-eunuch'

call plug#end()

colorscheme onedark

if has("autocmd")
  au InsertEnter * silent execute "!sed -i.bak -e 's/TERMINAL_CURSOR_SHAPE_BLOCK/TERMINAL_CURSOR_SHAPE_IBEAM/' ~/.config/xfce4/terminal/terminalrc"
  au InsertLeave * silent execute "!sed -i.bak -e 's/TERMINAL_CURSOR_SHAPE_IBEAM/TERMINAL_CURSOR_SHAPE_BLOCK/' ~/.config/xfce4/terminal/terminalrc"
  au VimLeave * silent execute "!sed -i.bak -e 's/TERMINAL_CURSOR_SHAPE_IBEAM/TERMINAL_CURSOR_SHAPE_BLOCK/' ~/.config/xfce4/terminal/terminalrc"
endif

set nocompatible

set number
set cursorline
hi cursorline ctermbg=none

set expandtab
set smarttab
set shiftwidth=4
set tabstop=4

set lbr
set tw=500

set ai
set si

set autoread

command W w !sudo tee % > /dev/null

function! VisualSelection(direction, extra_filter) range
    let l:saved_reg = @"
    execute "normal! vgvy"

    let l:pattern = escape(@", "\\/.*'$^~[]")
    let l:pattern = substitute(l:pattern, "\n$", "", "")

    if a:direction == 'gv'
        call CmdLine("Ack '" . l:pattern . "' " )
    elseif a:direction == 'replace'
        call CmdLine("%s" . '/'. l:pattern . '/')
    endif

    let @/ = l:pattern
    let @" = l:saved_reg
endfunction

vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>

map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/

set so=7

set smartcase

set noerrorbells
set novisualbell

set nobackup
set nowb
set noswapfile
  • 1
    Last inoremap: The pipe (|) needs to be escaped with a backslash. – Ralf Apr 5 at 12:02
  • @Ralf Solved the problem. thanks. – amirali Apr 5 at 12:07
1

As Ralf mentions in the comments, the | in the last inoremap actually starts a new command, so when you start editing a file its buffer is deleted.

Escape it with a backslash.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.