Easy French Punctuation on Linux with Nvim/Vim
The grasshoppers invade Egypt and the commas invade punctuation.
La légende des siècles
If you like me type a lot in both English and French, how do you deal with the spaces before question marks, exclamation marks colons, semi-colons, as well as quote marks. In French these spaces are mandatory although misunderstood for some English speakers as a mistake!
With my preferred editor Nvim on Linux this is easy.
Lets get to it!
-
Create a file at the following location for either Vim or Nvim
-
With the following contents:
let b:keymap_name="French"
"highlight lCursor ctermbg=red guibg=red
loadkeymap
? ?
! !
: :
; ;
The spaces before the punctuation marks are nonbreakable spaces. These unicode characters can be entered in nvim/vim by pressing kbd:[Ctrl + V] kbd:[u] kbd:[0] kbd:[0] kbd:[a] kbd:[0] and normally you should also be able to cut and paste the text above. |
This takes care of the question mark, exclamation mark, colon and semi colon. The quote marks need a bit more work. For those lets create a specific "french.vim" configuration file which will also load the preceding keymap in:
(vim/gim): |
~/.vim/spell/fr.vim |
(nvim): |
~/.config/nvim/spell/fr.vim |
-
With the following content:
setl spell complete+=kspell
setl keymap=fr
:imap <expr> " getline('.')[col('.')-2]=~'\S' ? ' »' : '« '
set background=dark
set wordwrap
This preceding file now takes care of loading the keymap, and also replacing the English " with either ��or�� depending on the position and also including the non breaking space. The file will load automatically when you apply the spell correction language.
run :set spelllang=fr to activate the French settings. (The spelling corrector is independent of the keyboard settings. You can activate or deactivate the spelling corrector with :set spell or :set nospell) |
This file for me also makes a change to the colorscheme when I’m editing a file of a particular language, and also sets the wordrap option. you can add here any vim command to personalize your French work environment. (More about that another time and space!)
Now if you change the spelling dictionary to French, the keyboard configuration options will be activated automatically!