2

I'm using nord theme, it works normally with other kind of files but not flex file I have syntax on and filetype on I tried switching colorthing from gruvbox to nord but it still behaving the same. this is my vimrc file

set guifont=Fira\ Code\ 18
nnoremap <A-j> :m .+1<CR>==
nnoremap <A-k> :m .-2<CR>==
inoremap <A-j> <Esc>:m .+1<CR>==gi
inoremap <A-k> <Esc>:m .-2<CR>==gi
vnoremap <A-j> :m '>+1<CR>gv=gv
vnoremap <A-k> :m '<-2<CR>gv=gv

" line number
set number

syntax on

filetype on                  " required

set nocompatible              " be iMproved, required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
syntax oncall vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

Plugin 'Valloric/YouCompleteMe'

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required


call plug#begin(has('nvim') ? stdpath('data') . '/plugged' : '~/.vim/plugged')

    " Any valid git URL is allowed
    Plug 'https://github.com/junegunn/vim-github-dashboard.git'

    " Using a non-default branch
    Plug 'rdnetto/YCM-Generator', { 'branch': 'stable' }

    " Using a tagged release; wildcard allowed (requires git 1.9.2 or above)
    Plug 'fatih/vim-go', { 'tag': '*' }

    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'

    Plug 'arcticicestudio/nord-vim'

    Plug 'preservim/nerdtree'

    "Plug 'morhetz/gruvbox'
call plug#end()
"let g:gruvbox_gruvbox_contrast_dark = 'soft'
"colorscheme gruvbox
"set background=dark

colorscheme nord

" custom key bindings
vmap <C-c> "+yi
vmap <C-x> "+c
vmap <C-v> c<ESC>"+p
imap <C-v> <C-r><C-o>+

" set compatibility to vim only
set nocompatibible

" status bar
set laststatus=2

"auto wrap text that extents beyond the sreen length
set wrap

" Encoding
set encoding=utf-8

filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab

set smartindent

" Auto save
let g:auto_save = 1
autocmd TextChanged, TextChangedI <buffer> silent write 
autocmd BufRead, BufNewFile * start 

" Airline
let g:airline_theme = 'base16_adwaita'
let g:airline_powerline_fonts = 1

set tags+=./tags;,tags

let g:zettelkasten = "/home/danhpc/opt/note_linked/"

" Make Ctrlp use ripgrep
if executable('rg')
    let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
    let g:ctrlp_user_caching = 0
endif

" Make :grep use ripgrep
if executable('rg')
    set grepprg=rg\ --color=never\ --vimgrep
endif

" My own version, only searches markdown as well using ripgrep
" Thus depends on grepprg being set to rg
command! -nargs=1 Ngrep grep "<args>" -g "*.md" $NOTES_DIR
nnoremap <leader>nn :Ngrep<space>

command! Vlist botright vertical copen | vertical resize 50
nnoremap <leader>v :Vlist<CR>

" Generate ctags
nnoremap <leader>tt :silent !ctags -R . <CR>:redraw!<CR>

" Go to tag file
nnoremap <leader>nt :e $NOTES_DIR/tags<CR>:cd $NOTES_DIR<CR>

" Go to the note dir
nnoremap <leader>nd :ex $NOTES_DIR<CR>:cd $NOTES_DIR<CR>

" Change directory to directory of current file
nnoremap <leader>cd :cd %:h<CR>

" Binding for searching tags ("search tag")
nnoremap <leader>st :CtrlPTag<CR>

" 1) pre-fills all the stuff we don’t want to type, namely the timestamp and the extension (always markdown)
" 2) that prompts you for the name of your note
command! -nargs=1 NewZettel :execute ":e" zettelkasten . strftime("%Y%m%d%H%M%S") . "-<args>.md"

nnoremap <leader>nz :NewZettel 

" CtrlP function for inserting a markdown link with Ctrl-X
function! CtrlPOpenFunc(action, line)
   if a:action =~ '^h$'    
      " Get the filename
      let filename = fnameescape(fnamemodify(a:line, ':t'))
      let l:filename_wo_timestamp = fnameescape(fnamemodify(a:line, ':t:s/\(^\d\+-\)\?\(.*\)\..\{1,3\}/\2/'))
      let l:filename_wo_timestamp = substitute(l:filename_wo_timestamp, "_", " ", "g")

      " Close CtrlP
      call ctrlp#exit()
      call ctrlp#mrufiles#add(filename)

      " Insert the markdown link to the file in the current buffer
      let mdlink = "[".filename_wo_timestamp."]( ".filename." )"
      put=mdlink
  else    
      " Use CtrlP's default file opening function
      call call('ctrlp#acceptfile', [a:action, a:line])
   endif
endfunction

let g:ctrlp_open_func = { 
         \ 'files': 'CtrlPOpenFunc',
         \ 'mru files': 'CtrlPOpenFunc' 
         \ }

Edit 1: a part of my flex file


%x NESTED_COMMENT INLINE_COMMENT
int nested_level = 0;

%}

DARROW  =>

%%

// Nested comment

<INITIAL,NESTED_COMMENT>"(*"    {BEGIN NESTED_COMMENT;
                    ++nested_level;}
<NESTED_COMMENT>"*"+)   {if(nested_level) --nested_level;
            else BEGIN INITIAL;}
<NESTED_COMMENT>[^*)\n]+    { }
<NESTED_COMMENT>"*"+    { }
<NESTED_COMMENT>\n  { }

// inline comment
<INITIAL> 

Edit 2 a picture of uncolored flex file enter image description here

9
  • Welcome to Vim :-) In order to understand or reproduce your problem we would need an example of flex file (ideally small) that is not display correctly and a description of what you dislike (a screenshot would be helpful to understand what you dislike). Nov 28, 2023 at 11:37
  • You needn't include your whole vimrc. Since you did, may I say that it looks just a little bit cluttered? Two plugin managers being used, the same options being set multiple times etc.
    – Friedrich
    Nov 28, 2023 at 11:38
  • Two plugin managers? Also, Vim doesn't appear to support syntax highlighting for "flex files". What are those, by the way? Are they related to web.mit.edu/gnu/doc/html/flex_1.html? Is the syntax close to lex, which is supported.
    – romainl
    Nov 28, 2023 at 12:07
  • @VivianDeSmedt thank you for replying, I just added some edits please take a look.
    – Danh Le
    Nov 28, 2023 at 12:18
  • @Friedrich haha, thank you for your honesty, I just got into Vim (I really enjoy it so far). First I just use Plug then I need Vurdle to isntall YCM. If you have any tips to make my vimrc more concise, I would really appreciate.
    – Danh Le
    Nov 28, 2023 at 12:23

1 Answer 1

1

Out of the box, Vim doesn't know anything about "flex": it doesn't detect it and doesn't provide specific syntax highlighting for it.

As a quick workaround, you can set the syntax to lex for flex files, which is supported. You can do it manually:

:set syntax=lex

or tell Vim to do it automatically for you:

" in ftdetect/flex.vim
" adjust the file pattern to taste
autocmd BufRead,BufNewFile *.flex setfiletype lex

Alternatively, you could use the .l file extension, which is automatically recognized by Vim as lex:

lex

But I don't know if it will cover everything as there certainly are differences between flex and lex.

FWIW, there is a plugin that appears to provide updated syntax highlighting for lex/flex. You should probably give it a try.

1
  • 1
    this works for me nicely, thank you for your time.
    – Danh Le
    Nov 28, 2023 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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